Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 7.0 #1459

Merged
merged 19 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bot API 7.0 - Replies 2.0
  • Loading branch information
noplanman committed May 4, 2024
commit e49bf3bc1e323f8cbb6971b5547b67d9da1dceaa
5 changes: 3 additions & 2 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ public static function insertMessageRequest(Message $message): bool
(
`id`, `user_id`, `chat_id`, `message_thread_id`, `sender_chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`forward_signature`, `forward_sender_name`, `forward_date`, `is_topic_message`,
`reply_to_chat`, `reply_to_message`, `via_bot`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
`reply_to_chat`, `reply_to_message`, `external_reply`, `via_bot`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
`audio`, `document`, `animation`, `game`, `photo`, `sticker`, `story`, `video`, `voice`, `video_note`, `caption`, `has_media_spoiler`, `contact`,
`location`, `venue`, `poll`, `dice`, `new_chat_members`, `left_chat_member`,
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
Expand All @@ -1230,7 +1230,7 @@ public static function insertMessageRequest(Message $message): bool
) VALUES (
:message_id, :user_id, :chat_id, :message_thread_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_signature, :forward_sender_name, :forward_date, :is_topic_message,
:reply_to_chat, :reply_to_message, :via_bot, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
:reply_to_chat, :reply_to_message, :external_reply, :via_bot, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
:audio, :document, :animation, :game, :photo, :sticker, :story, :video, :voice, :video_note, :caption, :has_media_spoiler, :contact,
:location, :venue, :poll, :dice, :new_chat_members, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
Expand Down Expand Up @@ -1272,6 +1272,7 @@ public static function insertMessageRequest(Message $message): bool
}
$sth->bindValue(':reply_to_chat', $reply_to_chat_id);
$sth->bindValue(':reply_to_message', $reply_to_message_id);
$sth->bindValue(':external_reply', $message->getExternalReply());

$sth->bindValue(':via_bot', $via_bot_id);
$sth->bindValue(':edit_date', self::getTimestamp($message->getEditDate()));
Expand Down
74 changes: 74 additions & 0 deletions src/Entities/ExternalReplyInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Longman\TelegramBot\Entities;

/**
* This object contains information about a message that is being replied to, which may come from another chat or forum topic.
*
* @link https://core.telegram.org/bots/api#externalreplyinfo
*
* @method MessageOrigin getOrigin() Origin of the message replied to by the given message
* @method Chat getChat() Optional. Chat the original message belongs to. Available only if the chat is a supergroup or a channel.
* @method int getMessageId() Optional. Unique message identifier inside the original chat. Available only if the original chat is a supergroup or a channel.
* @method LinkPreviewOptions getLinkPreviewOptions() Optional. Options used for link preview generation for the original message, if it is a text message
* @method Animation getAnimation() Optional. Message is an animation, information about the animation
* @method Audio getAudio() Optional. Message is an audio file, information about the file
* @method Document getDocument() Optional. Message is a general file, information about the file
* @method PhotoSize[] getPhoto() Optional. Message is a photo, available sizes of the photo
* @method Sticker getSticker() Optional. Message is a sticker, information about the sticker
* @method Story getStory() Optional. Message is a forwarded story
* @method Video getVideo() Optional. Message is a video, information about the video
* @method VideoNote getVideoNote() Optional. Message is a video note, information about the video message
* @method Voice getVoice() Optional. Message is a voice message, information about the file
* @method bool getHasMediaSpoiler() Optional. True, if the message media is covered by a spoiler animation
* @method Contact getContact() Optional. Message is a shared contact, information about the contact
* @method Dice getDice() Optional. Message is a dice with random value
* @method Game getGame() Optional. Message is a game, information about the game. More about games »
* @method Giveaway getGiveaway() Optional. Message is a scheduled giveaway, information about the giveaway
* @method GiveawayWinners getGiveawayWinners() Optional. A giveaway with public winners was completed
* @method Invoice getInvoice() Optional. Message is an invoice for a payment, information about the invoice. More about payments »
* @method Location getLocation() Optional. Message is a shared location, information about the location
* @method Poll getPoll() Optional. Message is a native poll, information about the poll
* @method Venue getVenue() Optional. Message is a venue, information about the venue
*/
class ExternalReplyInfo extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities(): array
{
return [
'origin' => MessageOrigin::class,
'chat' => Chat::class,
'link_preview_options' => LinkPreviewOptions::class,
'animation' => Animation::class,
'audio' => Audio::class,
'document' => Document::class,
'photo' => [PhotoSize::class],
'sticker' => Sticker::class,
'story' => Story::class,
'video' => Video::class,
'video_note' => VideoNote::class,
'voice' => Voice::class,
'contact' => Contact::class,
'dice' => Dice::class,
'game' => Game::class,
'giveaway' => Giveaway::class,
'giveaway_winners' => GiveawayWinners::class,
'invoice' => Invoice::class,
'location' => Location::class,
'poll' => Poll::class,
'venue' => Venue::class,
];
}
}
4 changes: 4 additions & 0 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
* @method bool getIsTopicMessage() Optional. True, if the message is sent to a forum topic
* @method bool getIsAutomaticForward() Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group
* @method ReplyToMessage getReplyToMessage() Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
* @method ExternalReplyInfo getExternalReply() Optional. Information about the message that is being replied to, which may come from another chat or forum topic
* @method TextQuote getQuote() Optional. For replies that quote part of the original message, the quoted part of the message
* @method User getViaBot() Optional. Bot through which the message was sent
* @method int getEditDate() Optional. Date the message was last edited in Unix time
* @method bool getHasProtectedContent() Optional. True, if the message can't be forwarded
Expand Down Expand Up @@ -115,6 +117,8 @@ protected function subEntities(): array
'forward_from' => User::class,
'forward_from_chat' => Chat::class,
'reply_to_message' => ReplyToMessage::class,
'external_reply' => ExternalReplyInfo::class,
'quote' => TextQuote::class,
'via_bot' => User::class,
'entities' => [MessageEntity::class],
'animation' => Animation::class,
Expand Down
38 changes: 38 additions & 0 deletions src/Entities/ReplyParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Longman\TelegramBot\Entities;

/**
* Describes reply parameters for the message that is being sent.
*
* @link https://core.telegram.org/bots/api#replyparameters
*
* @method int getMessageId() Identifier of the message that will be replied to in the current chat, or in the chat chat_id if it is specified
* @method int|string getChatId() Optional. If the message to be replied to is from a different chat, unique identifier for the chat or username of the channel (in the format @channelusername)
* @method bool getAllowSendingWithoutReply() Optional. Pass True if the message should be sent even if the specified message to be replied to is not found; can be used only for replies in the same chat and forum topic.
* @method string getQuote() Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing. The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and custom_emoji entities. The message will fail to send if the quote isn't found in the original message.
* @method string getQuoteParseMode() Optional. Mode for parsing entities in the quote. See formatting options for more details.
* @method MessageEntity[] getQuoteEntities() Optional. A JSON-serialized list of special entities that appear in the quote. It can be specified instead of quote_parse_mode.
* @method int getQuotePosition() Optional. Position of the quote in the original message in UTF-16 code units
*/
class ReplyParameters extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities(): array
{
return [
'quote_entities' => [MessageEntity::class],
];
}
}
35 changes: 35 additions & 0 deletions src/Entities/TextQuote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Longman\TelegramBot\Entities;

/**
* This object contains information about the quoted part of a message that is replied to by the given message.
*
* @link https://core.telegram.org/bots/api#textquote
*
* @method string getText() Text of the quoted part of a message that is replied to by the given message
* @method MessageEntity[] getEntities() Optional. Special entities that appear in the quote. Currently, only bold, italic, underline, strikethrough, spoiler, and custom_emoji entities are kept in quotes.
* @method int getPosition() Approximate quote position in the original message in UTF-16 code units as specified by the sender
* @method bool getIsManual() Optional. True, if the quote was chosen manually by the message sender. Otherwise, the quote was added automatically by the server.
*/
class TextQuote extends Entity
{
/**
* {@inheritdoc}
*/
protected function subEntities(): array
{
return [
'entities' => [MessageEntity::class],
];
}
}
1 change: 1 addition & 0 deletions structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`is_automatic_forward` tinyint(1) DEFAULT 0 COMMENT 'True, if the message is a channel post that was automatically forwarded to the connected discussion group',
`reply_to_chat` bigint NULL DEFAULT NULL COMMENT 'Unique chat identifier',
`reply_to_message` bigint UNSIGNED DEFAULT NULL COMMENT 'Message that this message is reply to',
`external_reply` TEXT NULL DEFAULT NULL COMMENT 'Optional. Information about the message that is being replied to, which may come from another chat or forum topic',
`via_bot` bigint NULL DEFAULT NULL COMMENT 'Optional. Bot through which the message was sent',
`edit_date` timestamp NULL DEFAULT NULL COMMENT 'Date the message was last edited in Unix time',
`has_protected_content` tinyint(1) DEFAULT 0 COMMENT 'True, if the message can''t be forwarded',
Expand Down
3 changes: 3 additions & 0 deletions utils/db-schema-update/0.82.0-unreleased.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ CREATE TABLE IF NOT EXISTS `message_reaction_count` (
FOREIGN KEY (`chat_id`) REFERENCES `chat` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;

ALTER TABLE `message`
ADD COLUMN `external_reply` TEXT NULL DEFAULT NULL COMMENT 'Optional. Information about the message that is being replied to, which may come from another chat or forum topic' AFTER `reply_to_message`;

ALTER TABLE `telegram_update`
ADD COLUMN `message_reaction_id` bigint UNSIGNED DEFAULT NULL COMMENT 'A reaction to a message was changed by a user' AFTER `edited_channel_post_id`,
ADD COLUMN `message_reaction_count_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Reactions to a message with anonymous reactions were changed' AFTER `message_reaction_id`;