diff --git a/README.md b/README.md index 6f41720..7a526fe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # xBot -![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-10.0-blue?style=flat-square) +![Telegram Bot API](https://img.shields.io/badge/Telegram%20Bot%20API-10.2-blue?style=flat-square) ![GitHub Release](https://img.shields.io/github/v/release/al3x5dev/xbot?include_prereleases&style=flat-square&color=blue) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/al3x5dev/http?style=flat-square) ![GitHub License](https://img.shields.io/github/license/al3x5dev/xbot?style=flat-square) @@ -25,6 +25,7 @@ - [Message Format](https://github.com/al3x5dev/xbot/blob/main/docs/format.md) - [Events Logger](https://github.com/al3x5dev/xbot/blob/main/docs/logger.md) - [Middlewares](https://github.com/al3x5dev/xbot/blob/main/docs/middlewares.md) +- [Rich Messages](https://github.com/al3x5dev/xbot/blob/main/docs/rich-message-examples.md) ## Contributions diff --git a/composer.json b/composer.json index f8d2651..be2a600 100755 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "psr-4": { "Al3x5\\xBot\\": "src/", "Bot\\": "bot/" - }, "files": [ "src/helpers.php" diff --git a/docs/format.md b/docs/format.md index 1deedb3..4ee24ce 100644 --- a/docs/format.md +++ b/docs/format.md @@ -1,16 +1,16 @@ -# FormatHelper +# Text -The `FormatHelper` class provides static methods for applying different formats to text in Telegram messages. These formats include bold, italics, underlines, strikethrough, spoilers, links, user mentions, custom emoji, code blocks, and quotes. This class is useful for formatting messages sent through a Telegram bot, improving their presentation and readability. +The `Text` class provides static methods for applying different formats to text in Telegram messages. These formats include bold, italics, underlines, strikethrough, spoilers, links, user mentions, custom emoji, code blocks, and quotes. This class is useful for formatting messages sent through a Telegram bot, improving their presentation and readability. > [!WARNING] -> `FormatHelper` generates the formatting according to the configuration value of `parse_mode` (default is `'HTML'`). +> `Text` generates the formatting according to the configuration value of `parse_mode` (default is `'HTML'`). > > If you override `parse_mode` in a method's parameters (e.g., `reply($msg, ['parse_mode' => 'MarkdownV2'])`), -> the text formatted by `FormatHelper` will *NOT* be automatically adapted—it will continue to use the configuration's formatting. +> the text formatted by `Text` will *NOT* be automatically adapted—it will continue to use the configuration's formatting. > > In that case, you are responsible for ensuring that the text format matches the `parse_mode` you are sending. > -> **Using `FormatHelper` is not recommended when the message's `parse_mode` differs from the globally configured one.** +> **Using `Text` is not recommended when the message's `parse_mode` differs from the globally configured one.** ## Methods @@ -19,7 +19,7 @@ The `FormatHelper` class provides static methods for applying different formats Formats the provided text in bold. ```php -$this->reply(FormatHelper::bold('This text will be bold')); +$this->reply(Text::bold('This text will be bold')); // Output: This text will be bold ``` @@ -28,7 +28,7 @@ $this->reply(FormatHelper::bold('This text will be bold')); Formats the provided text in italics. ```php -$this->reply(FormatHelper::italic('This text will be italic')); +$this->reply(Text::italic('This text will be italic')); // Output: This text will be italic ``` @@ -37,7 +37,7 @@ $this->reply(FormatHelper::italic('This text will be italic')); Formats the provided text as underlined. ```php -$this->reply(FormatHelper::underline('This text will be underlined')); +$this->reply(Text::underline('This text will be underlined')); // Output: This text will be underlined ``` @@ -46,7 +46,7 @@ $this->reply(FormatHelper::underline('This text will be underlined')); Formats the provided text as a strikethrough. ```php -$this->reply(FormatHelper::strikethrough('This text will be strikethrough')); +$this->reply(Text::strikethrough('This text will be strikethrough')); // Output: This text will be strikethrough ``` @@ -55,7 +55,7 @@ $this->reply(FormatHelper::strikethrough('This text will be strikethrough')); Formats the provided text as a spoiler. ```php -$this->reply(FormatHelper::spoiler('This text will be a spoiler')); +$this->reply(Text::spoiler('This text will be a spoiler')); // Output: This text will be a spoiler ``` @@ -64,7 +64,7 @@ $this->reply(FormatHelper::spoiler('This text will be a spoiler')); Formats the provided text as a link. ```php -$this->reply(FormatHelper::link('Click here', 'https://example.com')); +$this->reply(Text::link('Click here', 'https://example.com')); // Output: Click here ``` @@ -73,7 +73,7 @@ $this->reply(FormatHelper::link('Click here', 'https://example.com')); Formats the provided text as a user mention. ```php -$this->reply(FormatHelper::mention('@user', 123456789)); +$this->reply(Text::mention('@user', 123456789)); // Output: @user ``` @@ -82,7 +82,7 @@ $this->reply(FormatHelper::mention('@user', 123456789)); Formats the provided text as a custom emoji. ```php -$this->reply(FormatHelper::emoji('😊', '1234567890')); +$this->reply(Text::emoji('😊', '1234567890')); // Output: 😊 ``` @@ -91,7 +91,7 @@ $this->reply(FormatHelper::emoji('😊', '1234567890')); Formats the provided text as inline code. ```php -$this->reply(FormatHelper::inlineCode('inline code')); +$this->reply(Text::inlineCode('inline code')); // Output: inline code ``` @@ -100,7 +100,7 @@ $this->reply(FormatHelper::inlineCode('inline code')); Formats the provided text as a code block. ```php -$this->reply(FormatHelper::codeBlock('block code', 'php')); +$this->reply(Text::codeBlock('block code', 'php')); // Output:
block code
``` @@ -116,7 +116,7 @@ Formats a Unix timestamp for display. Supports multiple format options: - `r`: Relative time from current moment ```php -$this->reply(FormatHelper::time(1710691200, 't')); +$this->reply(Text::time(1710691200, 't')); // Output: fecha ``` @@ -125,7 +125,7 @@ $this->reply(FormatHelper::time(1710691200, 't')); Formats the provided text as a blockquote. ```php -$this->reply(FormatHelper::blockQuote('This is a blockquote')); +$this->reply(Text::blockQuote('This is a blockquote')); // Output:
This is a blockquote
``` @@ -134,6 +134,282 @@ $this->reply(FormatHelper::blockQuote('This is a blockquote')); Formats the provided text as an expandable blockquote. ```php -$this->reply(FormatHelper::expandableBlockQuote('This is an expandable blockquote')); +$this->reply(Text::expandableBlockQuote('This is an expandable blockquote')); // Output:
This is an expandable blockquote
-``` \ No newline at end of file +``` + +--- + +## Rich Text Formatting (for RichMessage) + +These methods return `RichText` entity objects (not strings) for use inside `RichMessage` blocks and tables. They produce the nested JSON structure required by the Telegram Bot API 7.0+ rich message format. + +```php +use Al3x5\xBot\Telegram\Text; + +$bold = Text::richBold('Bold text'); +$italic = Text::richItalic('Italic text'); +``` + +### richBold(string|RichText $text): RichTextBold + +```php +Block::heading(Text::richBold('Title')); +``` + +### richItalic(string|RichText $text): RichTextItalic + +```php +Block::paragraph(Text::richItalic('Intro')); +``` + +### richUnderline(string|RichText $text): RichTextUnderline + +### richStrikethrough(string|RichText $text): RichTextStrikethrough + +### richSpoiler(string|RichText $text): RichTextSpoiler + +### richCode(string|RichText $text): RichTextCode + +### richUrl(string|RichText $text, string $url): RichTextUrl + +Creates a clickable URL with the given text. + +### richEmail(string|RichText $text): RichTextEmailAddress + +### richPhone(string|RichText $text): RichTextPhoneNumber + +### richMention(string|RichText $text, string $username): RichTextMention + +Mentions a user by username. + +### richTextMention(string|RichText $text, User|int $user): RichTextTextMention + +Mentions a user by their user ID. + +### richCustomEmoji(string $emoji, string $id): RichTextCustomEmoji + +Inserts a custom emoji by its ID. + +### richSubscript(string|RichText $text): RichTextSubscript + +### richSuperscript(string|RichText $text): RichTextSuperscript + +### richMarked(string|RichText $text): RichTextMarked + +### richDatetime(int $unix): RichTextDateTime + +Formats a Unix timestamp as a time entity. + +### richMath(string $expression): RichTextMathematicalExpression + +### richAnchor(string $name): RichTextAnchor + +Creates an anchor that can be referenced by `richAnchorLink`. + +### richAnchorLink(string|RichText $text, string $anchor): RichTextAnchorLink + +Creates a link to a previously defined anchor. + +### richReference(string|RichText $text, string $reference): RichTextReference + +### richReferenceLink(string|RichText $text, string $reference): RichTextReferenceLink + +--- + +## RichMessage Builder + +The `RichMessage` builder creates a `sendRichMessage` payload. It supports rich blocks, HTML/Markdown fallbacks, and RTL direction. + +```php +use Al3x5\xBot\Telegram\Factories\RichMessage; +use Al3x5\xBot\Telegram\Factories\Rich\Block; +use Al3x5\xBot\Telegram\Text; + +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Welcome'))) + ->block(Block::paragraph(Text::richItalic('This is a rich message'))) + ->block(Block::divider()) + ->html('Fallback HTML') + ->rtl() + ->build(); + +$this->sendRichMessage($chatId, $message); +``` + +### make(): RichMessage + +Creates a new builder instance. + +### block(Entity $block): self + +Adds a block (from `Block::*()` factories). + +### html(string $html): self + +Sets an HTML fallback for clients that don't support rich messages. + +### markdown(string $markdown): self + +Sets a Markdown fallback. + +### rtl(bool $v = true): self + +Enables right-to-left rendering. + +### build(): InputRichMessage + +Builds the message entity ready for `sendRichMessage`. + +--- + +## Rich\Block Factory + +Provides static methods to create all 20 rich block types for use with `RichMessage::block()`. + +```php +use Al3x5\xBot\Telegram\Factories\Rich\Block; + +$msg = RichMessage::make() + ->block(Block::paragraph('Simple text')) + ->block(Block::divider()) + ->block(Block::table()->header(['Name', 'Value'])->body([['Item', '$10']])->build()) + ->build(); +``` + +### paragraph(string|RichText|array $text): InputRichBlockParagraph + +A paragraph block with formatted text. + +### heading(string|RichText|array $text, int $size = 1): InputRichBlockSectionHeading + +A section heading. `$size` ranges from 1 (largest) to 6. + +### preformatted(string|RichText|array $text, string $language = ''): InputRichBlockPreformatted + +Preformatted/code block. Optionally specify the programming language. + +### footer(string|RichText|array $text): InputRichBlockFooter + +A footer block. + +### divider(): InputRichBlockDivider + +A horizontal divider line. + +### thinking(string|RichText|array $text): InputRichBlockThinking + +Animated thinking/typing indicator block. + +### blockQuote(array $blocks, string|RichText|null $credit = null): InputRichBlockBlockQuotation + +A block quote containing nested blocks. Optional attribution text. + +```php +Block::blockQuote([Block::paragraph('Quoted text')], '— Source'); +``` + +### pullQuote(string|RichText|array $text, string|RichText|null $credit = null): InputRichBlockPullQuotation + +A pull quote with large stylized text. Optional attribution. + +### photo(string $media, string|RichText|null $caption = null, string|RichText|null $credit = null): InputRichBlockPhoto + +A photo block. `$media` is the file ID. + +### video(string $media, ...): InputRichBlockVideo + +### audio(string $media, ...): InputRichBlockAudio + +### animation(string $media, ...): InputRichBlockAnimation + +### voiceNote(string $media, ...): InputRichBlockVoiceNote + +### table(): Table + +Returns a `Table` builder instance for constructing table blocks. + +### list(array $items): InputRichBlockList + +Creates a list block. Each item can be a block or array of blocks. + +```php +Block::list([ + Block::paragraph('Item 1'), + Block::paragraph('Item 2'), +]); +``` + +### details(string|RichText|array $summary, array $blocks, bool $is_open = false): InputRichBlockDetails + +A collapsible details/summary block. + +### collage(array $blocks, ...): InputRichBlockCollage + +A collage of multiple media blocks. + +### slideshow(array $blocks, ...): InputRichBlockSlideshow + +A slideshow/carousel of blocks. + +### map(array $location, int $zoom = 15, int $width = 300, int $height = 200, ...): InputRichBlockMap + +Embedded map. `$location` is `['latitude' => float, 'longitude' => float]`. + +### math(string $expression): InputRichBlockMathematicalExpression + +Renders a mathematical expression using Telegram's rendering engine. + +### anchor(string $name): InputRichBlockAnchor + +Creates an anchor point that can be linked to via block anchor links. + +--- + +## Rich\Table Builder + +The `Table` builder constructs table blocks for use inside `RichMessage`. + +```php +use Al3x5\xBot\Telegram\Factories\Rich\Block; +use Al3x5\xBot\Telegram\Text; + +$table = Block::table() + ->header(['Product', 'Price']) + ->body([ + ['Shirt', '$25'], + ['Shoes', '$80'], + ]) + ->footer(['Total', '$105']) + ->bordered() + ->caption(Text::richBold('Order Summary')) + ->build(); +``` + +### header(array $cells): self + +Sets the header row. Each cell can be a string, `RichText` object, or array. + +### body(array $rows): self + +Sets the body rows. Each row is an array of cells. + +### footer(array $cells): self + +Sets the footer row. + +### bordered(bool $v = true): self + +Enables table borders. + +### striped(bool $v = true): self + +Enables alternating row striping. + +### caption(string|RichText|array $caption): self + +Sets the table caption. + +### build(): InputRichBlockTable + +Builds the table block entity. \ No newline at end of file diff --git a/docs/keyboards.md b/docs/keyboards.md index a7293e5..4904c7b 100644 --- a/docs/keyboards.md +++ b/docs/keyboards.md @@ -15,8 +15,8 @@ Creates an inline keyboard that appears next to the message. Each button can have actions such as opening a URL, sending callback data, etc. ```php -use Al3x5\xBot\Telegram\Factories\InlineButton; use Al3x5\xBot\Telegram\Factories\Keyboard; +use Al3x5\xBot\Telegram\Factories\Keyboard\InlineButton; $keyboard = Keyboard::inline() ->row([ @@ -159,8 +159,8 @@ This static method creates a new instance of `ReplyKeyboard`, which is used to b ```php -use Al3x5\xBot\Telegram\Factories\ReplyButton; use Al3x5\xBot\Telegram\Factories\Keyboard; +use Al3x5\xBot\Telegram\Factories\Keyboard\ReplyButton; $keyboard = Keyboard::reply() ->row([ diff --git a/docs/middlewares.md b/docs/middlewares.md index 16dee8c..f3f0d08 100644 --- a/docs/middlewares.md +++ b/docs/middlewares.md @@ -210,7 +210,7 @@ Example: namespace Bot\Middlewares; -use Al3x5\xBot\Telegram\FormatHelper; +use Al3x5\xBot\Telegram\Text; use Al3x5\xBot\Telegram\Actions\Middlewares; class AdminMiddleware extends Middlewares @@ -220,7 +220,7 @@ class AdminMiddleware extends Middlewares if (!$this->isAdmin()) { return $this->abort( '🚫 No eres bienvenido aquí ' . - FormatHelper::mention( + Text::mention( $this->update->message->from->first_name, $this->update->message->from->id ) @@ -229,7 +229,7 @@ class AdminMiddleware extends Middlewares $this->reply( '✅ Bienvenido ' . - FormatHelper::mention( + Text::mention( $this->update->message->from->first_name, $this->update->message->from->id ) diff --git a/docs/rich-message-examples.md b/docs/rich-message-examples.md new file mode 100644 index 0000000..6658301 --- /dev/null +++ b/docs/rich-message-examples.md @@ -0,0 +1,404 @@ +# Rich Message Examples + +Complete examples of rich messages using the Telegram Bot API 7.0+ format. + +All examples assume you have access to `$this->message->chat->id` from a command context. + +> [!IMPORTANT] +> `blocks`, `html`, and `markdown` are **mutually exclusive**. Use only one per message. Calling both `->html(...)` and `->markdown(...)` (or also `->block(...)`) will send multiple fields and the API will reject the request. + +```php +use Al3x5\xBot\Telegram\Text; +use Al3x5\xBot\Telegram\Factories\RichMessage; +use Al3x5\xBot\Telegram\Factories\Rich\Block; +``` + +--- + +## 1. Simple Message + +Heading + paragraph + divider: + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Welcome to xBot'))) + ->block(Block::paragraph('This is a simple rich message.')) + ->block(Block::paragraph(Text::richItalic('Enjoy the new features!'))) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 2. Formatted Text + +Nested `RichText` entities: + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Notifications'), 1)) + ->block(Block::paragraph([ + Text::richBold('New update! '), + Text::richItalic('Version 4.6') + ])) + ->block(Block::paragraph( + Text::richSpoiler('This is a spoiler text') + )) + ->block(Block::paragraph( + Text::richCode('composer update') + )) + ->block(Block::preformatted( + Text::richBold('const VERSION = "4.6.0";'), + 'php' + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 3. Table + +Table with header, body, footer, borders, and caption: + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Order Summary'))) + ->block(Block::table() + ->header(['Product', 'Qty', 'Price']) + ->body([ + ['T-Shirt', '2', '$50'], + ['Jeans', '1', '$80'], + ['Shoes', '1', '$120'], + ]) + ->footer(['Total', '4', '$250']) + ->bordered() + ->caption(Text::richBold('Order #12345')) + ->build() + ) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 4. Table with Richtext Cells + +```php +$message = RichMessage::make() + ->block(Block::table() + ->header([Text::richBold('Name'), Text::richBold('Status')]) + ->body([ + [Text::richBold('Alice'), Text::richItalic('Online')], + [Text::richBold('Bob'), Text::richItalic('Offline')], + ]) + ->striped() + ->build() + ) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 5. List + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Shopping List'))) + ->block(Block::list([ + Block::paragraph(Text::richBold('Fruits') . ': Apples, Bananas'), + Block::paragraph(Text::richBold('Dairy') . ': Milk, Cheese'), + Block::paragraph(Text::richBold('Bakery') . ': Bread, Croissants'), + ])) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 6. Collage + +Multiple media blocks arranged as a collage: + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Photo Gallery'))) + ->block(Block::collage( + [ + Block::photo('AgACAg...photoId1'), + Block::photo('AgACAg...photoId2'), + Block::photo('AgACAg...photoId3'), + ], + Text::richItalic('Our latest collection'), + Text::richBold('Gallery 2025') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +Mixed media collage: + +```php +$message = RichMessage::make() + ->block(Block::collage( + [ + Block::photo('AgACAg...photoId'), + Block::video('BAAD...videoId'), + ] + )) + ->block(Block::audio('CQAD...audioId')) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 7. Slideshow + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Product Showcase'))) + ->block(Block::slideshow( + [ + Block::photo('AgACAg...photo1', Text::richBold('Front view')), + Block::photo('AgACAg...photo2', Text::richBold('Side view')), + Block::photo('AgACAg...photo3', Text::richBold('Back view')), + ], + Text::richItalic('Swipe to see more') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 8. Details (Collapsible) + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('FAQ'))) + ->block(Block::details( + Text::richBold('How to install?'), + [ + Block::paragraph('Run the following command:'), + Block::preformatted('composer install', 'bash'), + ], + is_open: false + )) + ->block(Block::details( + Text::richBold('How to update?'), + [ + Block::paragraph('Use composer update:'), + Block::preformatted('composer update', 'bash'), + ], + is_open: true + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 9. Blockquote + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Testimonial'))) + ->block(Block::blockQuote( + [ + Block::paragraph('Amazing product! Highly recommended.'), + Block::paragraph(Text::richItalic('Changed my workflow completely.')), + ], + Text::richBold('— Happy Customer') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 10. Pull Quote + +```php +$message = RichMessage::make() + ->block(Block::pullQuote( + Text::richBold('The best time to plant a tree was 20 years ago. The second best time is now.'), + Text::richItalic('— Chinese Proverb') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 11. Photo with Caption + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Product Photo'))) + ->block(Block::photo( + 'AgACAg...photoFileId', + [Text::richBold('Premium T-Shirt'), "\n", Text::richItalic('$49.99')], + Text::richBold('Summer Collection 2024') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 12. Video + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Promo Video'))) + ->block(Block::video( + 'BAAD...videoFileId', + Text::richBold('Watch our new promo!'), + Text::richItalic('Duration: 2:30') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 13. Embedded Map + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Our Location'))) + ->block(Block::map( + ['latitude' => 40.7128, 'longitude' => -74.0060], + zoom: 15, + width: 400, + height: 300, + caption: Text::richBold('New York City'), + credit: Text::richItalic('Main Office') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 14. Thinking / Typing Block + +```php +$message = RichMessage::make() + ->block(Block::thinking(Text::richItalic('Analyzing your request...'))) + ->build(); + +$this->sendRichMessageDraft($chatId, $draftId, $message); +``` + +--- + +## 15. Math Expression + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('Math Result'))) + ->block(Block::math('E = mc^2')) + ->block(Block::paragraph( + Text::richItalic('Einsteins equation') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 16. Complete Invoice Example + +Combines multiple block types in a realistic scenario: + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('INVOICE #INV-2024-001'))) + ->block(Block::table() + ->header([Text::richBold('Item'), Text::richBold('Qty'), Text::richBold('Price')]) + ->body([ + ['Web Development', '40h', '$2,000'], + ['UI/UX Design', '20h', '$1,200'], + ['Hosting (1 year)', '1', '$360'], + ]) + ->footer([Text::richBold('Total'), '', Text::richBold('$3,560')]) + ->bordered() + ->striped() + ->caption(Text::richBold('Payment due within 30 days')) + ->build() + ) + ->block(Block::divider()) + ->block(Block::paragraph( + Text::richBold('Status: ') . Text::richItalic('Pending Payment') + )) + ->block(Block::paragraph( + Text::richBold('Due Date: ') . Text::richDatetime(strtotime('+30 days')) + )) + ->block(Block::blockQuote( + [Block::paragraph('Thank you for your business!')], + Text::richBold('xBot Team') + )) + ->block(Block::divider()) + ->block(Block::footer( + Text::richItalic('For questions, reply to this message.') + )) + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 17. RTL Message + +```php +$message = RichMessage::make() + ->block(Block::heading(Text::richBold('مرحباً بكم'))) + ->block(Block::paragraph('هذا نص من اليمين إلى اليسار')) + ->rtl() + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 18. With HTML Fallback + +```php +$message = RichMessage::make() + ->html('Rich MessageFallback for older clients') + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` + +--- + +## 19. With Markdown Fallback + +```php +$message = RichMessage::make() + ->markdown('*Rich Message* _Fallback for older clients_') + ->build(); + +$this->sendRichMessage($this->message->chat->id, $message); +``` diff --git a/src/Bot.php b/src/Bot.php index 5cf1df2..14ba3c4 100644 --- a/src/Bot.php +++ b/src/Bot.php @@ -18,7 +18,7 @@ class Bot { public const NAME = 'xBot'; - public const VERSION = '4.5.0'; + public const VERSION = '4.6.0'; public ?Update $update = null; diff --git a/src/Telegram/Entities/BackgroundFillFreeformGradient.php b/src/Telegram/Entities/BackgroundFillFreeformGradient.php index ae6c5bf..dbb31a9 100644 --- a/src/Telegram/Entities/BackgroundFillFreeformGradient.php +++ b/src/Telegram/Entities/BackgroundFillFreeformGradient.php @@ -9,7 +9,7 @@ * @property string $type * @property array $colors */ -class BackgroundFillFreeformGradient extends Entity +class BackgroundFillFreeformGradient extends BackgroundFill { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundFillGradient.php b/src/Telegram/Entities/BackgroundFillGradient.php index 5e129c0..2f857fd 100644 --- a/src/Telegram/Entities/BackgroundFillGradient.php +++ b/src/Telegram/Entities/BackgroundFillGradient.php @@ -11,7 +11,7 @@ * @property int $bottom_color * @property int $rotation_angle */ -class BackgroundFillGradient extends Entity +class BackgroundFillGradient extends BackgroundFill { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundFillSolid.php b/src/Telegram/Entities/BackgroundFillSolid.php index affde4d..5cb65a0 100644 --- a/src/Telegram/Entities/BackgroundFillSolid.php +++ b/src/Telegram/Entities/BackgroundFillSolid.php @@ -9,7 +9,7 @@ * @property string $type * @property int $color */ -class BackgroundFillSolid extends Entity +class BackgroundFillSolid extends BackgroundFill { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundTypeChatTheme.php b/src/Telegram/Entities/BackgroundTypeChatTheme.php index 7d1d73b..9372ec3 100644 --- a/src/Telegram/Entities/BackgroundTypeChatTheme.php +++ b/src/Telegram/Entities/BackgroundTypeChatTheme.php @@ -9,7 +9,7 @@ * @property string $type * @property string $theme_name */ -class BackgroundTypeChatTheme extends Entity +class BackgroundTypeChatTheme extends BackgroundType { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundTypeFill.php b/src/Telegram/Entities/BackgroundTypeFill.php index 4c2bf87..501ea31 100644 --- a/src/Telegram/Entities/BackgroundTypeFill.php +++ b/src/Telegram/Entities/BackgroundTypeFill.php @@ -10,7 +10,7 @@ * @property BackgroundFill $fill * @property int $dark_theme_dimming */ -class BackgroundTypeFill extends Entity +class BackgroundTypeFill extends BackgroundType { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundTypePattern.php b/src/Telegram/Entities/BackgroundTypePattern.php index bfab0d5..71e7052 100644 --- a/src/Telegram/Entities/BackgroundTypePattern.php +++ b/src/Telegram/Entities/BackgroundTypePattern.php @@ -13,7 +13,7 @@ * @property bool $is_inverted * @property bool $is_moving */ -class BackgroundTypePattern extends Entity +class BackgroundTypePattern extends BackgroundType { protected function setEntities(): array diff --git a/src/Telegram/Entities/BackgroundTypeWallpaper.php b/src/Telegram/Entities/BackgroundTypeWallpaper.php index f74f19d..89519be 100644 --- a/src/Telegram/Entities/BackgroundTypeWallpaper.php +++ b/src/Telegram/Entities/BackgroundTypeWallpaper.php @@ -12,7 +12,7 @@ * @property bool $is_blurred * @property bool $is_moving */ -class BackgroundTypeWallpaper extends Entity +class BackgroundTypeWallpaper extends BackgroundType { protected function setEntities(): array diff --git a/src/Telegram/Entities/BotCommand.php b/src/Telegram/Entities/BotCommand.php index 5dc7e85..94ef104 100644 --- a/src/Telegram/Entities/BotCommand.php +++ b/src/Telegram/Entities/BotCommand.php @@ -8,6 +8,7 @@ * BotCommand Entity * @property string $command * @property string $description + * @property bool $is_ephemeral */ class BotCommand extends Entity { diff --git a/src/Telegram/Entities/BotCommandScopeAllChatAdministrators.php b/src/Telegram/Entities/BotCommandScopeAllChatAdministrators.php index 97a193a..0fd0e2d 100644 --- a/src/Telegram/Entities/BotCommandScopeAllChatAdministrators.php +++ b/src/Telegram/Entities/BotCommandScopeAllChatAdministrators.php @@ -8,7 +8,7 @@ * BotCommandScopeAllChatAdministrators Entity * @property string $type */ -class BotCommandScopeAllChatAdministrators extends Entity +class BotCommandScopeAllChatAdministrators extends BotCommandScope { protected function setEntities(): array diff --git a/src/Telegram/Entities/BotCommandScopeAllGroupChats.php b/src/Telegram/Entities/BotCommandScopeAllGroupChats.php index 3de97e0..d7190ac 100644 --- a/src/Telegram/Entities/BotCommandScopeAllGroupChats.php +++ b/src/Telegram/Entities/BotCommandScopeAllGroupChats.php @@ -8,7 +8,7 @@ * BotCommandScopeAllGroupChats Entity * @property string $type */ -class BotCommandScopeAllGroupChats extends Entity +class BotCommandScopeAllGroupChats extends BotCommandScope { protected function setEntities(): array diff --git a/src/Telegram/Entities/BotCommandScopeAllPrivateChats.php b/src/Telegram/Entities/BotCommandScopeAllPrivateChats.php index f6c6f63..70b5162 100644 --- a/src/Telegram/Entities/BotCommandScopeAllPrivateChats.php +++ b/src/Telegram/Entities/BotCommandScopeAllPrivateChats.php @@ -8,7 +8,7 @@ * BotCommandScopeAllPrivateChats Entity * @property string $type */ -class BotCommandScopeAllPrivateChats extends Entity +class BotCommandScopeAllPrivateChats extends BotCommandScope { protected function setEntities(): array diff --git a/src/Telegram/Entities/BotCommandScopeChat.php b/src/Telegram/Entities/BotCommandScopeChat.php index 18909d0..3f8c653 100644 --- a/src/Telegram/Entities/BotCommandScopeChat.php +++ b/src/Telegram/Entities/BotCommandScopeChat.php @@ -9,13 +9,11 @@ * @property string $type * @property int|string $chat_id */ -class BotCommandScopeChat extends Entity +class BotCommandScopeChat extends BotCommandScope { protected function setEntities(): array { - return [ - 'chat_id' => int|string::class, - ]; + return []; } } diff --git a/src/Telegram/Entities/BotCommandScopeChatAdministrators.php b/src/Telegram/Entities/BotCommandScopeChatAdministrators.php index 589b5b4..1fec114 100644 --- a/src/Telegram/Entities/BotCommandScopeChatAdministrators.php +++ b/src/Telegram/Entities/BotCommandScopeChatAdministrators.php @@ -9,13 +9,11 @@ * @property string $type * @property int|string $chat_id */ -class BotCommandScopeChatAdministrators extends Entity +class BotCommandScopeChatAdministrators extends BotCommandScope { protected function setEntities(): array { - return [ - 'chat_id' => int|string::class, - ]; + return []; } } diff --git a/src/Telegram/Entities/BotCommandScopeChatMember.php b/src/Telegram/Entities/BotCommandScopeChatMember.php index b048eb2..c4b742d 100644 --- a/src/Telegram/Entities/BotCommandScopeChatMember.php +++ b/src/Telegram/Entities/BotCommandScopeChatMember.php @@ -10,13 +10,11 @@ * @property int|string $chat_id * @property int $user_id */ -class BotCommandScopeChatMember extends Entity +class BotCommandScopeChatMember extends BotCommandScope { protected function setEntities(): array { - return [ - 'chat_id' => int|string::class, - ]; + return []; } } diff --git a/src/Telegram/Entities/BotCommandScopeDefault.php b/src/Telegram/Entities/BotCommandScopeDefault.php index 40c8037..27ef50b 100644 --- a/src/Telegram/Entities/BotCommandScopeDefault.php +++ b/src/Telegram/Entities/BotCommandScopeDefault.php @@ -8,7 +8,7 @@ * BotCommandScopeDefault Entity * @property string $type */ -class BotCommandScopeDefault extends Entity +class BotCommandScopeDefault extends BotCommandScope { protected function setEntities(): array diff --git a/src/Telegram/Entities/BotSubscriptionUpdated.php b/src/Telegram/Entities/BotSubscriptionUpdated.php new file mode 100644 index 0000000..8a1c4f1 --- /dev/null +++ b/src/Telegram/Entities/BotSubscriptionUpdated.php @@ -0,0 +1,22 @@ + User::class, + ]; + } +} diff --git a/src/Telegram/Entities/ChatBoostSourceGiftCode.php b/src/Telegram/Entities/ChatBoostSourceGiftCode.php index 77cdab3..259e42f 100644 --- a/src/Telegram/Entities/ChatBoostSourceGiftCode.php +++ b/src/Telegram/Entities/ChatBoostSourceGiftCode.php @@ -9,7 +9,7 @@ * @property string $source * @property User $user */ -class ChatBoostSourceGiftCode extends Entity +class ChatBoostSourceGiftCode extends ChatBoostSource { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatBoostSourceGiveaway.php b/src/Telegram/Entities/ChatBoostSourceGiveaway.php index c5299c7..df7fad9 100644 --- a/src/Telegram/Entities/ChatBoostSourceGiveaway.php +++ b/src/Telegram/Entities/ChatBoostSourceGiveaway.php @@ -12,7 +12,7 @@ * @property int $prize_star_count * @property bool $is_unclaimed */ -class ChatBoostSourceGiveaway extends Entity +class ChatBoostSourceGiveaway extends ChatBoostSource { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatBoostSourcePremium.php b/src/Telegram/Entities/ChatBoostSourcePremium.php index 423974f..aae578c 100644 --- a/src/Telegram/Entities/ChatBoostSourcePremium.php +++ b/src/Telegram/Entities/ChatBoostSourcePremium.php @@ -9,7 +9,7 @@ * @property string $source * @property User $user */ -class ChatBoostSourcePremium extends Entity +class ChatBoostSourcePremium extends ChatBoostSource { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatFullInfo.php b/src/Telegram/Entities/ChatFullInfo.php index d38e23d..75fa355 100644 --- a/src/Telegram/Entities/ChatFullInfo.php +++ b/src/Telegram/Entities/ChatFullInfo.php @@ -57,6 +57,8 @@ * @property Audio $first_profile_audio * @property UniqueGiftColors $unique_gift_colors * @property int $paid_message_star_count + * @property User $guard_bot + * @property Community $community */ class ChatFullInfo extends Entity { @@ -79,6 +81,8 @@ protected function setEntities(): array 'rating' => UserRating::class, 'first_profile_audio' => Audio::class, 'unique_gift_colors' => UniqueGiftColors::class, + 'guard_bot' => User::class, + 'community' => Community::class, ]; } } diff --git a/src/Telegram/Entities/ChatJoinRequest.php b/src/Telegram/Entities/ChatJoinRequest.php index c29822b..f02a92f 100644 --- a/src/Telegram/Entities/ChatJoinRequest.php +++ b/src/Telegram/Entities/ChatJoinRequest.php @@ -12,6 +12,7 @@ * @property int $date * @property string $bio * @property ChatInviteLink $invite_link + * @property string $query_id */ class ChatJoinRequest extends Entity { diff --git a/src/Telegram/Entities/ChatMemberAdministrator.php b/src/Telegram/Entities/ChatMemberAdministrator.php index 63fa61b..811b7e7 100644 --- a/src/Telegram/Entities/ChatMemberAdministrator.php +++ b/src/Telegram/Entities/ChatMemberAdministrator.php @@ -28,7 +28,7 @@ * @property bool $can_manage_tags * @property string $custom_title */ -class ChatMemberAdministrator extends Entity +class ChatMemberAdministrator extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatMemberBanned.php b/src/Telegram/Entities/ChatMemberBanned.php index 4b8a167..8d36ef8 100644 --- a/src/Telegram/Entities/ChatMemberBanned.php +++ b/src/Telegram/Entities/ChatMemberBanned.php @@ -10,7 +10,7 @@ * @property User $user * @property int $until_date */ -class ChatMemberBanned extends Entity +class ChatMemberBanned extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatMemberLeft.php b/src/Telegram/Entities/ChatMemberLeft.php index 6eaf95d..8b69c9c 100644 --- a/src/Telegram/Entities/ChatMemberLeft.php +++ b/src/Telegram/Entities/ChatMemberLeft.php @@ -9,7 +9,7 @@ * @property string $status * @property User $user */ -class ChatMemberLeft extends Entity +class ChatMemberLeft extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatMemberMember.php b/src/Telegram/Entities/ChatMemberMember.php index 8aa66dc..c230c6c 100644 --- a/src/Telegram/Entities/ChatMemberMember.php +++ b/src/Telegram/Entities/ChatMemberMember.php @@ -11,7 +11,7 @@ * @property User $user * @property int $until_date */ -class ChatMemberMember extends Entity +class ChatMemberMember extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatMemberOwner.php b/src/Telegram/Entities/ChatMemberOwner.php index f08fbd6..8c9733c 100644 --- a/src/Telegram/Entities/ChatMemberOwner.php +++ b/src/Telegram/Entities/ChatMemberOwner.php @@ -11,7 +11,7 @@ * @property bool $is_anonymous * @property string $custom_title */ -class ChatMemberOwner extends Entity +class ChatMemberOwner extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/ChatMemberRestricted.php b/src/Telegram/Entities/ChatMemberRestricted.php index e21aab1..c75331b 100644 --- a/src/Telegram/Entities/ChatMemberRestricted.php +++ b/src/Telegram/Entities/ChatMemberRestricted.php @@ -28,7 +28,7 @@ * @property bool $can_manage_topics * @property int $until_date */ -class ChatMemberRestricted extends Entity +class ChatMemberRestricted extends ChatMember { protected function setEntities(): array diff --git a/src/Telegram/Entities/Community.php b/src/Telegram/Entities/Community.php new file mode 100644 index 0000000..3a71ecd --- /dev/null +++ b/src/Telegram/Entities/Community.php @@ -0,0 +1,19 @@ + Community::class, + ]; + } +} diff --git a/src/Telegram/Entities/CommunityChatRemoved.php b/src/Telegram/Entities/CommunityChatRemoved.php new file mode 100644 index 0000000..0deefd3 --- /dev/null +++ b/src/Telegram/Entities/CommunityChatRemoved.php @@ -0,0 +1,17 @@ + [MessageEntity::class], + ]; + } +} diff --git a/src/Telegram/Entities/InputMessageContent.php b/src/Telegram/Entities/InputMessageContent.php index 6f96aa4..93bbe9e 100644 --- a/src/Telegram/Entities/InputMessageContent.php +++ b/src/Telegram/Entities/InputMessageContent.php @@ -39,6 +39,9 @@ public function resolve(): Entity ) { return new InputLocationMessageContent($this->properties); } + if ($this->hasProperty('html') || $this->hasProperty('markdown')) { + return new InputRichMessageContent($this->properties); + } throw new \InvalidArgumentException('Unknown InputMessageContent'); } @@ -54,6 +57,7 @@ public function resolve(): Entity * | payload | InputInvoiceMessageContent | * | latitude + longitude + title | InputVenueMessageContent | * | latitude + longitude | InputLocationMessageContent | + * | html / markdown | InputRichMessageContent | * @throws \InvalidArgumentException */ public static function create(array $data): Entity @@ -64,6 +68,7 @@ public static function create(array $data): Entity isset($data['payload']) => new InputInvoiceMessageContent($data), isset($data['latitude'], $data['longitude'], $data['title']) => new InputVenueMessageContent($data), isset($data['latitude'], $data['longitude']) => new InputLocationMessageContent($data), + isset($data['html']) || isset($data['markdown']) => new InputRichMessageContent($data), default => throw new \InvalidArgumentException('Unknown InputMessageContent: no valid property found'), }; } diff --git a/src/Telegram/Entities/InputPaidMediaLivePhoto.php b/src/Telegram/Entities/InputPaidMediaLivePhoto.php index 7de8021..58c8f10 100644 --- a/src/Telegram/Entities/InputPaidMediaLivePhoto.php +++ b/src/Telegram/Entities/InputPaidMediaLivePhoto.php @@ -10,7 +10,7 @@ * @property string $media * @property string $photo */ -class InputPaidMediaLivePhoto extends Entity +class InputPaidMediaLivePhoto extends InputPaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputPaidMediaPhoto.php b/src/Telegram/Entities/InputPaidMediaPhoto.php index 64b1a27..f28768a 100644 --- a/src/Telegram/Entities/InputPaidMediaPhoto.php +++ b/src/Telegram/Entities/InputPaidMediaPhoto.php @@ -9,7 +9,7 @@ * @property string $type * @property string $media */ -class InputPaidMediaPhoto extends Entity +class InputPaidMediaPhoto extends InputPaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputPaidMediaVideo.php b/src/Telegram/Entities/InputPaidMediaVideo.php index be46141..f302e34 100644 --- a/src/Telegram/Entities/InputPaidMediaVideo.php +++ b/src/Telegram/Entities/InputPaidMediaVideo.php @@ -16,7 +16,7 @@ * @property int $duration * @property bool $supports_streaming */ -class InputPaidMediaVideo extends Entity +class InputPaidMediaVideo extends InputPaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputPollOptionMedia.php b/src/Telegram/Entities/InputPollOptionMedia.php index 670cf97..57564f0 100644 --- a/src/Telegram/Entities/InputPollOptionMedia.php +++ b/src/Telegram/Entities/InputPollOptionMedia.php @@ -11,6 +11,7 @@ class InputPollOptionMedia extends Entity { public const TYPE_ANIMATION = 'animation'; + public const TYPE_LINK = 'link'; public const TYPE_LIVE_PHOTO = 'live_photo'; public const TYPE_LOCATION = 'location'; public const TYPE_PHOTO = 'photo'; @@ -26,6 +27,7 @@ public function resolve(): Entity { return match($this->type) { 'animation' => new InputMediaAnimation($this->properties), + 'link' => new InputMediaLink($this->properties), 'live_photo' => new InputMediaLivePhoto($this->properties), 'location' => new InputMediaLocation($this->properties), 'photo' => new InputMediaPhoto($this->properties), @@ -45,6 +47,7 @@ public function resolve(): Entity * | type= | Creates | * |-------|----------| * | animation | InputMediaAnimation | + * | link | InputMediaLink | * | live_photo | InputMediaLivePhoto | * | location | InputMediaLocation | * | photo | InputMediaPhoto | @@ -57,6 +60,7 @@ public static function create(array $data): Entity { return match($data['type'] ?? null) { self::TYPE_ANIMATION => new InputMediaAnimation($data), + self::TYPE_LINK => new InputMediaLink($data), self::TYPE_LIVE_PHOTO => new InputMediaLivePhoto($data), self::TYPE_LOCATION => new InputMediaLocation($data), self::TYPE_PHOTO => new InputMediaPhoto($data), diff --git a/src/Telegram/Entities/InputProfilePhotoAnimated.php b/src/Telegram/Entities/InputProfilePhotoAnimated.php index cb2adcd..6911935 100644 --- a/src/Telegram/Entities/InputProfilePhotoAnimated.php +++ b/src/Telegram/Entities/InputProfilePhotoAnimated.php @@ -10,7 +10,7 @@ * @property string $animation * @property float $main_frame_timestamp */ -class InputProfilePhotoAnimated extends Entity +class InputProfilePhotoAnimated extends InputProfilePhoto { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputProfilePhotoStatic.php b/src/Telegram/Entities/InputProfilePhotoStatic.php index b72c32f..91ce485 100644 --- a/src/Telegram/Entities/InputProfilePhotoStatic.php +++ b/src/Telegram/Entities/InputProfilePhotoStatic.php @@ -9,7 +9,7 @@ * @property string $type * @property string $photo */ -class InputProfilePhotoStatic extends Entity +class InputProfilePhotoStatic extends InputProfilePhoto { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputRichBlock.php b/src/Telegram/Entities/InputRichBlock.php new file mode 100644 index 0000000..0f7baa5 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlock.php @@ -0,0 +1,102 @@ +type) { + 'paragraph' => new InputRichBlockParagraph($this->properties), + 'heading' => new InputRichBlockSectionHeading($this->properties), + 'pre' => new InputRichBlockPreformatted($this->properties), + 'footer' => new InputRichBlockFooter($this->properties), + 'divider' => new InputRichBlockDivider($this->properties), + 'mathematical_expression' => new InputRichBlockMathematicalExpression($this->properties), + 'anchor' => new InputRichBlockAnchor($this->properties), + 'list' => new InputRichBlockList($this->properties), + 'blockquote' => new InputRichBlockBlockQuotation($this->properties), + 'pullquote' => new InputRichBlockPullQuotation($this->properties), + 'collage' => new InputRichBlockCollage($this->properties), + 'slideshow' => new InputRichBlockSlideshow($this->properties), + 'table' => new InputRichBlockTable($this->properties), + 'details' => new InputRichBlockDetails($this->properties), + 'map' => new InputRichBlockMap($this->properties), + 'animation' => new InputRichBlockAnimation($this->properties), + 'audio' => new InputRichBlockAudio($this->properties), + 'photo' => new InputRichBlockPhoto($this->properties), + 'video' => new InputRichBlockVideo($this->properties), + 'voice_note' => new InputRichBlockVoiceNote($this->properties), + 'thinking' => new InputRichBlockThinking($this->properties), + default => throw new \InvalidArgumentException('Unknown InputRichBlock type: ' . $this->type), + }; + } + + /** + * Factory: creates the correct subclass based on type + * + * @param array $data Must contain 'type' key + * @return Entity + * @throws \InvalidArgumentException + */ + public static function create(array $data): Entity + { + return match($data['type'] ?? null) { + self::TYPE_PARAGRAPH => new InputRichBlockParagraph($data), + self::TYPE_HEADING => new InputRichBlockSectionHeading($data), + self::TYPE_PREFORMATTED => new InputRichBlockPreformatted($data), + self::TYPE_FOOTER => new InputRichBlockFooter($data), + self::TYPE_DIVIDER => new InputRichBlockDivider($data), + self::TYPE_MATHEMATICAL_EXPRESSION => new InputRichBlockMathematicalExpression($data), + self::TYPE_ANCHOR => new InputRichBlockAnchor($data), + self::TYPE_LIST => new InputRichBlockList($data), + self::TYPE_BLOCK_QUOTATION => new InputRichBlockBlockQuotation($data), + self::TYPE_PULL_QUOTATION => new InputRichBlockPullQuotation($data), + self::TYPE_COLLAGE => new InputRichBlockCollage($data), + self::TYPE_SLIDESHOW => new InputRichBlockSlideshow($data), + self::TYPE_TABLE => new InputRichBlockTable($data), + self::TYPE_DETAILS => new InputRichBlockDetails($data), + self::TYPE_MAP => new InputRichBlockMap($data), + self::TYPE_ANIMATION => new InputRichBlockAnimation($data), + self::TYPE_AUDIO => new InputRichBlockAudio($data), + self::TYPE_PHOTO => new InputRichBlockPhoto($data), + self::TYPE_VIDEO => new InputRichBlockVideo($data), + self::TYPE_VOICE_NOTE => new InputRichBlockVoiceNote($data), + self::TYPE_THINKING => new InputRichBlockThinking($data), + default => throw new \InvalidArgumentException('Unknown InputRichBlock type: ' . ($data['type'] ?? 'null')), + }; + } + +} diff --git a/src/Telegram/Entities/InputRichBlockAnchor.php b/src/Telegram/Entities/InputRichBlockAnchor.php new file mode 100644 index 0000000..5f71848 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockAnchor.php @@ -0,0 +1,19 @@ + InputMediaAnimation::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockAudio.php b/src/Telegram/Entities/InputRichBlockAudio.php new file mode 100644 index 0000000..299e5d7 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockAudio.php @@ -0,0 +1,23 @@ + InputMediaAudio::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockBlockQuotation.php b/src/Telegram/Entities/InputRichBlockBlockQuotation.php new file mode 100644 index 0000000..b0a21e4 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockBlockQuotation.php @@ -0,0 +1,23 @@ + [InputRichBlock::class], + 'credit' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockCollage.php b/src/Telegram/Entities/InputRichBlockCollage.php new file mode 100644 index 0000000..8935c75 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockCollage.php @@ -0,0 +1,23 @@ + [InputRichBlock::class], + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockDetails.php b/src/Telegram/Entities/InputRichBlockDetails.php new file mode 100644 index 0000000..ac079b4 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockDetails.php @@ -0,0 +1,24 @@ + RichText::class, + 'blocks' => [InputRichBlock::class], + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockDivider.php b/src/Telegram/Entities/InputRichBlockDivider.php new file mode 100644 index 0000000..3ff4fe3 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockDivider.php @@ -0,0 +1,18 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockList.php b/src/Telegram/Entities/InputRichBlockList.php new file mode 100644 index 0000000..fd75f44 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockList.php @@ -0,0 +1,21 @@ + [InputRichBlockListItem::class], + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockListItem.php b/src/Telegram/Entities/InputRichBlockListItem.php new file mode 100644 index 0000000..4a6b092 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockListItem.php @@ -0,0 +1,24 @@ + [InputRichBlock::class], + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockMap.php b/src/Telegram/Entities/InputRichBlockMap.php new file mode 100644 index 0000000..e60c52a --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockMap.php @@ -0,0 +1,26 @@ + Location::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockMathematicalExpression.php b/src/Telegram/Entities/InputRichBlockMathematicalExpression.php new file mode 100644 index 0000000..843da9f --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockMathematicalExpression.php @@ -0,0 +1,19 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockPhoto.php b/src/Telegram/Entities/InputRichBlockPhoto.php new file mode 100644 index 0000000..df2844c --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockPhoto.php @@ -0,0 +1,23 @@ + InputMediaPhoto::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockPreformatted.php b/src/Telegram/Entities/InputRichBlockPreformatted.php new file mode 100644 index 0000000..5dec49f --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockPreformatted.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockPullQuotation.php b/src/Telegram/Entities/InputRichBlockPullQuotation.php new file mode 100644 index 0000000..7c8af19 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockPullQuotation.php @@ -0,0 +1,23 @@ + RichText::class, + 'credit' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockSectionHeading.php b/src/Telegram/Entities/InputRichBlockSectionHeading.php new file mode 100644 index 0000000..115d217 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockSectionHeading.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockSlideshow.php b/src/Telegram/Entities/InputRichBlockSlideshow.php new file mode 100644 index 0000000..f956120 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockSlideshow.php @@ -0,0 +1,23 @@ + [InputRichBlock::class], + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockTable.php b/src/Telegram/Entities/InputRichBlockTable.php new file mode 100644 index 0000000..2acb5b7 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockTable.php @@ -0,0 +1,25 @@ + [RichBlockTableCell::class], + 'caption' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockThinking.php b/src/Telegram/Entities/InputRichBlockThinking.php new file mode 100644 index 0000000..3b55a9c --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockThinking.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockVideo.php b/src/Telegram/Entities/InputRichBlockVideo.php new file mode 100644 index 0000000..68d4b45 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockVideo.php @@ -0,0 +1,23 @@ + InputMediaVideo::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichBlockVoiceNote.php b/src/Telegram/Entities/InputRichBlockVoiceNote.php new file mode 100644 index 0000000..8e0ee91 --- /dev/null +++ b/src/Telegram/Entities/InputRichBlockVoiceNote.php @@ -0,0 +1,23 @@ + InputMediaVoiceNote::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichMessage.php b/src/Telegram/Entities/InputRichMessage.php new file mode 100644 index 0000000..930fe08 --- /dev/null +++ b/src/Telegram/Entities/InputRichMessage.php @@ -0,0 +1,26 @@ + [InputRichBlock::class], + 'media' => [InputRichMessageMedia::class], + ]; + } +} diff --git a/src/Telegram/Entities/InputRichMessageContent.php b/src/Telegram/Entities/InputRichMessageContent.php new file mode 100644 index 0000000..2cd68cd --- /dev/null +++ b/src/Telegram/Entities/InputRichMessageContent.php @@ -0,0 +1,20 @@ + InputRichMessage::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputRichMessageMedia.php b/src/Telegram/Entities/InputRichMessageMedia.php new file mode 100644 index 0000000..099e4d7 --- /dev/null +++ b/src/Telegram/Entities/InputRichMessageMedia.php @@ -0,0 +1,21 @@ + InputMediaAnimation::class, + ]; + } +} diff --git a/src/Telegram/Entities/InputStoryContentPhoto.php b/src/Telegram/Entities/InputStoryContentPhoto.php index bd13a78..4e0a4e0 100644 --- a/src/Telegram/Entities/InputStoryContentPhoto.php +++ b/src/Telegram/Entities/InputStoryContentPhoto.php @@ -9,7 +9,7 @@ * @property string $type * @property string $photo */ -class InputStoryContentPhoto extends Entity +class InputStoryContentPhoto extends InputStoryContent { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputStoryContentVideo.php b/src/Telegram/Entities/InputStoryContentVideo.php index cabb974..ea09e84 100644 --- a/src/Telegram/Entities/InputStoryContentVideo.php +++ b/src/Telegram/Entities/InputStoryContentVideo.php @@ -12,7 +12,7 @@ * @property float $cover_frame_timestamp * @property bool $is_animation */ -class InputStoryContentVideo extends Entity +class InputStoryContentVideo extends InputStoryContent { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputTextMessageContent.php b/src/Telegram/Entities/InputTextMessageContent.php index 99137f1..85faf59 100644 --- a/src/Telegram/Entities/InputTextMessageContent.php +++ b/src/Telegram/Entities/InputTextMessageContent.php @@ -11,7 +11,7 @@ * @property MessageEntity[] $entities * @property LinkPreviewOptions $link_preview_options */ -class InputTextMessageContent extends Entity +class InputTextMessageContent extends InputMessageContent { protected function setEntities(): array diff --git a/src/Telegram/Entities/InputVenueMessageContent.php b/src/Telegram/Entities/InputVenueMessageContent.php index 04acf3c..2de4383 100644 --- a/src/Telegram/Entities/InputVenueMessageContent.php +++ b/src/Telegram/Entities/InputVenueMessageContent.php @@ -15,7 +15,7 @@ * @property string $google_place_id * @property string $google_place_type */ -class InputVenueMessageContent extends Entity +class InputVenueMessageContent extends InputMessageContent { protected function setEntities(): array diff --git a/src/Telegram/Entities/Link.php b/src/Telegram/Entities/Link.php new file mode 100644 index 0000000..2e70c6e --- /dev/null +++ b/src/Telegram/Entities/Link.php @@ -0,0 +1,18 @@ + User::class, 'sender_chat' => Chat::class, 'sender_business_bot' => User::class, + 'receiver_user' => User::class, 'chat' => Chat::class, 'forward_origin' => MessageOrigin::class, 'reply_to_message' => Message::class, @@ -143,6 +149,7 @@ protected function setEntities(): array 'entities' => [MessageEntity::class], 'link_preview_options' => LinkPreviewOptions::class, 'suggested_post_info' => SuggestedPostInfo::class, + 'rich_message' => RichMessage::class, 'animation' => Animation::class, 'audio' => Audio::class, 'document' => Document::class, @@ -184,6 +191,8 @@ protected function setEntities(): array 'chat_background_set' => ChatBackground::class, 'checklist_tasks_done' => ChecklistTasksDone::class, 'checklist_tasks_added' => ChecklistTasksAdded::class, + 'community_chat_added' => CommunityChatAdded::class, + 'community_chat_removed' => CommunityChatRemoved::class, 'direct_message_price_changed' => DirectMessagePriceChanged::class, 'forum_topic_created' => ForumTopicCreated::class, 'forum_topic_edited' => ForumTopicEdited::class, diff --git a/src/Telegram/Entities/MessageOriginChannel.php b/src/Telegram/Entities/MessageOriginChannel.php index 94beb81..9329127 100644 --- a/src/Telegram/Entities/MessageOriginChannel.php +++ b/src/Telegram/Entities/MessageOriginChannel.php @@ -12,7 +12,7 @@ * @property int $message_id * @property string $author_signature */ -class MessageOriginChannel extends Entity +class MessageOriginChannel extends MessageOrigin { protected function setEntities(): array diff --git a/src/Telegram/Entities/MessageOriginChat.php b/src/Telegram/Entities/MessageOriginChat.php index 1245ad0..3437c8a 100644 --- a/src/Telegram/Entities/MessageOriginChat.php +++ b/src/Telegram/Entities/MessageOriginChat.php @@ -11,7 +11,7 @@ * @property Chat $sender_chat * @property string $author_signature */ -class MessageOriginChat extends Entity +class MessageOriginChat extends MessageOrigin { protected function setEntities(): array diff --git a/src/Telegram/Entities/MessageOriginHiddenUser.php b/src/Telegram/Entities/MessageOriginHiddenUser.php index 5307c79..579660c 100644 --- a/src/Telegram/Entities/MessageOriginHiddenUser.php +++ b/src/Telegram/Entities/MessageOriginHiddenUser.php @@ -10,7 +10,7 @@ * @property int $date * @property string $sender_user_name */ -class MessageOriginHiddenUser extends Entity +class MessageOriginHiddenUser extends MessageOrigin { protected function setEntities(): array diff --git a/src/Telegram/Entities/MessageOriginUser.php b/src/Telegram/Entities/MessageOriginUser.php index eb19381..9bbb4fd 100644 --- a/src/Telegram/Entities/MessageOriginUser.php +++ b/src/Telegram/Entities/MessageOriginUser.php @@ -10,7 +10,7 @@ * @property int $date * @property User $sender_user */ -class MessageOriginUser extends Entity +class MessageOriginUser extends MessageOrigin { protected function setEntities(): array diff --git a/src/Telegram/Entities/OwnedGiftRegular.php b/src/Telegram/Entities/OwnedGiftRegular.php index 0ee56e5..f14b242 100644 --- a/src/Telegram/Entities/OwnedGiftRegular.php +++ b/src/Telegram/Entities/OwnedGiftRegular.php @@ -22,7 +22,7 @@ * @property bool $is_upgrade_separate * @property int $unique_gift_number */ -class OwnedGiftRegular extends Entity +class OwnedGiftRegular extends OwnedGift { protected function setEntities(): array diff --git a/src/Telegram/Entities/OwnedGiftUnique.php b/src/Telegram/Entities/OwnedGiftUnique.php index dcfc700..218cd8f 100644 --- a/src/Telegram/Entities/OwnedGiftUnique.php +++ b/src/Telegram/Entities/OwnedGiftUnique.php @@ -16,7 +16,7 @@ * @property int $transfer_star_count * @property int $next_transfer_date */ -class OwnedGiftUnique extends Entity +class OwnedGiftUnique extends OwnedGift { protected function setEntities(): array diff --git a/src/Telegram/Entities/PaidMediaLivePhoto.php b/src/Telegram/Entities/PaidMediaLivePhoto.php index df78304..b57ff66 100644 --- a/src/Telegram/Entities/PaidMediaLivePhoto.php +++ b/src/Telegram/Entities/PaidMediaLivePhoto.php @@ -9,7 +9,7 @@ * @property string $type * @property LivePhoto $live_photo */ -class PaidMediaLivePhoto extends Entity +class PaidMediaLivePhoto extends PaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/PaidMediaPhoto.php b/src/Telegram/Entities/PaidMediaPhoto.php index 71dbd9b..d75acb7 100644 --- a/src/Telegram/Entities/PaidMediaPhoto.php +++ b/src/Telegram/Entities/PaidMediaPhoto.php @@ -9,7 +9,7 @@ * @property string $type * @property PhotoSize[] $photo */ -class PaidMediaPhoto extends Entity +class PaidMediaPhoto extends PaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/PaidMediaPreview.php b/src/Telegram/Entities/PaidMediaPreview.php index 66b2431..14fb456 100644 --- a/src/Telegram/Entities/PaidMediaPreview.php +++ b/src/Telegram/Entities/PaidMediaPreview.php @@ -11,7 +11,7 @@ * @property int $height * @property int $duration */ -class PaidMediaPreview extends Entity +class PaidMediaPreview extends PaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/PaidMediaVideo.php b/src/Telegram/Entities/PaidMediaVideo.php index 484fcab..28132cc 100644 --- a/src/Telegram/Entities/PaidMediaVideo.php +++ b/src/Telegram/Entities/PaidMediaVideo.php @@ -9,7 +9,7 @@ * @property string $type * @property Video $video */ -class PaidMediaVideo extends Entity +class PaidMediaVideo extends PaidMedia { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorDataField.php b/src/Telegram/Entities/PassportElementErrorDataField.php index 0218295..4281e3f 100644 --- a/src/Telegram/Entities/PassportElementErrorDataField.php +++ b/src/Telegram/Entities/PassportElementErrorDataField.php @@ -12,7 +12,7 @@ * @property string $data_hash * @property string $message */ -class PassportElementErrorDataField extends Entity +class PassportElementErrorDataField extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorFile.php b/src/Telegram/Entities/PassportElementErrorFile.php index 25c97db..e1ebe88 100644 --- a/src/Telegram/Entities/PassportElementErrorFile.php +++ b/src/Telegram/Entities/PassportElementErrorFile.php @@ -11,7 +11,7 @@ * @property string $file_hash * @property string $message */ -class PassportElementErrorFile extends Entity +class PassportElementErrorFile extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorFiles.php b/src/Telegram/Entities/PassportElementErrorFiles.php index c161760..6a31688 100644 --- a/src/Telegram/Entities/PassportElementErrorFiles.php +++ b/src/Telegram/Entities/PassportElementErrorFiles.php @@ -11,7 +11,7 @@ * @property array $file_hashes * @property string $message */ -class PassportElementErrorFiles extends Entity +class PassportElementErrorFiles extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorFrontSide.php b/src/Telegram/Entities/PassportElementErrorFrontSide.php index 8910698..266b768 100644 --- a/src/Telegram/Entities/PassportElementErrorFrontSide.php +++ b/src/Telegram/Entities/PassportElementErrorFrontSide.php @@ -11,7 +11,7 @@ * @property string $file_hash * @property string $message */ -class PassportElementErrorFrontSide extends Entity +class PassportElementErrorFrontSide extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorReverseSide.php b/src/Telegram/Entities/PassportElementErrorReverseSide.php index 58b508f..374ef20 100644 --- a/src/Telegram/Entities/PassportElementErrorReverseSide.php +++ b/src/Telegram/Entities/PassportElementErrorReverseSide.php @@ -11,7 +11,7 @@ * @property string $file_hash * @property string $message */ -class PassportElementErrorReverseSide extends Entity +class PassportElementErrorReverseSide extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorSelfie.php b/src/Telegram/Entities/PassportElementErrorSelfie.php index 19b10f1..15080a5 100644 --- a/src/Telegram/Entities/PassportElementErrorSelfie.php +++ b/src/Telegram/Entities/PassportElementErrorSelfie.php @@ -11,7 +11,7 @@ * @property string $file_hash * @property string $message */ -class PassportElementErrorSelfie extends Entity +class PassportElementErrorSelfie extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorTranslationFile.php b/src/Telegram/Entities/PassportElementErrorTranslationFile.php index baff99e..956fb6b 100644 --- a/src/Telegram/Entities/PassportElementErrorTranslationFile.php +++ b/src/Telegram/Entities/PassportElementErrorTranslationFile.php @@ -11,7 +11,7 @@ * @property string $file_hash * @property string $message */ -class PassportElementErrorTranslationFile extends Entity +class PassportElementErrorTranslationFile extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorTranslationFiles.php b/src/Telegram/Entities/PassportElementErrorTranslationFiles.php index df7657c..6089636 100644 --- a/src/Telegram/Entities/PassportElementErrorTranslationFiles.php +++ b/src/Telegram/Entities/PassportElementErrorTranslationFiles.php @@ -11,7 +11,7 @@ * @property array $file_hashes * @property string $message */ -class PassportElementErrorTranslationFiles extends Entity +class PassportElementErrorTranslationFiles extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PassportElementErrorUnspecified.php b/src/Telegram/Entities/PassportElementErrorUnspecified.php index 033f326..fee8e63 100644 --- a/src/Telegram/Entities/PassportElementErrorUnspecified.php +++ b/src/Telegram/Entities/PassportElementErrorUnspecified.php @@ -11,7 +11,7 @@ * @property string $element_hash * @property string $message */ -class PassportElementErrorUnspecified extends Entity +class PassportElementErrorUnspecified extends PassportElementError { protected function setEntities(): array diff --git a/src/Telegram/Entities/PollMedia.php b/src/Telegram/Entities/PollMedia.php index 2cd5670..9f74051 100644 --- a/src/Telegram/Entities/PollMedia.php +++ b/src/Telegram/Entities/PollMedia.php @@ -9,6 +9,7 @@ * @property Animation $animation * @property Audio $audio * @property Document $document + * @property Link $link * @property LivePhoto $live_photo * @property Location $location * @property PhotoSize[] $photo @@ -25,6 +26,7 @@ protected function setEntities(): array 'animation' => Animation::class, 'audio' => Audio::class, 'document' => Document::class, + 'link' => Link::class, 'live_photo' => LivePhoto::class, 'location' => Location::class, 'photo' => [PhotoSize::class], diff --git a/src/Telegram/Entities/ReactionTypeCustomEmoji.php b/src/Telegram/Entities/ReactionTypeCustomEmoji.php index 3e13e65..2dc64df 100644 --- a/src/Telegram/Entities/ReactionTypeCustomEmoji.php +++ b/src/Telegram/Entities/ReactionTypeCustomEmoji.php @@ -9,7 +9,7 @@ * @property string $type * @property string $custom_emoji_id */ -class ReactionTypeCustomEmoji extends Entity +class ReactionTypeCustomEmoji extends ReactionType { protected function setEntities(): array diff --git a/src/Telegram/Entities/ReactionTypeEmoji.php b/src/Telegram/Entities/ReactionTypeEmoji.php index f03875f..3f6c734 100644 --- a/src/Telegram/Entities/ReactionTypeEmoji.php +++ b/src/Telegram/Entities/ReactionTypeEmoji.php @@ -9,7 +9,7 @@ * @property string $type * @property string $emoji */ -class ReactionTypeEmoji extends Entity +class ReactionTypeEmoji extends ReactionType { protected function setEntities(): array diff --git a/src/Telegram/Entities/ReactionTypePaid.php b/src/Telegram/Entities/ReactionTypePaid.php index 7fb9e4c..e504053 100644 --- a/src/Telegram/Entities/ReactionTypePaid.php +++ b/src/Telegram/Entities/ReactionTypePaid.php @@ -8,7 +8,7 @@ * ReactionTypePaid Entity * @property string $type */ -class ReactionTypePaid extends Entity +class ReactionTypePaid extends ReactionType { protected function setEntities(): array diff --git a/src/Telegram/Entities/ReplyParameters.php b/src/Telegram/Entities/ReplyParameters.php index 191182c..ddf2cdc 100644 --- a/src/Telegram/Entities/ReplyParameters.php +++ b/src/Telegram/Entities/ReplyParameters.php @@ -8,6 +8,7 @@ * ReplyParameters Entity * @property int $message_id * @property int|string $chat_id + * @property int $ephemeral_message_id * @property bool $allow_sending_without_reply * @property string $quote * @property string $quote_parse_mode @@ -22,7 +23,6 @@ class ReplyParameters extends Entity protected function setEntities(): array { return [ - 'chat_id' => int|string::class, 'quote_entities' => [MessageEntity::class], ]; } diff --git a/src/Telegram/Entities/RevenueWithdrawalStateFailed.php b/src/Telegram/Entities/RevenueWithdrawalStateFailed.php index c9126ab..75400e3 100644 --- a/src/Telegram/Entities/RevenueWithdrawalStateFailed.php +++ b/src/Telegram/Entities/RevenueWithdrawalStateFailed.php @@ -8,7 +8,7 @@ * RevenueWithdrawalStateFailed Entity * @property string $type */ -class RevenueWithdrawalStateFailed extends Entity +class RevenueWithdrawalStateFailed extends RevenueWithdrawalState { protected function setEntities(): array diff --git a/src/Telegram/Entities/RevenueWithdrawalStatePending.php b/src/Telegram/Entities/RevenueWithdrawalStatePending.php index dac2833..1b900f6 100644 --- a/src/Telegram/Entities/RevenueWithdrawalStatePending.php +++ b/src/Telegram/Entities/RevenueWithdrawalStatePending.php @@ -8,7 +8,7 @@ * RevenueWithdrawalStatePending Entity * @property string $type */ -class RevenueWithdrawalStatePending extends Entity +class RevenueWithdrawalStatePending extends RevenueWithdrawalState { protected function setEntities(): array diff --git a/src/Telegram/Entities/RevenueWithdrawalStateSucceeded.php b/src/Telegram/Entities/RevenueWithdrawalStateSucceeded.php index 383118b..bba9130 100644 --- a/src/Telegram/Entities/RevenueWithdrawalStateSucceeded.php +++ b/src/Telegram/Entities/RevenueWithdrawalStateSucceeded.php @@ -10,7 +10,7 @@ * @property int $date * @property string $url */ -class RevenueWithdrawalStateSucceeded extends Entity +class RevenueWithdrawalStateSucceeded extends RevenueWithdrawalState { protected function setEntities(): array diff --git a/src/Telegram/Entities/RichBlock.php b/src/Telegram/Entities/RichBlock.php new file mode 100644 index 0000000..186c39a --- /dev/null +++ b/src/Telegram/Entities/RichBlock.php @@ -0,0 +1,102 @@ +type) { + 'paragraph' => new RichBlockParagraph($this->properties), + 'heading' => new RichBlockSectionHeading($this->properties), + 'pre' => new RichBlockPreformatted($this->properties), + 'footer' => new RichBlockFooter($this->properties), + 'divider' => new RichBlockDivider($this->properties), + 'mathematical_expression' => new RichBlockMathematicalExpression($this->properties), + 'anchor' => new RichBlockAnchor($this->properties), + 'list' => new RichBlockList($this->properties), + 'blockquote' => new RichBlockBlockQuotation($this->properties), + 'pullquote' => new RichBlockPullQuotation($this->properties), + 'collage' => new RichBlockCollage($this->properties), + 'slideshow' => new RichBlockSlideshow($this->properties), + 'table' => new RichBlockTable($this->properties), + 'details' => new RichBlockDetails($this->properties), + 'map' => new RichBlockMap($this->properties), + 'animation' => new RichBlockAnimation($this->properties), + 'audio' => new RichBlockAudio($this->properties), + 'photo' => new RichBlockPhoto($this->properties), + 'video' => new RichBlockVideo($this->properties), + 'voice_note' => new RichBlockVoiceNote($this->properties), + 'thinking' => new RichBlockThinking($this->properties), + default => throw new \InvalidArgumentException('Unknown RichBlock type: ' . $this->type), + }; + } + + /** + * Factory: creates the correct subclass based on type + * + * @param array $data Must contain 'type' key + * @return Entity + * @throws \InvalidArgumentException + */ + public static function create(array $data): Entity + { + return match($data['type'] ?? null) { + self::TYPE_PARAGRAPH => new RichBlockParagraph($data), + self::TYPE_HEADING => new RichBlockSectionHeading($data), + self::TYPE_PREFORMATTED => new RichBlockPreformatted($data), + self::TYPE_FOOTER => new RichBlockFooter($data), + self::TYPE_DIVIDER => new RichBlockDivider($data), + self::TYPE_MATHEMATICAL_EXPRESSION => new RichBlockMathematicalExpression($data), + self::TYPE_ANCHOR => new RichBlockAnchor($data), + self::TYPE_LIST => new RichBlockList($data), + self::TYPE_BLOCK_QUOTATION => new RichBlockBlockQuotation($data), + self::TYPE_PULL_QUOTATION => new RichBlockPullQuotation($data), + self::TYPE_COLLAGE => new RichBlockCollage($data), + self::TYPE_SLIDESHOW => new RichBlockSlideshow($data), + self::TYPE_TABLE => new RichBlockTable($data), + self::TYPE_DETAILS => new RichBlockDetails($data), + self::TYPE_MAP => new RichBlockMap($data), + self::TYPE_ANIMATION => new RichBlockAnimation($data), + self::TYPE_AUDIO => new RichBlockAudio($data), + self::TYPE_PHOTO => new RichBlockPhoto($data), + self::TYPE_VIDEO => new RichBlockVideo($data), + self::TYPE_VOICE_NOTE => new RichBlockVoiceNote($data), + self::TYPE_THINKING => new RichBlockThinking($data), + default => throw new \InvalidArgumentException('Unknown RichBlock type: ' . ($data['type'] ?? 'null')), + }; + } + +} diff --git a/src/Telegram/Entities/RichBlockAnchor.php b/src/Telegram/Entities/RichBlockAnchor.php new file mode 100644 index 0000000..42ed1b2 --- /dev/null +++ b/src/Telegram/Entities/RichBlockAnchor.php @@ -0,0 +1,19 @@ + Animation::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockAudio.php b/src/Telegram/Entities/RichBlockAudio.php new file mode 100644 index 0000000..55f2bd4 --- /dev/null +++ b/src/Telegram/Entities/RichBlockAudio.php @@ -0,0 +1,23 @@ + Audio::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockBlockQuotation.php b/src/Telegram/Entities/RichBlockBlockQuotation.php new file mode 100644 index 0000000..10c4719 --- /dev/null +++ b/src/Telegram/Entities/RichBlockBlockQuotation.php @@ -0,0 +1,23 @@ + [RichBlock::class], + 'credit' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockCaption.php b/src/Telegram/Entities/RichBlockCaption.php new file mode 100644 index 0000000..017a7f3 --- /dev/null +++ b/src/Telegram/Entities/RichBlockCaption.php @@ -0,0 +1,22 @@ + RichText::class, + 'credit' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockCollage.php b/src/Telegram/Entities/RichBlockCollage.php new file mode 100644 index 0000000..1f54b54 --- /dev/null +++ b/src/Telegram/Entities/RichBlockCollage.php @@ -0,0 +1,23 @@ + [RichBlock::class], + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockDetails.php b/src/Telegram/Entities/RichBlockDetails.php new file mode 100644 index 0000000..9bbb4e9 --- /dev/null +++ b/src/Telegram/Entities/RichBlockDetails.php @@ -0,0 +1,24 @@ + RichText::class, + 'blocks' => [RichBlock::class], + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockDivider.php b/src/Telegram/Entities/RichBlockDivider.php new file mode 100644 index 0000000..b4f755e --- /dev/null +++ b/src/Telegram/Entities/RichBlockDivider.php @@ -0,0 +1,18 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockList.php b/src/Telegram/Entities/RichBlockList.php new file mode 100644 index 0000000..ab22025 --- /dev/null +++ b/src/Telegram/Entities/RichBlockList.php @@ -0,0 +1,21 @@ + [RichBlockListItem::class], + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockListItem.php b/src/Telegram/Entities/RichBlockListItem.php new file mode 100644 index 0000000..103895e --- /dev/null +++ b/src/Telegram/Entities/RichBlockListItem.php @@ -0,0 +1,25 @@ + [RichBlock::class], + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockMap.php b/src/Telegram/Entities/RichBlockMap.php new file mode 100644 index 0000000..f67f071 --- /dev/null +++ b/src/Telegram/Entities/RichBlockMap.php @@ -0,0 +1,26 @@ + Location::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockMathematicalExpression.php b/src/Telegram/Entities/RichBlockMathematicalExpression.php new file mode 100644 index 0000000..99db397 --- /dev/null +++ b/src/Telegram/Entities/RichBlockMathematicalExpression.php @@ -0,0 +1,19 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockPhoto.php b/src/Telegram/Entities/RichBlockPhoto.php new file mode 100644 index 0000000..ee4370e --- /dev/null +++ b/src/Telegram/Entities/RichBlockPhoto.php @@ -0,0 +1,24 @@ + [PhotoSize::class], + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockPreformatted.php b/src/Telegram/Entities/RichBlockPreformatted.php new file mode 100644 index 0000000..ccff2a2 --- /dev/null +++ b/src/Telegram/Entities/RichBlockPreformatted.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockPullQuotation.php b/src/Telegram/Entities/RichBlockPullQuotation.php new file mode 100644 index 0000000..6da38fd --- /dev/null +++ b/src/Telegram/Entities/RichBlockPullQuotation.php @@ -0,0 +1,23 @@ + RichText::class, + 'credit' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockSectionHeading.php b/src/Telegram/Entities/RichBlockSectionHeading.php new file mode 100644 index 0000000..2ff4418 --- /dev/null +++ b/src/Telegram/Entities/RichBlockSectionHeading.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockSlideshow.php b/src/Telegram/Entities/RichBlockSlideshow.php new file mode 100644 index 0000000..8b63b17 --- /dev/null +++ b/src/Telegram/Entities/RichBlockSlideshow.php @@ -0,0 +1,23 @@ + [RichBlock::class], + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockTable.php b/src/Telegram/Entities/RichBlockTable.php new file mode 100644 index 0000000..045923e --- /dev/null +++ b/src/Telegram/Entities/RichBlockTable.php @@ -0,0 +1,25 @@ + [RichBlockTableCell::class], + 'caption' => RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockTableCell.php b/src/Telegram/Entities/RichBlockTableCell.php new file mode 100644 index 0000000..f649272 --- /dev/null +++ b/src/Telegram/Entities/RichBlockTableCell.php @@ -0,0 +1,25 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockThinking.php b/src/Telegram/Entities/RichBlockThinking.php new file mode 100644 index 0000000..e0e709d --- /dev/null +++ b/src/Telegram/Entities/RichBlockThinking.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockVideo.php b/src/Telegram/Entities/RichBlockVideo.php new file mode 100644 index 0000000..84e754f --- /dev/null +++ b/src/Telegram/Entities/RichBlockVideo.php @@ -0,0 +1,24 @@ + Video::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichBlockVoiceNote.php b/src/Telegram/Entities/RichBlockVoiceNote.php new file mode 100644 index 0000000..d7e765e --- /dev/null +++ b/src/Telegram/Entities/RichBlockVoiceNote.php @@ -0,0 +1,23 @@ + Voice::class, + 'caption' => RichBlockCaption::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichMessage.php b/src/Telegram/Entities/RichMessage.php new file mode 100644 index 0000000..cbe3f0d --- /dev/null +++ b/src/Telegram/Entities/RichMessage.php @@ -0,0 +1,21 @@ + [RichBlock::class], + ]; + } +} diff --git a/src/Telegram/Entities/RichText.php b/src/Telegram/Entities/RichText.php new file mode 100644 index 0000000..9f2b92f --- /dev/null +++ b/src/Telegram/Entities/RichText.php @@ -0,0 +1,114 @@ +type) { + 'bold' => new RichTextBold($this->properties), + 'italic' => new RichTextItalic($this->properties), + 'underline' => new RichTextUnderline($this->properties), + 'strikethrough' => new RichTextStrikethrough($this->properties), + 'spoiler' => new RichTextSpoiler($this->properties), + 'date_time' => new RichTextDateTime($this->properties), + 'text_mention' => new RichTextTextMention($this->properties), + 'subscript' => new RichTextSubscript($this->properties), + 'superscript' => new RichTextSuperscript($this->properties), + 'marked' => new RichTextMarked($this->properties), + 'code' => new RichTextCode($this->properties), + 'custom_emoji' => new RichTextCustomEmoji($this->properties), + 'mathematical_expression' => new RichTextMathematicalExpression($this->properties), + 'url' => new RichTextUrl($this->properties), + 'email_address' => new RichTextEmailAddress($this->properties), + 'phone_number' => new RichTextPhoneNumber($this->properties), + 'bank_card_number' => new RichTextBankCardNumber($this->properties), + 'mention' => new RichTextMention($this->properties), + 'hashtag' => new RichTextHashtag($this->properties), + 'cashtag' => new RichTextCashtag($this->properties), + 'bot_command' => new RichTextBotCommand($this->properties), + 'anchor' => new RichTextAnchor($this->properties), + 'anchor_link' => new RichTextAnchorLink($this->properties), + 'reference' => new RichTextReference($this->properties), + 'reference_link' => new RichTextReferenceLink($this->properties), + default => throw new \InvalidArgumentException('Unknown RichText type: ' . $this->type), + }; + } + + /** + * Factory: creates the correct subclass based on type + * + * @param array $data Must contain 'type' key + * @return Entity + * @throws \InvalidArgumentException + */ + public static function create(array $data): Entity + { + return match($data['type'] ?? null) { + self::TYPE_BOLD => new RichTextBold($data), + self::TYPE_ITALIC => new RichTextItalic($data), + self::TYPE_UNDERLINE => new RichTextUnderline($data), + self::TYPE_STRIKETHROUGH => new RichTextStrikethrough($data), + self::TYPE_SPOILER => new RichTextSpoiler($data), + self::TYPE_DATETIME => new RichTextDateTime($data), + self::TYPE_TEXT_MENTION => new RichTextTextMention($data), + self::TYPE_SUBSCRIPT => new RichTextSubscript($data), + self::TYPE_SUPERSCRIPT => new RichTextSuperscript($data), + self::TYPE_MARKED => new RichTextMarked($data), + self::TYPE_CODE => new RichTextCode($data), + self::TYPE_CUSTOM_EMOJI => new RichTextCustomEmoji($data), + self::TYPE_MATHEMATICAL_EXPRESSION => new RichTextMathematicalExpression($data), + self::TYPE_URL => new RichTextUrl($data), + self::TYPE_EMAIL_ADDRESS => new RichTextEmailAddress($data), + self::TYPE_PHONE_NUMBER => new RichTextPhoneNumber($data), + self::TYPE_BANK_CARD_NUMBER => new RichTextBankCardNumber($data), + self::TYPE_MENTION => new RichTextMention($data), + self::TYPE_HASHTAG => new RichTextHashtag($data), + self::TYPE_CASHTAG => new RichTextCashtag($data), + self::TYPE_BOT_COMMAND => new RichTextBotCommand($data), + self::TYPE_ANCHOR => new RichTextAnchor($data), + self::TYPE_ANCHOR_LINK => new RichTextAnchorLink($data), + self::TYPE_REFERENCE => new RichTextReference($data), + self::TYPE_REFERENCE_LINK => new RichTextReferenceLink($data), + default => throw new \InvalidArgumentException('Unknown RichText type: ' . ($data['type'] ?? 'null')), + }; + } + +} diff --git a/src/Telegram/Entities/RichTextAnchor.php b/src/Telegram/Entities/RichTextAnchor.php new file mode 100644 index 0000000..3f4b678 --- /dev/null +++ b/src/Telegram/Entities/RichTextAnchor.php @@ -0,0 +1,19 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextBankCardNumber.php b/src/Telegram/Entities/RichTextBankCardNumber.php new file mode 100644 index 0000000..dc4e325 --- /dev/null +++ b/src/Telegram/Entities/RichTextBankCardNumber.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextBold.php b/src/Telegram/Entities/RichTextBold.php new file mode 100644 index 0000000..36bd676 --- /dev/null +++ b/src/Telegram/Entities/RichTextBold.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextBotCommand.php b/src/Telegram/Entities/RichTextBotCommand.php new file mode 100644 index 0000000..8bd225e --- /dev/null +++ b/src/Telegram/Entities/RichTextBotCommand.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextCashtag.php b/src/Telegram/Entities/RichTextCashtag.php new file mode 100644 index 0000000..7c9f0ab --- /dev/null +++ b/src/Telegram/Entities/RichTextCashtag.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextCode.php b/src/Telegram/Entities/RichTextCode.php new file mode 100644 index 0000000..f8ab095 --- /dev/null +++ b/src/Telegram/Entities/RichTextCode.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextCustomEmoji.php b/src/Telegram/Entities/RichTextCustomEmoji.php new file mode 100644 index 0000000..076a3a7 --- /dev/null +++ b/src/Telegram/Entities/RichTextCustomEmoji.php @@ -0,0 +1,20 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextEmailAddress.php b/src/Telegram/Entities/RichTextEmailAddress.php new file mode 100644 index 0000000..28958da --- /dev/null +++ b/src/Telegram/Entities/RichTextEmailAddress.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextHashtag.php b/src/Telegram/Entities/RichTextHashtag.php new file mode 100644 index 0000000..b5249dc --- /dev/null +++ b/src/Telegram/Entities/RichTextHashtag.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextItalic.php b/src/Telegram/Entities/RichTextItalic.php new file mode 100644 index 0000000..c3155a8 --- /dev/null +++ b/src/Telegram/Entities/RichTextItalic.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextMarked.php b/src/Telegram/Entities/RichTextMarked.php new file mode 100644 index 0000000..9a24be0 --- /dev/null +++ b/src/Telegram/Entities/RichTextMarked.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextMathematicalExpression.php b/src/Telegram/Entities/RichTextMathematicalExpression.php new file mode 100644 index 0000000..a91fba2 --- /dev/null +++ b/src/Telegram/Entities/RichTextMathematicalExpression.php @@ -0,0 +1,19 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextPhoneNumber.php b/src/Telegram/Entities/RichTextPhoneNumber.php new file mode 100644 index 0000000..2f00666 --- /dev/null +++ b/src/Telegram/Entities/RichTextPhoneNumber.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextReference.php b/src/Telegram/Entities/RichTextReference.php new file mode 100644 index 0000000..5b9fddc --- /dev/null +++ b/src/Telegram/Entities/RichTextReference.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextReferenceLink.php b/src/Telegram/Entities/RichTextReferenceLink.php new file mode 100644 index 0000000..ed14bd7 --- /dev/null +++ b/src/Telegram/Entities/RichTextReferenceLink.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextSpoiler.php b/src/Telegram/Entities/RichTextSpoiler.php new file mode 100644 index 0000000..5889141 --- /dev/null +++ b/src/Telegram/Entities/RichTextSpoiler.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextStrikethrough.php b/src/Telegram/Entities/RichTextStrikethrough.php new file mode 100644 index 0000000..06be993 --- /dev/null +++ b/src/Telegram/Entities/RichTextStrikethrough.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextSubscript.php b/src/Telegram/Entities/RichTextSubscript.php new file mode 100644 index 0000000..e023ff7 --- /dev/null +++ b/src/Telegram/Entities/RichTextSubscript.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextSuperscript.php b/src/Telegram/Entities/RichTextSuperscript.php new file mode 100644 index 0000000..2c05ebf --- /dev/null +++ b/src/Telegram/Entities/RichTextSuperscript.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextTextMention.php b/src/Telegram/Entities/RichTextTextMention.php new file mode 100644 index 0000000..3eb7572 --- /dev/null +++ b/src/Telegram/Entities/RichTextTextMention.php @@ -0,0 +1,23 @@ + RichText::class, + 'user' => User::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextUnderline.php b/src/Telegram/Entities/RichTextUnderline.php new file mode 100644 index 0000000..213c85c --- /dev/null +++ b/src/Telegram/Entities/RichTextUnderline.php @@ -0,0 +1,21 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/RichTextUrl.php b/src/Telegram/Entities/RichTextUrl.php new file mode 100644 index 0000000..1e0f8fb --- /dev/null +++ b/src/Telegram/Entities/RichTextUrl.php @@ -0,0 +1,22 @@ + RichText::class, + ]; + } +} diff --git a/src/Telegram/Entities/StoryAreaTypeLink.php b/src/Telegram/Entities/StoryAreaTypeLink.php index 57971b6..aa37024 100644 --- a/src/Telegram/Entities/StoryAreaTypeLink.php +++ b/src/Telegram/Entities/StoryAreaTypeLink.php @@ -9,7 +9,7 @@ * @property string $type * @property string $url */ -class StoryAreaTypeLink extends Entity +class StoryAreaTypeLink extends StoryAreaType { protected function setEntities(): array diff --git a/src/Telegram/Entities/StoryAreaTypeLocation.php b/src/Telegram/Entities/StoryAreaTypeLocation.php index 194ca01..5ce4977 100644 --- a/src/Telegram/Entities/StoryAreaTypeLocation.php +++ b/src/Telegram/Entities/StoryAreaTypeLocation.php @@ -11,7 +11,7 @@ * @property float $longitude * @property LocationAddress $address */ -class StoryAreaTypeLocation extends Entity +class StoryAreaTypeLocation extends StoryAreaType { protected function setEntities(): array diff --git a/src/Telegram/Entities/StoryAreaTypeSuggestedReaction.php b/src/Telegram/Entities/StoryAreaTypeSuggestedReaction.php index 29c58b4..a01ee5e 100644 --- a/src/Telegram/Entities/StoryAreaTypeSuggestedReaction.php +++ b/src/Telegram/Entities/StoryAreaTypeSuggestedReaction.php @@ -11,7 +11,7 @@ * @property bool $is_dark * @property bool $is_flipped */ -class StoryAreaTypeSuggestedReaction extends Entity +class StoryAreaTypeSuggestedReaction extends StoryAreaType { protected function setEntities(): array diff --git a/src/Telegram/Entities/StoryAreaTypeUniqueGift.php b/src/Telegram/Entities/StoryAreaTypeUniqueGift.php index ab33e5c..6c4a0be 100644 --- a/src/Telegram/Entities/StoryAreaTypeUniqueGift.php +++ b/src/Telegram/Entities/StoryAreaTypeUniqueGift.php @@ -9,7 +9,7 @@ * @property string $type * @property string $name */ -class StoryAreaTypeUniqueGift extends Entity +class StoryAreaTypeUniqueGift extends StoryAreaType { protected function setEntities(): array diff --git a/src/Telegram/Entities/StoryAreaTypeWeather.php b/src/Telegram/Entities/StoryAreaTypeWeather.php index d9d0744..7e0fe88 100644 --- a/src/Telegram/Entities/StoryAreaTypeWeather.php +++ b/src/Telegram/Entities/StoryAreaTypeWeather.php @@ -11,7 +11,7 @@ * @property string $emoji * @property int $background_color */ -class StoryAreaTypeWeather extends Entity +class StoryAreaTypeWeather extends StoryAreaType { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerAffiliateProgram.php b/src/Telegram/Entities/TransactionPartnerAffiliateProgram.php index 11fccaf..04a7683 100644 --- a/src/Telegram/Entities/TransactionPartnerAffiliateProgram.php +++ b/src/Telegram/Entities/TransactionPartnerAffiliateProgram.php @@ -10,7 +10,7 @@ * @property User $sponsor_user * @property int $commission_per_mille */ -class TransactionPartnerAffiliateProgram extends Entity +class TransactionPartnerAffiliateProgram extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerChat.php b/src/Telegram/Entities/TransactionPartnerChat.php index ea6adba..ceb4b86 100644 --- a/src/Telegram/Entities/TransactionPartnerChat.php +++ b/src/Telegram/Entities/TransactionPartnerChat.php @@ -10,7 +10,7 @@ * @property Chat $chat * @property Gift $gift */ -class TransactionPartnerChat extends Entity +class TransactionPartnerChat extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerFragment.php b/src/Telegram/Entities/TransactionPartnerFragment.php index 6e45389..85892ff 100644 --- a/src/Telegram/Entities/TransactionPartnerFragment.php +++ b/src/Telegram/Entities/TransactionPartnerFragment.php @@ -9,7 +9,7 @@ * @property string $type * @property RevenueWithdrawalState $withdrawal_state */ -class TransactionPartnerFragment extends Entity +class TransactionPartnerFragment extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerOther.php b/src/Telegram/Entities/TransactionPartnerOther.php index 496b40a..5106f69 100644 --- a/src/Telegram/Entities/TransactionPartnerOther.php +++ b/src/Telegram/Entities/TransactionPartnerOther.php @@ -8,7 +8,7 @@ * TransactionPartnerOther Entity * @property string $type */ -class TransactionPartnerOther extends Entity +class TransactionPartnerOther extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerTelegramAds.php b/src/Telegram/Entities/TransactionPartnerTelegramAds.php index 9546826..4b06609 100644 --- a/src/Telegram/Entities/TransactionPartnerTelegramAds.php +++ b/src/Telegram/Entities/TransactionPartnerTelegramAds.php @@ -8,7 +8,7 @@ * TransactionPartnerTelegramAds Entity * @property string $type */ -class TransactionPartnerTelegramAds extends Entity +class TransactionPartnerTelegramAds extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerTelegramApi.php b/src/Telegram/Entities/TransactionPartnerTelegramApi.php index 43bb89f..93deb89 100644 --- a/src/Telegram/Entities/TransactionPartnerTelegramApi.php +++ b/src/Telegram/Entities/TransactionPartnerTelegramApi.php @@ -9,7 +9,7 @@ * @property string $type * @property int $request_count */ -class TransactionPartnerTelegramApi extends Entity +class TransactionPartnerTelegramApi extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/TransactionPartnerUser.php b/src/Telegram/Entities/TransactionPartnerUser.php index a69b840..0d1e7ef 100644 --- a/src/Telegram/Entities/TransactionPartnerUser.php +++ b/src/Telegram/Entities/TransactionPartnerUser.php @@ -17,7 +17,7 @@ * @property Gift $gift * @property int $premium_subscription_duration */ -class TransactionPartnerUser extends Entity +class TransactionPartnerUser extends TransactionPartner { protected function setEntities(): array diff --git a/src/Telegram/Entities/Update.php b/src/Telegram/Entities/Update.php index 7b2040a..fb4af9e 100644 --- a/src/Telegram/Entities/Update.php +++ b/src/Telegram/Entities/Update.php @@ -32,6 +32,7 @@ * @property ChatBoostUpdated $chat_boost * @property ChatBoostRemoved $removed_chat_boost * @property ManagedBotUpdated $managed_bot + * @property BotSubscriptionUpdated $subscription */ class Update extends Entity { @@ -64,6 +65,7 @@ protected function setEntities(): array 'chat_boost' => ChatBoostUpdated::class, 'removed_chat_boost' => ChatBoostRemoved::class, 'managed_bot' => ManagedBotUpdated::class, + 'subscription' => BotSubscriptionUpdated::class, ]; } /** diff --git a/src/Telegram/Entities/User.php b/src/Telegram/Entities/User.php index 7d12546..25d41fa 100644 --- a/src/Telegram/Entities/User.php +++ b/src/Telegram/Entities/User.php @@ -23,6 +23,7 @@ * @property bool $has_topics_enabled * @property bool $allows_users_to_create_topics * @property bool $can_manage_bots + * @property bool $supports_join_request_queries */ class User extends Entity { diff --git a/src/Telegram/Entity.php b/src/Telegram/Entity.php index 8e8a0aa..b301808 100644 --- a/src/Telegram/Entity.php +++ b/src/Telegram/Entity.php @@ -55,7 +55,7 @@ protected function resolveEntity(array $data): void // Caso: Array de entidades (ej: 'photos' => [PhotoSize::class]) if (is_array($entityClass) && is_array($value)) { $this->properties[$key] = array_map( - fn($item) => new $entityClass[0]($item), + fn($item) => $item instanceof $entityClass[0] ? $item : new $entityClass[0]($item), $value ); } diff --git a/src/Telegram/Factories/Keyboard.php b/src/Telegram/Factories/Keyboard.php index c49413d..0bb9604 100644 --- a/src/Telegram/Factories/Keyboard.php +++ b/src/Telegram/Factories/Keyboard.php @@ -4,6 +4,8 @@ use Al3x5\xBot\Telegram\Entities\ForceReply; use Al3x5\xBot\Telegram\Entities\ReplyKeyboardRemove; +use Al3x5\xBot\Telegram\Factories\Keyboard\Inline; +use Al3x5\xBot\Telegram\Factories\Keyboard\Reply; class Keyboard { diff --git a/src/Telegram/Factories/Inline.php b/src/Telegram/Factories/Keyboard/Inline.php similarity index 73% rename from src/Telegram/Factories/Inline.php rename to src/Telegram/Factories/Keyboard/Inline.php index 72d95ae..3f33d9e 100644 --- a/src/Telegram/Factories/Inline.php +++ b/src/Telegram/Factories/Keyboard/Inline.php @@ -1,9 +1,8 @@ InputRichBlock::TYPE_PARAGRAPH, + ]); + $block->text = $text; + return $block; + } + + public static function heading(string|RichText|array $text, int $size = 1): InputRichBlockSectionHeading + { + $block = new InputRichBlockSectionHeading([ + 'type' => InputRichBlock::TYPE_HEADING, + 'size' => $size, + ]); + $block->text = $text; + return $block; + } + + public static function preformatted(string|RichText|array $text, string $language = ''): InputRichBlockPreformatted + { + $data = [ + 'type' => InputRichBlock::TYPE_PREFORMATTED, + ]; + if ($language !== '') { + $data['language'] = $language; + } + $block = new InputRichBlockPreformatted($data); + $block->text = $text; + return $block; + } + + public static function footer(string|RichText|array $text): InputRichBlockFooter + { + $block = new InputRichBlockFooter([ + 'type' => InputRichBlock::TYPE_FOOTER, + ]); + $block->text = $text; + return $block; + } + + public static function divider(): InputRichBlockDivider + { + return new InputRichBlockDivider([ + 'type' => InputRichBlock::TYPE_DIVIDER, + ]); + } + + public static function thinking(string|RichText|array $text): InputRichBlockThinking + { + $block = new InputRichBlockThinking([ + 'type' => InputRichBlock::TYPE_THINKING, + ]); + $block->text = $text; + return $block; + } + + public static function blockQuote(array $blocks, string|RichText|array|null $credit = null): InputRichBlockBlockQuotation + { + $block = new InputRichBlockBlockQuotation([ + 'type' => InputRichBlock::TYPE_BLOCK_QUOTATION, + 'blocks' => $blocks, + ]); + if ($credit !== null) { + $block->credit = $credit; + } + return $block; + } + + public static function pullQuote(string|RichText|array $text, string|RichText|array|null $credit = null): InputRichBlockPullQuotation + { + $block = new InputRichBlockPullQuotation([ + 'type' => InputRichBlock::TYPE_PULL_QUOTATION, + ]); + $block->text = $text; + if ($credit !== null) { + $block->credit = $credit; + } + return $block; + } + + public static function photo( + string $media, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockPhoto { + $data = [ + 'type' => InputRichBlock::TYPE_PHOTO, + 'photo' => new InputMediaPhoto([ + 'type' => 'photo', + 'media' => $media, + ]), + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockPhoto($data); + } + + public static function video( + string $media, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockVideo { + $data = [ + 'type' => InputRichBlock::TYPE_VIDEO, + 'video' => new InputMediaVideo([ + 'type' => 'video', + 'media' => $media, + ]), + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockVideo($data); + } + + public static function audio( + string $media, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockAudio { + $data = [ + 'type' => InputRichBlock::TYPE_AUDIO, + 'audio' => new InputMediaAudio([ + 'type' => 'audio', + 'media' => $media, + ]), + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockAudio($data); + } + + public static function animation( + string $media, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockAnimation { + $data = [ + 'type' => InputRichBlock::TYPE_ANIMATION, + 'animation' => new InputMediaAnimation([ + 'type' => 'animation', + 'media' => $media, + ]), + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockAnimation($data); + } + + public static function voiceNote( + string $media, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockVoiceNote { + $data = [ + 'type' => InputRichBlock::TYPE_VOICE_NOTE, + 'voice_note' => new InputMediaVoiceNote([ + 'type' => 'voice', + 'media' => $media, + ]), + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockVoiceNote($data); + } + + public static function table(): Table + { + return new Table(); + } + + public static function list(array $items): InputRichBlockList + { + $listItems = []; + foreach ($items as $item) { + if ($item instanceof InputRichBlock) { + $listItems[] = new InputRichBlockListItem([ + 'blocks' => [$item], + ]); + } elseif (is_array($item)) { + $listItems[] = new InputRichBlockListItem([ + 'blocks' => $item, + ]); + } + } + return new InputRichBlockList([ + 'type' => InputRichBlock::TYPE_LIST, + 'items' => $listItems, + ]); + } + + public static function details( + string|RichText|array $summary, + array $blocks, + bool $is_open = false + ): InputRichBlockDetails { + $block = new InputRichBlockDetails([ + 'type' => InputRichBlock::TYPE_DETAILS, + 'blocks' => $blocks, + 'is_open' => $is_open, + ]); + $block->summary = $summary; + return $block; + } + + public static function collage( + array $blocks, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockCollage { + $data = [ + 'type' => InputRichBlock::TYPE_COLLAGE, + 'blocks' => $blocks, + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockCollage($data); + } + + public static function slideshow( + array $blocks, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockSlideshow { + $data = [ + 'type' => InputRichBlock::TYPE_SLIDESHOW, + 'blocks' => $blocks, + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockSlideshow($data); + } + + public static function map( + array $location, + int $zoom = 15, + int $width = 300, + int $height = 200, + string|RichText|array|null $caption = null, + string|RichText|array|null $credit = null + ): InputRichBlockMap { + $data = [ + 'type' => InputRichBlock::TYPE_MAP, + 'location' => $location, + 'zoom' => $zoom, + 'width' => $width, + 'height' => $height, + ]; + if ($caption !== null || $credit !== null) { + $captionBlock = new RichBlockCaption([]); + if ($caption !== null) { + $captionBlock->text = $caption; + } + if ($credit !== null) { + $captionBlock->credit = $credit; + } + $data['caption'] = $captionBlock; + } + return new InputRichBlockMap($data); + } + + public static function math(string $expression): InputRichBlockMathematicalExpression + { + return new InputRichBlockMathematicalExpression([ + 'type' => InputRichBlock::TYPE_MATHEMATICAL_EXPRESSION, + 'expression' => $expression, + ]); + } + + public static function anchor(string $name): InputRichBlockAnchor + { + return new InputRichBlockAnchor([ + 'type' => InputRichBlock::TYPE_ANCHOR, + 'name' => $name, + ]); + } +} diff --git a/src/Telegram/Factories/Rich/Table.php b/src/Telegram/Factories/Rich/Table.php new file mode 100644 index 0000000..bb6b2ef --- /dev/null +++ b/src/Telegram/Factories/Rich/Table.php @@ -0,0 +1,114 @@ +header = $cells; + return $this; + } + + public function body(array $rows): self + { + $this->rows = $rows; + return $this; + } + + public function footer(array $cells): self + { + $this->footer = $cells; + return $this; + } + + public function bordered(bool $v = true): self + { + $this->options['is_bordered'] = $v; + return $this; + } + + public function striped(bool $v = true): self + { + $this->options['is_striped'] = $v; + return $this; + } + + public function caption(string|RichText|array $caption): self + { + $this->options['caption'] = $caption; + return $this; + } + + public function build(): InputRichBlockTable + { + $cells = []; + + if ($this->header) { + $cells[] = array_map(fn($c) => $this->resolveCell($c, true), $this->header); + } + + foreach ($this->rows as $row) { + $cells[] = array_map(fn($c) => $this->resolveCell($c, false), $row); + } + + if ($this->footer) { + $cells[] = array_map(fn($c) => $this->resolveCell($c, false), $this->footer); + } + + $table = new InputRichBlockTable([]); + $table->type = InputRichBlock::TYPE_TABLE; + $table->cells = $cells; + + if (isset($this->options['is_bordered'])) { + $table->is_bordered = $this->options['is_bordered']; + } + if (isset($this->options['is_striped'])) { + $table->is_striped = $this->options['is_striped']; + } + if (isset($this->options['caption'])) { + $table->caption = $this->options['caption']; + } + + return $table; + } + + private function resolveCell(mixed $cell, bool $isHeader): RichBlockTableCell + { + if ($cell instanceof RichBlockTableCell) { + return $cell; + } + + if (is_array($cell)) { + if (!isset($cell['text'])) { + $cell['text'] = ''; + } + if (!isset($cell['is_header'])) { + $cell['is_header'] = $isHeader; + } + return new RichBlockTableCell($cell); + } + + if ($cell instanceof RichText) { + return new RichBlockTableCell([ + 'text' => $cell, + 'is_header' => $isHeader, + ]); + } + + return new RichBlockTableCell([ + 'text' => (string) $cell, + 'is_header' => $isHeader, + ]); + } +} diff --git a/src/Telegram/Factories/RichMessage.php b/src/Telegram/Factories/RichMessage.php new file mode 100644 index 0000000..7af6b36 --- /dev/null +++ b/src/Telegram/Factories/RichMessage.php @@ -0,0 +1,53 @@ +blocks[] = $block; + return $this; + } + + public function html(string $html): self + { + $this->options['html'] = $html; + return $this; + } + + public function markdown(string $markdown): self + { + $this->options['markdown'] = $markdown; + return $this; + } + + public function rtl(bool $v = true): self + { + $this->options['is_rtl'] = $v; + return $this; + } + + public function build(): InputRichMessage + { + $msg = new InputRichMessage([]); + if ($this->blocks !== []) { + $msg->blocks = $this->blocks; + } + foreach ($this->options as $k => $v) { + $msg->{$k} = $v; + } + return $msg; + } +} diff --git a/src/Telegram/FormatHelper.php b/src/Telegram/FormatHelper.php deleted file mode 100644 index 257445e..0000000 --- a/src/Telegram/FormatHelper.php +++ /dev/null @@ -1,163 +0,0 @@ -$text" : "*$text*"; - } - - /** - * Formato: Cursiva - */ - public static function italic(string $text): string - { - return self::isHtml() ? "$text" : '_' . $text . '_'; - } - - /** - * Formato: Subrayado - */ - public static function underline(string $text): string - { - return self::isHtml() ? "$text" : '__' . $text . '__'; - } - - /** - * Formato: Tachado - */ - public static function strikethrough(string $text): string - { - return self::isHtml() ? "$text" : "~$text~"; - } - - /** - * Formato: Spoiler - */ - public static function spoiler(string $text): string - { - return self::isHtml() ? "$text" : "||$text||"; - } - - /** - * Formato: Enlace - */ - public static function link(string $text, string $url): string - { - if (!self::isHtml()) { - return "[$text]($url)"; - } - $text = self::sanitize($text, 'link'); - return "$text"; - } - - /** - * Formato: Mención de usuario - */ - public static function mention(string $text, int $userId): string - { - return self::link($text, "tg://user?id=$userId"); - } - - /** - * Formato: Emoji personalizado - */ - public static function emoji(string $emoji, string $emojiId): string - { - if (!self::isHtml()) { - return $emoji; - } - self::sanitize($emoji); - return "$emoji"; - } - - /** - * Formato: Código en línea - */ - public static function inlineCode(string $text): string - { - if (!self::isHtml()) { - return "`$text`"; - } - $text = self::sanitize($text); - return "$text"; - } - - /** - * Formato: Bloque de código - */ - public static function codeBlock(string $text, string $language = ''): string - { - if (!self::isHtml()) { - return "```$language\n$text\n```"; - } - $text = self::sanitize($text); - return $language - ? "
$text
" - : "
$text
"; - } - - /** - * Formato: Cita en bloque - */ - public static function blockQuote(string $text): string - { - return self::isHtml() ? "
$text
" : "> $text"; - } - - /** - * Formato: Cita expandible - */ - public static function expandableBlockQuote(string $text): string - { - return self::isHtml() ? "
$text
" : ">$text"; - } - - /** - * Formato: Tiempo/Timestamp - * - * @param int $unix Timestamp unix - * @param string $format Formato: 'wDT', 't', 'r', o vacío - * - * r: Muestra la hora en relación con la hora actual. No se puede combinar - * con ningún otro carácter de control. - * w: Muestra el día de la semana en el idioma del usuario. - * d: Muestra la fecha en formato abreviado (por ejemplo, “17.03.22”). - * D: Muestra la fecha en formato largo (por ejemplo, “17 de marzo de 2022”). - * t: Muestra la hora en formato abreviado (por ejemplo, “22:45”). - * T: Muestra la hora en formato largo (por ejemplo, “22:45:00”). - - */ - public static function time(int $unix, string $format = ''): string - { - if (!self::isHtml()) { - // MarkdownV2: ![texto](tg://time?unix=XXX&format=Y) - $url = "tg://time?unix=$unix" . ($format ? "&format=$format" : ''); - return "![fecha]($url)"; - } - // HTML: texto - return $format - ? "fecha" - : "fecha"; - } - - /** - * Sanear texto - */ - private static function sanitize(string $text): string - { - return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); - } - - private static function isHtml(): bool - { - return Config::get('parse_mode') == 'HTML'; - } -} diff --git a/src/Telegram/Methods.php b/src/Telegram/Methods.php index a6bbbe8..5e03d22 100644 --- a/src/Telegram/Methods.php +++ b/src/Telegram/Methods.php @@ -27,6 +27,7 @@ use Al3x5\xBot\Telegram\Entities\MenuButton; use Al3x5\xBot\Telegram\Entities\ChatAdministratorRights; use Al3x5\xBot\Telegram\Entities\AcceptedGiftTypes; +use Al3x5\xBot\Telegram\Entities\BotAccessSettings; use Al3x5\xBot\Telegram\Entities\InputStoryContent; use Al3x5\xBot\Telegram\Entities\StoryArea; use Al3x5\xBot\Telegram\Entities\InputMedia; @@ -53,10 +54,15 @@ use Al3x5\xBot\Telegram\Entities\BotName; use Al3x5\xBot\Telegram\Entities\BotDescription; use Al3x5\xBot\Telegram\Entities\BotShortDescription; +use Al3x5\xBot\Telegram\Entities\InputPollMedia; +use Al3x5\xBot\Telegram\Entities\InputRichMessage; +use Al3x5\xBot\Telegram\Entities\KeyboardButton; use Al3x5\xBot\Telegram\Entities\StarAmount; use Al3x5\xBot\Telegram\Entities\Poll; use Al3x5\xBot\Telegram\Entities\StickerSet; use Al3x5\xBot\Telegram\Entities\PreparedInlineMessage; +use Al3x5\xBot\Telegram\Entities\PreparedKeyboardButton; +use Al3x5\xBot\Telegram\Entities\SentGuestMessage; use Al3x5\xBot\Telegram\Entities\UserProfileAudios; use Al3x5\xBot\Telegram\Entities\SentWebAppMessage; use Al3x5\xBot\Telegram\Entities\StarTransactions; @@ -165,6 +171,8 @@ public function close(): bool * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param string $text * @param string $parse_mode * @param MessageEntity[] $entities @@ -178,7 +186,7 @@ public function close(): bool * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendMessage(int|string $chat_id, string $text, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $parse_mode = null, ?array $entities = null, ?LinkPreviewOptions $link_preview_options = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendMessage(int|string $chat_id, string $text, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $parse_mode = null, ?array $entities = null, ?LinkPreviewOptions $link_preview_options = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -207,7 +215,7 @@ public function forwardMessage(int|string $chat_id, int|string $from_chat_id, in } /** - * Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned. + * Use this method to forward multiple messages of any kind. If some of the specified messages can't be found or forwarded, they are skipped. Service messages and messages with protected content can't be forwarded. Album grouping is kept for forwarded messages. On success, an Array of MessageId of the sent messages is returned. * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id @@ -225,7 +233,7 @@ public function forwardMessages(int|string $chat_id, int|string $from_chat_id, a } /** - * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. + * Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_ids is known to the bot. The method is analogous to the method forwardMessage, but the copied message doesn't have a link to the original message. Returns the MessageId of the sent message on success. * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id @@ -253,7 +261,7 @@ public function copyMessage(int|string $chat_id, int|string $from_chat_id, int $ } /** - * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned. + * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_ids is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages. On success, an Array of MessageId of the sent messages is returned. * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id @@ -277,6 +285,8 @@ public function copyMessages(int|string $chat_id, int|string $from_chat_id, arra * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $photo * @param string $caption * @param string $parse_mode @@ -292,7 +302,7 @@ public function copyMessages(int|string $chat_id, int|string $from_chat_id, arra * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendPhoto(int|string $chat_id, InputFile|string $photo, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendPhoto(int|string $chat_id, InputFile|string $photo, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -305,6 +315,8 @@ public function sendPhoto(int|string $chat_id, InputFile|string $photo, ?string * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $live_photo * @param InputFile|string $photo * @param string $caption @@ -321,7 +333,7 @@ public function sendPhoto(int|string $chat_id, InputFile|string $photo, ?string * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendLivePhoto(int|string $chat_id, InputFile|string $live_photo, InputFile|string $photo, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendLivePhoto(int|string $chat_id, InputFile|string $live_photo, InputFile|string $photo, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -335,6 +347,8 @@ public function sendLivePhoto(int|string $chat_id, InputFile|string $live_photo, * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $audio * @param string $caption * @param string $parse_mode @@ -352,7 +366,7 @@ public function sendLivePhoto(int|string $chat_id, InputFile|string $live_photo, * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendAudio(int|string $chat_id, InputFile|string $audio, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?int $duration = null, ?string $performer = null, ?string $title = null, InputFile|string|null $thumbnail = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendAudio(int|string $chat_id, InputFile|string $audio, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?int $duration = null, ?string $performer = null, ?string $title = null, InputFile|string|null $thumbnail = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -365,6 +379,8 @@ public function sendAudio(int|string $chat_id, InputFile|string $audio, ?string * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $document * @param InputFile|string $thumbnail * @param string $caption @@ -380,7 +396,7 @@ public function sendAudio(int|string $chat_id, InputFile|string $audio, ?string * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendDocument(int|string $chat_id, InputFile|string $document, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, InputFile|string|null $thumbnail = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $disable_content_type_detection = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendDocument(int|string $chat_id, InputFile|string $document, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, InputFile|string|null $thumbnail = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $disable_content_type_detection = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -393,6 +409,8 @@ public function sendDocument(int|string $chat_id, InputFile|string $document, ?s * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $video * @param int $duration * @param int $width @@ -415,7 +433,7 @@ public function sendDocument(int|string $chat_id, InputFile|string $document, ?s * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendVideo(int|string $chat_id, InputFile|string $video, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $duration = null, ?int $width = null, ?int $height = null, InputFile|string|null $thumbnail = null, InputFile|string|null $cover = null, ?int $start_timestamp = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $supports_streaming = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendVideo(int|string $chat_id, InputFile|string $video, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?int $duration = null, ?int $width = null, ?int $height = null, InputFile|string|null $thumbnail = null, InputFile|string|null $cover = null, ?int $start_timestamp = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $supports_streaming = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -428,6 +446,8 @@ public function sendVideo(int|string $chat_id, InputFile|string $video, ?string * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $animation * @param int $duration * @param int $width @@ -447,7 +467,7 @@ public function sendVideo(int|string $chat_id, InputFile|string $video, ?string * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendAnimation(int|string $chat_id, InputFile|string $animation, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $duration = null, ?int $width = null, ?int $height = null, InputFile|string|null $thumbnail = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendAnimation(int|string $chat_id, InputFile|string $animation, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?int $duration = null, ?int $width = null, ?int $height = null, InputFile|string|null $thumbnail = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?bool $show_caption_above_media = null, ?bool $has_spoiler = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -460,6 +480,8 @@ public function sendAnimation(int|string $chat_id, InputFile|string $animation, * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $voice * @param string $caption * @param string $parse_mode @@ -474,7 +496,7 @@ public function sendAnimation(int|string $chat_id, InputFile|string $animation, * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendVoice(int|string $chat_id, InputFile|string $voice, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?int $duration = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendVoice(int|string $chat_id, InputFile|string $voice, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?int $duration = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -487,6 +509,8 @@ public function sendVoice(int|string $chat_id, InputFile|string $voice, ?string * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $video_note * @param int $duration * @param int $length @@ -500,7 +524,7 @@ public function sendVoice(int|string $chat_id, InputFile|string $voice, ?string * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendVideoNote(int|string $chat_id, InputFile|string $video_note, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $duration = null, ?int $length = null, InputFile|string|null $thumbnail = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendVideoNote(int|string $chat_id, InputFile|string $video_note, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?int $duration = null, ?int $length = null, InputFile|string|null $thumbnail = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -536,7 +560,7 @@ public function sendPaidMedia(int|string $chat_id, int $star_count, array $media } /** - * Use this method to send a group of photos, live photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of Message objects that were sent is returned. + * Use this method to send a group of photos, live photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an Array of Message objects that were sent is returned. * @param string $business_connection_id * @param int|string $chat_id * @param int $message_thread_id @@ -562,6 +586,8 @@ public function sendMediaGroup(int|string $chat_id, array $media, ?string $busin * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param float $latitude * @param float $longitude * @param float $horizontal_accuracy @@ -577,7 +603,7 @@ public function sendMediaGroup(int|string $chat_id, array $media, ?string $busin * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendLocation(int|string $chat_id, float $latitude, float $longitude, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?float $horizontal_accuracy = null, ?int $live_period = null, ?int $heading = null, ?int $proximity_alert_radius = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendLocation(int|string $chat_id, float $latitude, float $longitude, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?float $horizontal_accuracy = null, ?int $live_period = null, ?int $heading = null, ?int $proximity_alert_radius = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -590,6 +616,8 @@ public function sendLocation(int|string $chat_id, float $latitude, float $longit * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param float $latitude * @param float $longitude * @param string $title @@ -607,7 +635,7 @@ public function sendLocation(int|string $chat_id, float $latitude, float $longit * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendVenue(int|string $chat_id, float $latitude, float $longitude, string $title, string $address, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $foursquare_id = null, ?string $foursquare_type = null, ?string $google_place_id = null, ?string $google_place_type = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendVenue(int|string $chat_id, float $latitude, float $longitude, string $title, string $address, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $foursquare_id = null, ?string $foursquare_type = null, ?string $google_place_id = null, ?string $google_place_type = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -620,6 +648,8 @@ public function sendVenue(int|string $chat_id, float $latitude, float $longitude * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param string $phone_number * @param string $first_name * @param string $last_name @@ -633,7 +663,7 @@ public function sendVenue(int|string $chat_id, float $latitude, float $longitude * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendContact(int|string $chat_id, string $phone_number, string $first_name, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $last_name = null, ?string $vcard = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendContact(int|string $chat_id, string $phone_number, string $first_name, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $last_name = null, ?string $vcard = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -1086,6 +1116,32 @@ public function declineChatJoinRequest(int|string $chat_id, int $user_id): bool return $this->sender(__FUNCTION__, $args); } + /** + * Use this method to process a received chat join request query. Returns True on success. + * @param string $chat_join_request_query_id + * @param string $result + * @return bool + */ + public function answerChatJoinRequestQuery(string $chat_join_request_query_id, string $result): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + + /** + * Use this method to process a received chat join request query by showing a Mini App to the user before deciding the outcome. Call answerChatJoinRequestQuery to resolve the join request query based on the user interaction with the Mini App. Returns True on success. + * @param string $chat_join_request_query_id + * @param string $web_app_url + * @return bool + */ + public function sendChatJoinRequestWebApp(string $chat_join_request_query_id, string $web_app_url): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + /** * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success. * @param int|string $chat_id @@ -1216,7 +1272,7 @@ public function getChatAdministrators(int|string $chat_id, ?bool $return_bots = } /** - * Use this method to get the number of members in a chat. Returns Int on success. + * Use this method to get the number of members in a chat. Returns Integer on success. * @param int|string $chat_id * @return int */ @@ -1241,7 +1297,7 @@ public function getChatMember(int|string $chat_id, int $user_id): ChatMember } /** - * Use this method to get the last messages from the personal chat (i.e., the chat currently added to their profile) of a given user. On success, an array of Message objects is returned. + * Use this method to get the last messages from the personal chat (i.e., the chat currently added to their profile) of a given user. On success, an Array of Message objects is returned. * @param int $user_id * @param int $limit * @return Message[] @@ -2184,7 +2240,7 @@ public function savePreparedKeyboardButton(int $user_id, KeyboardButton $button) } /** - * Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. + * Use this method to edit text, rich and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. * @param string $business_connection_id * @param int|string $chat_id * @param int $message_id @@ -2193,10 +2249,11 @@ public function savePreparedKeyboardButton(int $user_id, KeyboardButton $button) * @param string $parse_mode * @param MessageEntity[] $entities * @param LinkPreviewOptions $link_preview_options + * @param InputRichMessage $rich_message * @param InlineKeyboardMarkup $reply_markup * @return Message|bool */ - public function editMessageText(string $text, ?string $business_connection_id = null, int|string|null $chat_id = null, ?int $message_id = null, ?string $inline_message_id = null, ?string $parse_mode = null, ?array $entities = null, ?LinkPreviewOptions $link_preview_options = null, ?InlineKeyboardMarkup $reply_markup = null): Message|bool + public function editMessageText(?string $business_connection_id = null, int|string|null $chat_id = null, ?int $message_id = null, ?string $inline_message_id = null, ?string $text = null, ?string $parse_mode = null, ?array $entities = null, ?LinkPreviewOptions $link_preview_options = null, ?InputRichMessage $rich_message = null, ?InlineKeyboardMarkup $reply_markup = null): Message|bool { $args = get_defined_vars(); unset($args['this']); @@ -2224,7 +2281,7 @@ public function editMessageCaption(?string $business_connection_id = null, int|s } /** - * Use this method to edit animation, audio, document, live photo, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo, a live photo, or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. + * Use this method to edit animation, audio, document, live photo, photo, or video messages, or to replace a text or a rich message with a media. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo, a live photo, or a video otherwise. When an inline message is edited, a new file can't be uploaded; use a previously uploaded file via its file_id or specify a URL. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent. * @param string $business_connection_id * @param int|string $chat_id * @param int $message_id @@ -2325,6 +2382,74 @@ public function stopPoll(int|string $chat_id, int $message_id, ?string $business return $this->sender(__FUNCTION__, $args); } + /** + * Use this method to edit an ephemeral text message. Note that it is not guaranteed that the user will receive the message edit event, especially if they are offline. On success, True is returned. + * @param int|string $chat_id + * @param int $receiver_user_id + * @param int $ephemeral_message_id + * @param string $text + * @param string $parse_mode + * @param MessageEntity[] $entities + * @param LinkPreviewOptions $link_preview_options + * @param InlineKeyboardMarkup $reply_markup + * @return bool + */ + public function editEphemeralMessageText(int|string $chat_id, int $receiver_user_id, int $ephemeral_message_id, string $text, ?string $parse_mode = null, ?array $entities = null, ?LinkPreviewOptions $link_preview_options = null, ?InlineKeyboardMarkup $reply_markup = null): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + + /** + * Use this method to edit the media of an ephemeral message. Note that it is not guaranteed that the user will receive the message edit event, especially if they are offline. On success, True is returned. + * @param int|string $chat_id + * @param int $receiver_user_id + * @param int $ephemeral_message_id + * @param InputMedia $media + * @param InlineKeyboardMarkup $reply_markup + * @return bool + */ + public function editEphemeralMessageMedia(int|string $chat_id, int $receiver_user_id, int $ephemeral_message_id, InputMedia $media, ?InlineKeyboardMarkup $reply_markup = null): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + + /** + * Use this method to edit the caption of an ephemeral message. Note that it is not guaranteed that the user will receive the message edit event, especially if they are offline. On success, True is returned. + * @param int|string $chat_id + * @param int $receiver_user_id + * @param int $ephemeral_message_id + * @param string $caption + * @param string $parse_mode + * @param MessageEntity[] $caption_entities + * @param InlineKeyboardMarkup $reply_markup + * @return bool + */ + public function editEphemeralMessageCaption(int|string $chat_id, int $receiver_user_id, int $ephemeral_message_id, ?string $caption = null, ?string $parse_mode = null, ?array $caption_entities = null, ?InlineKeyboardMarkup $reply_markup = null): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + + /** + * Use this method to edit only the reply markup of an ephemeral message. Note that it is not guaranteed that the user will receive the message edit event, especially if they are offline. On success, True is returned. + * @param int|string $chat_id + * @param int $receiver_user_id + * @param int $ephemeral_message_id + * @param InlineKeyboardMarkup $reply_markup + * @return bool + */ + public function editEphemeralMessageReplyMarkup(int|string $chat_id, int $receiver_user_id, int $ephemeral_message_id, ?InlineKeyboardMarkup $reply_markup = null): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + /** * Use this method to approve a suggested post in a direct messages chat. The bot must have the 'can_post_messages' administrator right in the corresponding channel chat. Returns True on success. * @param int $chat_id @@ -2379,6 +2504,20 @@ public function deleteMessages(int|string $chat_id, array $message_ids): bool return $this->sender(__FUNCTION__, $args); } + /** + * Use this method to delete an ephemeral message. Note that it is not guaranteed that the user will receive the message deletion event, especially if they are offline. Returns True on success. + * @param int|string $chat_id + * @param int $receiver_user_id + * @param int $ephemeral_message_id + * @return bool + */ + public function deleteEphemeralMessage(int|string $chat_id, int $receiver_user_id, int $ephemeral_message_id): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + /** * Use this method to remove a reaction from a message in a group or a supergroup chat. The bot must have the 'can_delete_messages' administrator right in the chat. Returns True on success. * @param int|string $chat_id @@ -2414,6 +2553,8 @@ public function deleteAllMessageReactions(int|string $chat_id, ?int $user_id = n * @param int|string $chat_id * @param int $message_thread_id * @param int $direct_messages_topic_id + * @param int $receiver_user_id + * @param string $callback_query_id * @param InputFile|string $sticker * @param string $emoji * @param bool $disable_notification @@ -2425,7 +2566,7 @@ public function deleteAllMessageReactions(int|string $chat_id, ?int $user_id = n * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup * @return Message */ - public function sendSticker(int|string $chat_id, InputFile|string $sticker, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?string $emoji = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + public function sendSticker(int|string $chat_id, InputFile|string $sticker, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?int $receiver_user_id = null, ?string $callback_query_id = null, ?string $emoji = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message { $args = get_defined_vars(); unset($args['this']); @@ -2633,6 +2774,44 @@ public function deleteStickerSet(string $name): bool return $this->sender(__FUNCTION__, $args); } + /** + * Use this method to send rich messages. If the message contains a block with a media element, then the bot must have the right to send the media to the chat. On success, the sent Message is returned. + * @param string $business_connection_id + * @param int|string $chat_id + * @param int $message_thread_id + * @param int $direct_messages_topic_id + * @param InputRichMessage $rich_message + * @param bool $disable_notification + * @param bool $protect_content + * @param bool $allow_paid_broadcast + * @param string $message_effect_id + * @param SuggestedPostParameters $suggested_post_parameters + * @param ReplyParameters $reply_parameters + * @param InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply $reply_markup + * @return Message + */ + public function sendRichMessage(int|string $chat_id, InputRichMessage $rich_message, ?string $business_connection_id = null, ?int $message_thread_id = null, ?int $direct_messages_topic_id = null, ?bool $disable_notification = null, ?bool $protect_content = null, ?bool $allow_paid_broadcast = null, ?string $message_effect_id = null, ?SuggestedPostParameters $suggested_post_parameters = null, ?ReplyParameters $reply_parameters = null, InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $reply_markup = null): Message + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + + /** + * Use this method to stream a partial rich message to a user while the message is being generated. Note that the streamed draft is ephemeral and acts as a temporary 30-second preview - once the output is finalized, you must call sendRichMessage with the complete message to persist it in the user's chat. Returns True on success. + * @param int $chat_id + * @param int $message_thread_id + * @param int $draft_id + * @param InputRichMessage $rich_message + * @return bool + */ + public function sendRichMessageDraft(int $chat_id, int $draft_id, InputRichMessage $rich_message, ?int $message_thread_id = null): bool + { + $args = get_defined_vars(); + unset($args['this']); + return $this->sender(__FUNCTION__, $args); + } + /** * Use this method to send answers to an inline query. On success, True is returned.No more than 50 results per query are allowed. * @param string $inline_query_id diff --git a/src/Telegram/Text.php b/src/Telegram/Text.php new file mode 100644 index 0000000..5960af7 --- /dev/null +++ b/src/Telegram/Text.php @@ -0,0 +1,244 @@ +$text" : "*$text*"; + } + + public static function italic(string $text): string + { + return self::isHtml() ? "$text" : '_' . $text . '_'; + } + + public static function underline(string $text): string + { + return self::isHtml() ? "$text" : '__' . $text . '__'; + } + + public static function strikethrough(string $text): string + { + return self::isHtml() ? "$text" : "~$text~"; + } + + public static function spoiler(string $text): string + { + return self::isHtml() ? "$text" : "||$text||"; + } + + public static function link(string $text, string $url): string + { + if (!self::isHtml()) { + return "[$text]($url)"; + } + $text = self::sanitize($text, 'link'); + return "$text"; + } + + public static function mention(string $text, int $userId): string + { + return self::link($text, "tg://user?id=$userId"); + } + + public static function emoji(string $emoji, string $emojiId): string + { + if (!self::isHtml()) { + return $emoji; + } + self::sanitize($emoji); + return "$emoji"; + } + + public static function inlineCode(string $text): string + { + if (!self::isHtml()) { + return "`$text`"; + } + $text = self::sanitize($text); + return "$text"; + } + + public static function codeBlock(string $text, string $language = ''): string + { + if (!self::isHtml()) { + return "```$language\n$text\n```"; + } + $text = self::sanitize($text); + return $language + ? "
$text
" + : "
$text
"; + } + + public static function blockQuote(string $text): string + { + return self::isHtml() ? "
$text
" : "> $text"; + } + + public static function expandableBlockQuote(string $text): string + { + return self::isHtml() ? "
$text
" : ">$text"; + } + + public static function time(int $unix, string $format = ''): string + { + if (!self::isHtml()) { + $url = "tg://time?unix=$unix" . ($format ? "&format=$format" : ''); + return "![fecha]($url)"; + } + return $format + ? "fecha" + : "fecha"; + } + + private static function sanitize(string $text): string + { + return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); + } + + private static function isHtml(): bool + { + return Config::get('parse_mode') == 'HTML'; + } + + private static function richText(string|RichText $text): string|RichText + { + return $text instanceof RichText ? $text : $text; + } + + public static function richBold(string|RichText $text): RichTextBold + { + return new RichTextBold(['type' => 'bold', 'text' => self::richText($text)]); + } + + public static function richItalic(string|RichText $text): RichTextItalic + { + return new RichTextItalic(['type' => 'italic', 'text' => self::richText($text)]); + } + + public static function richUnderline(string|RichText $text): RichTextUnderline + { + return new RichTextUnderline(['type' => 'underline', 'text' => self::richText($text)]); + } + + public static function richStrikethrough(string|RichText $text): RichTextStrikethrough + { + return new RichTextStrikethrough(['type' => 'strikethrough', 'text' => self::richText($text)]); + } + + public static function richSpoiler(string|RichText $text): RichTextSpoiler + { + return new RichTextSpoiler(['type' => 'spoiler', 'text' => self::richText($text)]); + } + + public static function richCode(string|RichText $text): RichTextCode + { + return new RichTextCode(['type' => 'code', 'text' => self::richText($text)]); + } + + public static function richUrl(string|RichText $text, string $url): RichTextUrl + { + return new RichTextUrl(['type' => 'url', 'text' => self::richText($text), 'url' => $url]); + } + + public static function richEmail(string|RichText $text): RichTextEmailAddress + { + return new RichTextEmailAddress(['type' => 'email_address', 'text' => self::richText($text)]); + } + + public static function richPhone(string|RichText $text): RichTextPhoneNumber + { + return new RichTextPhoneNumber(['type' => 'phone_number', 'text' => self::richText($text)]); + } + + public static function richMention(string|RichText $text, string $username): RichTextMention + { + return new RichTextMention(['type' => 'mention', 'text' => self::richText($text), 'username' => $username]); + } + + public static function richTextMention(string|RichText $text, User|int $user): RichTextTextMention + { + $userData = $user instanceof User ? $user : new User(['id' => $user, 'is_bot' => false, 'first_name' => '']); + return new RichTextTextMention(['type' => 'text_mention', 'text' => self::richText($text), 'user' => $userData]); + } + + public static function richCustomEmoji(string $emoji, string $id): RichTextCustomEmoji + { + return new RichTextCustomEmoji(['type' => 'custom_emoji', 'custom_emoji_id' => $id, 'alternative_text' => $emoji]); + } + + public static function richSubscript(string|RichText $text): RichTextSubscript + { + return new RichTextSubscript(['type' => 'subscript', 'text' => self::richText($text)]); + } + + public static function richSuperscript(string|RichText $text): RichTextSuperscript + { + return new RichTextSuperscript(['type' => 'superscript', 'text' => self::richText($text)]); + } + + public static function richMarked(string|RichText $text): RichTextMarked + { + return new RichTextMarked(['type' => 'marked', 'text' => self::richText($text)]); + } + + public static function richDatetime(int $unix): RichTextDateTime + { + return new RichTextDateTime([ + 'type' => RichText::TYPE_DATETIME, + 'unix_time' => $unix + ]); + } + + public static function richMath(string $expression): RichTextMathematicalExpression + { + return new RichTextMathematicalExpression(['type' => 'mathematical_expression', 'expression' => $expression]); + } + + public static function richAnchor(string $name): RichTextAnchor + { + return new RichTextAnchor(['type' => 'anchor', 'name' => $name]); + } + + public static function richAnchorLink(string|RichText $text, string $anchor): RichTextAnchorLink + { + return new RichTextAnchorLink(['type' => 'anchor_link', 'text' => self::richText($text), 'anchor' => $anchor]); + } + + public static function richReference(string|RichText $text, string $reference): RichTextReference + { + return new RichTextReference(['type' => 'reference', 'text' => self::richText($text), 'reference' => $reference]); + } + + public static function richReferenceLink(string|RichText $text, string $reference): RichTextReferenceLink + { + return new RichTextReferenceLink(['type' => 'reference_link', 'text' => self::richText($text), 'reference' => $reference]); + } +} diff --git a/tests/Unit/KeyboardTest.php b/tests/Unit/KeyboardTest.php index 0b1683b..a56688c 100644 --- a/tests/Unit/KeyboardTest.php +++ b/tests/Unit/KeyboardTest.php @@ -3,8 +3,8 @@ namespace Al3x5\xBot\Tests\Unit; use Al3x5\xBot\Telegram\Factories\Keyboard; -use Al3x5\xBot\Telegram\Factories\InlineButton; -use Al3x5\xBot\Telegram\Factories\ReplyButton; +use Al3x5\xBot\Telegram\Factories\Keyboard\InlineButton; +use Al3x5\xBot\Telegram\Factories\Keyboard\ReplyButton; use Al3x5\xBot\Telegram\Entities\InlineKeyboardMarkup; use Al3x5\xBot\Telegram\Entities\ReplyKeyboardMarkup; use Al3x5\xBot\Telegram\Entities\ReplyKeyboardRemove; @@ -19,14 +19,14 @@ public function testInlineReturnsInlineKeyboardInstance(): void { $keyboard = Keyboard::inline(); - $this->assertInstanceOf(\Al3x5\xBot\Telegram\Factories\Inline::class, $keyboard); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Factories\Keyboard\Inline::class, $keyboard); } public function testReplyReturnsReplyKeyboardInstance(): void { $keyboard = Keyboard::reply(); - $this->assertInstanceOf(\Al3x5\xBot\Telegram\Factories\Reply::class, $keyboard); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Factories\Keyboard\Reply::class, $keyboard); } public function testRemoveReturnsReplyKeyboardRemove(): void diff --git a/tests/Unit/FormatHelperTest.php b/tests/Unit/TextTest.php similarity index 54% rename from tests/Unit/FormatHelperTest.php rename to tests/Unit/TextTest.php index fcd93c0..89b6a9e 100644 --- a/tests/Unit/FormatHelperTest.php +++ b/tests/Unit/TextTest.php @@ -3,10 +3,10 @@ namespace Al3x5\xBot\Tests\Unit; use Al3x5\xBot\Config; -use Al3x5\xBot\Telegram\FormatHelper; +use Al3x5\xBot\Telegram\Text; use PHPUnit\Framework\TestCase; -class FormatHelperTest extends TestCase +class TextTest extends TestCase { public static function setUpBeforeClass(): void { @@ -25,79 +25,108 @@ public static function setUpBeforeClass(): void public function testBold(): void { - $result = FormatHelper::bold('Hello'); + $result = Text::bold('Hello'); $this->assertEquals('Hello', $result); } public function testItalic(): void { - $result = FormatHelper::italic('Hello'); + $result = Text::italic('Hello'); $this->assertEquals('Hello', $result); } public function testUnderline(): void { - $result = FormatHelper::underline('Hello'); + $result = Text::underline('Hello'); $this->assertEquals('Hello', $result); } public function testStrikethrough(): void { - $result = FormatHelper::strikethrough('Hello'); + $result = Text::strikethrough('Hello'); $this->assertEquals('Hello', $result); } public function testSpoiler(): void { - $result = FormatHelper::spoiler('Hello'); + $result = Text::spoiler('Hello'); $this->assertEquals('Hello', $result); } public function testLink(): void { - $result = FormatHelper::link('Click here', 'https://example.com'); + $result = Text::link('Click here', 'https://example.com'); $this->assertEquals('Click here', $result); } public function testMention(): void { - $result = FormatHelper::mention('John', 123456); + $result = Text::mention('John', 123456); $this->assertEquals('John', $result); } public function testEmoji(): void { - $result = FormatHelper::emoji('😀', '123456789'); + $result = Text::emoji('😀', '123456789'); $this->assertEquals('😀', $result); } public function testInlineCode(): void { - $result = FormatHelper::inlineCode('code'); + $result = Text::inlineCode('code'); $this->assertEquals('code', $result); } public function testCodeBlockWithoutLanguage(): void { - $result = FormatHelper::codeBlock('code'); + $result = Text::codeBlock('code'); $this->assertEquals('
code
', $result); } public function testCodeBlockWithLanguage(): void { - $result = FormatHelper::codeBlock('code', 'php'); + $result = Text::codeBlock('code', 'php'); $this->assertEquals('
code
', $result); } public function testBlockQuote(): void { - $result = FormatHelper::blockQuote('Quote'); + $result = Text::blockQuote('Quote'); $this->assertEquals('
Quote
', $result); } public function testExpandableBlockQuote(): void { - $result = FormatHelper::expandableBlockQuote('Quote'); + $result = Text::expandableBlockQuote('Quote'); $this->assertEquals('
Quote
', $result); } -} \ No newline at end of file + + public function testRichBoldReturnsRichTextBold(): void + { + $result = Text::richBold('hello'); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Entities\RichTextBold::class, $result); + $this->assertEquals('bold', $result->getType()); + } + + public function testRichItalicReturnsRichTextItalic(): void + { + $result = Text::richItalic('hello'); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Entities\RichTextItalic::class, $result); + $this->assertEquals('italic', $result->getType()); + } + + public function testRichUrlReturnsRichTextUrl(): void + { + $result = Text::richUrl('click', 'https://example.com'); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Entities\RichTextUrl::class, $result); + $this->assertEquals('url', $result->getType()); + $this->assertEquals('https://example.com', $result->getUrl()); + } + + public function testRichCodeReturnsRichTextCode(): void + { + $result = Text::richCode('echo hello'); + $this->assertInstanceOf(\Al3x5\xBot\Telegram\Entities\RichTextCode::class, $result); + $this->assertEquals('code', $result->getType()); + } +}