Skip to content

Commit

Permalink
Merge pull request #1465 from php-telegram-bot/bot-api-7.1
Browse files Browse the repository at this point in the history
Bot API 7.1
  • Loading branch information
noplanman authored May 25, 2024
2 parents 784c209 + 0991911 commit 6804631
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- [:exclamation:][unreleased-bc-minimum-php-81] PHP 8.1+ required!
### Added
- Bot API 7.0 (@noplanman, @TiiFuchs) (#1459)
- Bot API 7.1 (@noplanman)
### Changed
- [:exclamation:][unreleased-bc-user-to-users] Various fields have been pluralised from "user" to "users".
### Deprecated
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

[![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)
[![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)
[![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)
[![Donate](https://img.shields.io/badge/%F0%9F%92%99-Donate%20%2F%20Support%20Us-blue.svg)](#donate)

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

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

### Types

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

### Inline Query

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

### Methods

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

#### Send Message

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function preExecute(): ServerResponse
'text' => sprintf(
"/%s command is only available in a private chat.\n(`%s`)",
$this->getName(),
$message->getText()
$message->getText(),
),
]);
}
Expand Down Expand Up @@ -422,11 +422,11 @@ public function replyToChat(string $text, array $data = []): ServerResponse
'chat_id' => $message->getChat()->getId(),
'text' => $text,
];

if ($message->getIsTopicMessage()) {
$reply['message_thread_id'] = $message->getMessageThreadId();
}

return Request::sendMessage(array_merge($reply, $data));
}

Expand Down
16 changes: 10 additions & 6 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,25 +1315,25 @@ public static function insertMessageRequest(Message $message): bool
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_MESSAGE . '`
(
`id`, `user_id`, `chat_id`, `message_thread_id`, `sender_chat_id`, `date`, `forward_from`, `forward_from_chat`, `forward_from_message_id`,
`id`, `user_id`, `chat_id`, `message_thread_id`, `sender_chat_id`, `sender_boost_count`, `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`, `external_reply`, `via_bot`, `link_preview_options`, `edit_date`, `media_group_id`, `author_signature`, `text`, `entities`, `caption_entities`,
`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`,
`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`,
`supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
`pinned_message`, `invoice`, `successful_payment`, `users_shared`, `chat_shared`, `connected_website`, `write_access_allowed`, `passport_data`, `proximity_alert_triggered`,
`pinned_message`, `invoice`, `successful_payment`, `users_shared`, `chat_shared`, `connected_website`, `write_access_allowed`, `passport_data`, `proximity_alert_triggered`, `boost_added`,
`forum_topic_created`, `forum_topic_edited`, `forum_topic_closed`, `forum_topic_reopened`, `general_forum_topic_hidden`, `general_forum_topic_unhidden`,
`video_chat_scheduled`, `video_chat_started`, `video_chat_ended`, `video_chat_participants_invited`, `web_app_data`, `reply_markup`
) VALUES (
:message_id, :user_id, :chat_id, :message_thread_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
: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,
:forward_signature, :forward_sender_name, :forward_date, :is_topic_message,
:reply_to_chat, :reply_to_message, :external_reply, :via_bot, :link_preview_options, :edit_date, :media_group_id, :author_signature, :text, :entities, :caption_entities,
: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,
: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,
:supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
:pinned_message, :invoice, :successful_payment, :users_shared, :chat_shared, :connected_website, :write_access_allowed, :passport_data, :proximity_alert_triggered,
:pinned_message, :invoice, :successful_payment, :users_shared, :chat_shared, :connected_website, :write_access_allowed, :passport_data, :proximity_alert_triggered, :boost_added,
:forum_topic_created, :forum_topic_edited, :forum_topic_closed, :forum_topic_reopened, :general_forum_topic_hidden, :general_forum_topic_unhidden,
:video_chat_scheduled, :video_chat_started, :video_chat_ended, :video_chat_participants_invited, :web_app_data, :reply_markup
)
Expand All @@ -1355,6 +1355,7 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':sender_chat_id', $sender_chat_id);
$sth->bindValue(':message_thread_id', $message->getMessageThreadId());
$sth->bindValue(':user_id', $user_id);
$sth->bindValue(':sender_boost_count', $message->getSenderBoostCount());
$sth->bindValue(':date', $date);
$sth->bindValue(':forward_from', $forward_from);
$sth->bindValue(':forward_from_chat', $forward_from_chat);
Expand All @@ -1372,6 +1373,8 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':reply_to_message', $reply_to_message_id);
$sth->bindValue(':external_reply', $message->getExternalReply());

$sth->bindValue(':quote', $message->getQuote());
$sth->bindValue(':reply_to_story', $message->getReplyToStory());
$sth->bindValue(':via_bot', $via_bot_id);
$sth->bindValue(':link_preview_options', $message->getLinkPreviewOptions());
$sth->bindValue(':edit_date', self::getTimestamp($message->getEditDate()));
Expand Down Expand Up @@ -1417,6 +1420,7 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':write_access_allowed', $message->getWriteAccessAllowed());
$sth->bindValue(':passport_data', $message->getPassportData());
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
$sth->bindValue(':boost_added', $message->getBoostAdded());
$sth->bindValue(':forum_topic_created', $message->getForumTopicCreated());
$sth->bindValue(':forum_topic_edited', $message->getForumTopicEdited());
$sth->bindValue(':forum_topic_closed', $message->getForumTopicClosed());
Expand Down
2 changes: 2 additions & 0 deletions src/Entities/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
* @method Message getPinnedMessage() Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat.
* @method ChatPermissions getPermissions() Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat.
* @method int getSlowModeDelay() Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat.
* @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.
* @method int getMessageAutoDeleteTime() Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds. Returned only in getChat.
* @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.
* @method bool getHasHiddenMembers() Optional. True, if non-administrators can only get the list of bots and administrators in the chat. Returned only in getChat.
* @method bool getHasProtectedContent() Optional. True, if messages from the chat can't be forwarded to other chats. Returned only in getChat.
* @method bool getHasVisibleHistory() Optional. True, if new chat members will have access to old messages; available only to chat administrators
* @method string getStickerSetName() Optional. For supergroups, name of group sticker set. Returned only in getChat.
* @method bool getCanSetStickerSet() Optional. True, if the bot can change the group sticker set. Returned only in getChat.
* @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.
* @method int getLinkedChatId() Optional. Unique identifier for the linked chat. Returned only in getChat.
* @method ChatLocation getLocation() Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat.
*/
Expand Down
24 changes: 24 additions & 0 deletions src/Entities/ChatBoostAdded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
*
* 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 represents a service message about a user boosting a chat.
*
* @link https://core.telegram.org/bots/api#chatboostadded
*
* @method int getBoostCount() Number of boosts added by the user
*/
class ChatBoostAdded extends Entity
{

}
15 changes: 11 additions & 4 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
* @link https://core.telegram.org/bots/api#message
*
* @method int getMessageId() Unique message identifier
* @method int getMessageThreadId() Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
* @method int getMessageThreadId() Optional. Unique identifier of a message thread to which the message belongs;
for supergroups only
* @method User getFrom() Optional. Sender, can be empty for messages sent to channels
* @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
* @method int getSenderBoostCount() Optional. If the sender of the message boosted the chat, the number of boosts added by the user
* @method int getDate() Date the message was sent in Unix time
* @method Chat getChat() Conversation the message belongs to
* @method MessageOrigin getForwardOrigin() Optional. Information about the original message for forwarded messages
Expand All @@ -49,6 +51,7 @@
* @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 Story getReplyToStory() Optional. For replies to a story, the original story
* @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 @@ -94,6 +97,7 @@
* @method WriteAccessAllowed getWriteAccessAllowed() Optional. Service message: the user allowed the bot added to the attachment menu to write messages
* @method PassportData getPassportData() Optional. Telegram Passport data
* @method ProximityAlertTriggered getProximityAlertTriggered() Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location.
* @method ChatBoostAdded getBoostAdded() Optional. Service message: user boosted the chat
* @method ForumTopicCreated getForumTopicCreated() Optional. Service message: forum topic created
* @method ForumTopicEdited getForumTopicEdited() Optional. Service message: forum topic edited
* @method ForumTopicClosed getForumTopicClosed() Optional. Service message: forum topic closed
Expand Down Expand Up @@ -126,6 +130,7 @@ protected function subEntities(): array
'reply_to_message' => ReplyToMessage::class,
'external_reply' => ExternalReplyInfo::class,
'quote' => TextQuote::class,
'reply_to_story' => Story::class,
'via_bot' => User::class,
'link_preview_options' => LinkPreviewOptions::class,
'entities' => [MessageEntity::class],
Expand Down Expand Up @@ -157,6 +162,7 @@ protected function subEntities(): array
'write_access_allowed' => WriteAccessAllowed::class,
'passport_data' => PassportData::class,
'proximity_alert_triggered' => ProximityAlertTriggered::class,
'boost_added' => ChatBoostAdded::class,
'forum_topic_created' => ForumTopicCreated::class,
'forum_topic_edited' => ForumTopicEdited::class,
'forum_topic_closed' => ForumTopicClosed::class,
Expand Down Expand Up @@ -188,7 +194,7 @@ public function getFullCommand(): ?string
return null;
}

$no_EOL = strtok($text, PHP_EOL);
$no_EOL = strtok($text, PHP_EOL);
$no_space = strtok($text, ' ');

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

//check if command is followed by bot username
$split_cmd = explode('@', $full_command);
if (! isset($split_cmd[1])) {
if (!isset($split_cmd[1])) {
//command is not followed by name
return $full_command;
}
Expand All @@ -230,7 +236,7 @@ public function getCommand(): ?string
/**
* For text messages, the actual UTF-8 text of the message, 0-4096 characters.
*
* @param bool $without_cmd
* @param bool $without_cmd
*
* @return string|null
*/
Expand Down Expand Up @@ -307,6 +313,7 @@ public function getType(): string
'write_access_allowed',
'passport_data',
'proximity_alert_triggered',
'boost_added',
'forum_topic_created',
'forum_topic_edited',
'forum_topic_closed',
Expand Down
13 changes: 12 additions & 1 deletion src/Entities/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@
* Class Story
*
* @link https://core.telegram.org/bots/api#story
*
* @method Chat getChat() Chat that posted the story
* @method int getId() Unique identifier for the story in the chat
*/
class Story extends Entity
{

/**
* {@inheritdoc}
*/
protected function subEntities(): array
{
return [
'chat' => Chat::class,
];
}
}
Loading

0 comments on commit 6804631

Please sign in to comment.