Skip to content

Commit 6804631

Browse files
authored
Merge pull request #1465 from php-telegram-bot/bot-api-7.1
Bot API 7.1
2 parents 784c209 + 0991911 commit 6804631

File tree

10 files changed

+77
-20
lines changed

10 files changed

+77
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
99
- [:exclamation:][unreleased-bc-minimum-php-81] PHP 8.1+ required!
1010
### Added
1111
- Bot API 7.0 (@noplanman, @TiiFuchs) (#1459)
12+
- Bot API 7.1 (@noplanman)
1213
### Changed
1314
- [:exclamation:][unreleased-bc-user-to-users] Various fields have been pluralised from "user" to "users".
1415
### Deprecated

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
A Telegram Bot based on the official [Telegram Bot API]
99

10-
[![API Version](https://img.shields.io/badge/Bot%20API-6.9%20%28September%202023%29-32a2da.svg)](https://core.telegram.org/bots/api-changelog#september-22-2023)
10+
[![API Version](https://img.shields.io/badge/Bot%20API-7.1%20%28February%202024%29-32a2da.svg)](https://core.telegram.org/bots/api-changelog#february-16-2024)
1111
[![Join the bot support group on Telegram](https://img.shields.io/badge/telegram-@PHP__Telegram__Bot__Support-64659d.svg)](https://telegram.me/PHP_Telegram_Bot_Support)
1212
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate)
1313

@@ -78,7 +78,7 @@ This Bot aims to provide a platform where one can simply write a bot and have in
7878

7979
The Bot can:
8080
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
81-
- Supports all types and methods according to Telegram Bot API 6.9 (September 2023).
81+
- Supports all types and methods according to Telegram Bot API 7.1 (February 2024).
8282
- Supports supergroups.
8383
- Handle commands in chat with other bots.
8484
- Manage Channel from the bot admin interface.
@@ -389,15 +389,15 @@ The reason for denying an update can be defined with the `$reason` parameter. Th
389389

390390
### Types
391391

392-
All types are implemented according to Telegram API 6.9 (September 2023).
392+
All types are implemented according to Telegram API 7.1 (February 2024).
393393

394394
### Inline Query
395395

396-
Full support for inline query according to Telegram API 6.9 (September 2023).
396+
Full support for inline query according to Telegram API 7.1 (February 2024).
397397

398398
### Methods
399399

400-
All methods are implemented according to Telegram API 6.9 (September 2023).
400+
All methods are implemented according to Telegram API 7.1 (February 2024).
401401

402402
#### Send Message
403403

src/Commands/Command.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function preExecute(): ServerResponse
193193
'text' => sprintf(
194194
"/%s command is only available in a private chat.\n(`%s`)",
195195
$this->getName(),
196-
$message->getText()
196+
$message->getText(),
197197
),
198198
]);
199199
}
@@ -422,11 +422,11 @@ public function replyToChat(string $text, array $data = []): ServerResponse
422422
'chat_id' => $message->getChat()->getId(),
423423
'text' => $text,
424424
];
425-
425+
426426
if ($message->getIsTopicMessage()) {
427427
$reply['message_thread_id'] = $message->getMessageThreadId();
428428
}
429-
429+
430430
return Request::sendMessage(array_merge($reply, $data));
431431
}
432432

src/DB.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -1315,25 +1315,25 @@ public static function insertMessageRequest(Message $message): bool
13151315
$sth = self::$pdo->prepare('
13161316
INSERT IGNORE INTO `' . TB_MESSAGE . '`
13171317
(
1318-
`id`, `user_id`, `chat_id`, `message_thread_id`, `sender_chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
1318+
`id`, `user_id`, `chat_id`, `message_thread_id`, `sender_chat_id`, `sender_boost_count`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
13191319
`forward_signature`, `forward_sender_name`, `forward_date`, `is_topic_message`,
1320-
`reply_to_chat`, `reply_to_message`, `external_reply`, `via_bot`, `link_preview_options`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
1320+
`reply_to_chat`, `reply_to_message`, `external_reply`, `quote`, `reply_to_story`, `via_bot`, `link_preview_options`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
13211321
`audio`, `document`, `animation`, `game`, `photo`, `sticker`, `story`, `video`, `voice`, `video_note`, `caption`, `has_media_spoiler`, `contact`,
13221322
`location`, `venue`, `poll`, `dice`, `new_chat_members`, `left_chat_member`,
13231323
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
13241324
`supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
1325-
`pinned_message`, `invoice`, `successful_payment`, `users_shared`, `chat_shared`, `connected_website`, `write_access_allowed`, `passport_data`, `proximity_alert_triggered`,
1325+
`pinned_message`, `invoice`, `successful_payment`, `users_shared`, `chat_shared`, `connected_website`, `write_access_allowed`, `passport_data`, `proximity_alert_triggered`, `boost_added`,
13261326
`forum_topic_created`, `forum_topic_edited`, `forum_topic_closed`, `forum_topic_reopened`, `general_forum_topic_hidden`, `general_forum_topic_unhidden`,
13271327
`video_chat_scheduled`, `video_chat_started`, `video_chat_ended`, `video_chat_participants_invited`, `web_app_data`, `reply_markup`
13281328
) VALUES (
1329-
:message_id, :user_id, :chat_id, :message_thread_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
1329+
:message_id, :user_id, :chat_id, :message_thread_id, :sender_chat_id, :sender_boost_count, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
13301330
:forward_signature, :forward_sender_name, :forward_date, :is_topic_message,
1331-
:reply_to_chat, :reply_to_message, :external_reply, :via_bot, :link_preview_options, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
1331+
:reply_to_chat, :reply_to_message, :external_reply, :quote, :reply_to_story, :via_bot, :link_preview_options, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
13321332
:audio, :document, :animation, :game, :photo, :sticker, :story, :video, :voice, :video_note, :caption, :has_media_spoiler, :contact,
13331333
:location, :venue, :poll, :dice, :new_chat_members, :left_chat_member,
13341334
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
13351335
:supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
1336-
:pinned_message, :invoice, :successful_payment, :users_shared, :chat_shared, :connected_website, :write_access_allowed, :passport_data, :proximity_alert_triggered,
1336+
:pinned_message, :invoice, :successful_payment, :users_shared, :chat_shared, :connected_website, :write_access_allowed, :passport_data, :proximity_alert_triggered, :boost_added,
13371337
:forum_topic_created, :forum_topic_edited, :forum_topic_closed, :forum_topic_reopened, :general_forum_topic_hidden, :general_forum_topic_unhidden,
13381338
:video_chat_scheduled, :video_chat_started, :video_chat_ended, :video_chat_participants_invited, :web_app_data, :reply_markup
13391339
)
@@ -1355,6 +1355,7 @@ public static function insertMessageRequest(Message $message): bool
13551355
$sth->bindValue(':sender_chat_id', $sender_chat_id);
13561356
$sth->bindValue(':message_thread_id', $message->getMessageThreadId());
13571357
$sth->bindValue(':user_id', $user_id);
1358+
$sth->bindValue(':sender_boost_count', $message->getSenderBoostCount());
13581359
$sth->bindValue(':date', $date);
13591360
$sth->bindValue(':forward_from', $forward_from);
13601361
$sth->bindValue(':forward_from_chat', $forward_from_chat);
@@ -1372,6 +1373,8 @@ public static function insertMessageRequest(Message $message): bool
13721373
$sth->bindValue(':reply_to_message', $reply_to_message_id);
13731374
$sth->bindValue(':external_reply', $message->getExternalReply());
13741375

1376+
$sth->bindValue(':quote', $message->getQuote());
1377+
$sth->bindValue(':reply_to_story', $message->getReplyToStory());
13751378
$sth->bindValue(':via_bot', $via_bot_id);
13761379
$sth->bindValue(':link_preview_options', $message->getLinkPreviewOptions());
13771380
$sth->bindValue(':edit_date', self::getTimestamp($message->getEditDate()));
@@ -1417,6 +1420,7 @@ public static function insertMessageRequest(Message $message): bool
14171420
$sth->bindValue(':write_access_allowed', $message->getWriteAccessAllowed());
14181421
$sth->bindValue(':passport_data', $message->getPassportData());
14191422
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
1423+
$sth->bindValue(':boost_added', $message->getBoostAdded());
14201424
$sth->bindValue(':forum_topic_created', $message->getForumTopicCreated());
14211425
$sth->bindValue(':forum_topic_edited', $message->getForumTopicEdited());
14221426
$sth->bindValue(':forum_topic_closed', $message->getForumTopicClosed());

src/Entities/Chat.php

+2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@
4747
* @method Message getPinnedMessage() Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat.
4848
* @method ChatPermissions getPermissions() Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
4949
* @method int getSlowModeDelay() Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat.
50+
* @method int getUnrestrictBoostCount() Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions.
5051
* @method int getMessageAutoDeleteTime() Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
5152
* @method bool getHasAggressiveAntiSpamEnabled() Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators. Returned only in getChat.
5253
* @method bool getHasHiddenMembers() Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat.
5354
* @method bool getHasProtectedContent() Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
5455
* @method bool getHasVisibleHistory() Optional. True, if new chat members will have access to old messages; available only to chat administrators
5556
* @method string getStickerSetName() Optional. For supergroups, name of group sticker set. Returned only in getChat.
5657
* @method bool getCanSetStickerSet() Optional. True, if the bot can change the group sticker set. Returned only in getChat.
58+
* @method string getCustomEmojiStickerSetName() Optional. For supergroups, the name of the group's custom emoji sticker set. Custom emoji from this set can be used by all users and bots in the group.
5759
* @method int getLinkedChatId() Optional. Unique identifier for the linked chat. Returned only in getChat.
5860
* @method ChatLocation getLocation() Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
5961
*/

src/Entities/ChatBoostAdded.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the TelegramBot package.
5+
*
6+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Longman\TelegramBot\Entities;
13+
14+
/**
15+
* This object represents a service message about a user boosting a chat.
16+
*
17+
* @link https://core.telegram.org/bots/api#chatboostadded
18+
*
19+
* @method int getBoostCount() Number of boosts added by the user
20+
*/
21+
class ChatBoostAdded extends Entity
22+
{
23+
24+
}

src/Entities/Message.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
* @link https://core.telegram.org/bots/api#message
3939
*
4040
* @method int getMessageId() Unique message identifier
41-
* @method int getMessageThreadId() Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
41+
* @method int getMessageThreadId() Optional. Unique identifier of a message thread to which the message belongs;
42+
for supergroups only
4243
* @method User getFrom() Optional. Sender, can be empty for messages sent to channels
4344
* @method Chat getSenderChat() Optional. Sender of the message, sent on behalf of a chat. The channel itself for channel messages. The supergroup itself for messages from anonymous group administrators. The linked channel for messages automatically forwarded to the discussion group
45+
* @method int getSenderBoostCount() Optional. If the sender of the message boosted the chat, the number of boosts added by the user
4446
* @method int getDate() Date the message was sent in Unix time
4547
* @method Chat getChat() Conversation the message belongs to
4648
* @method MessageOrigin getForwardOrigin() Optional. Information about the original message for forwarded messages
@@ -49,6 +51,7 @@
4951
* @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.
5052
* @method ExternalReplyInfo getExternalReply() Optional. Information about the message that is being replied to, which may come from another chat or forum topic
5153
* @method TextQuote getQuote() Optional. For replies that quote part of the original message, the quoted part of the message
54+
* @method Story getReplyToStory() Optional. For replies to a story, the original story
5255
* @method User getViaBot() Optional. Bot through which the message was sent
5356
* @method int getEditDate() Optional. Date the message was last edited in Unix time
5457
* @method bool getHasProtectedContent() Optional. True, if the message can't be forwarded
@@ -94,6 +97,7 @@
9497
* @method WriteAccessAllowed getWriteAccessAllowed() Optional. Service message: the user allowed the bot added to the attachment menu to write messages
9598
* @method PassportData getPassportData() Optional. Telegram Passport data
9699
* @method ProximityAlertTriggered getProximityAlertTriggered() Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location.
100+
* @method ChatBoostAdded getBoostAdded() Optional. Service message: user boosted the chat
97101
* @method ForumTopicCreated getForumTopicCreated() Optional. Service message: forum topic created
98102
* @method ForumTopicEdited getForumTopicEdited() Optional. Service message: forum topic edited
99103
* @method ForumTopicClosed getForumTopicClosed() Optional. Service message: forum topic closed
@@ -126,6 +130,7 @@ protected function subEntities(): array
126130
'reply_to_message' => ReplyToMessage::class,
127131
'external_reply' => ExternalReplyInfo::class,
128132
'quote' => TextQuote::class,
133+
'reply_to_story' => Story::class,
129134
'via_bot' => User::class,
130135
'link_preview_options' => LinkPreviewOptions::class,
131136
'entities' => [MessageEntity::class],
@@ -157,6 +162,7 @@ protected function subEntities(): array
157162
'write_access_allowed' => WriteAccessAllowed::class,
158163
'passport_data' => PassportData::class,
159164
'proximity_alert_triggered' => ProximityAlertTriggered::class,
165+
'boost_added' => ChatBoostAdded::class,
160166
'forum_topic_created' => ForumTopicCreated::class,
161167
'forum_topic_edited' => ForumTopicEdited::class,
162168
'forum_topic_closed' => ForumTopicClosed::class,
@@ -188,7 +194,7 @@ public function getFullCommand(): ?string
188194
return null;
189195
}
190196

191-
$no_EOL = strtok($text, PHP_EOL);
197+
$no_EOL = strtok($text, PHP_EOL);
192198
$no_space = strtok($text, ' ');
193199

194200
//try to understand which separator \n or space divide /command from text
@@ -214,7 +220,7 @@ public function getCommand(): ?string
214220

215221
//check if command is followed by bot username
216222
$split_cmd = explode('@', $full_command);
217-
if (! isset($split_cmd[1])) {
223+
if (!isset($split_cmd[1])) {
218224
//command is not followed by name
219225
return $full_command;
220226
}
@@ -230,7 +236,7 @@ public function getCommand(): ?string
230236
/**
231237
* For text messages, the actual UTF-8 text of the message, 0-4096 characters.
232238
*
233-
* @param bool $without_cmd
239+
* @param bool $without_cmd
234240
*
235241
* @return string|null
236242
*/
@@ -307,6 +313,7 @@ public function getType(): string
307313
'write_access_allowed',
308314
'passport_data',
309315
'proximity_alert_triggered',
316+
'boost_added',
310317
'forum_topic_created',
311318
'forum_topic_edited',
312319
'forum_topic_closed',

src/Entities/Story.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,19 @@
1515
* Class Story
1616
*
1717
* @link https://core.telegram.org/bots/api#story
18+
*
19+
* @method Chat getChat() Chat that posted the story
20+
* @method int getId() Unique identifier for the story in the chat
1821
*/
1922
class Story extends Entity
2023
{
21-
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
protected function subEntities(): array
28+
{
29+
return [
30+
'chat' => Chat::class,
31+
];
32+
}
2233
}

0 commit comments

Comments
 (0)