Skip to content

Commit 0b92b7a

Browse files
authored
Merge pull request #1216 from noplanman/1215-bot-api-5.2
Add Bot API 5.2, Payments 2.0 and various fixes
2 parents b6ea355 + 7de6fb6 commit 0b92b7a

File tree

10 files changed

+130
-12
lines changed

10 files changed

+130
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
55

66
## [Unreleased]
77
### Notes
8-
- [:ledger: View file changes][Unreleased]
8+
- [:ledger: View file changes][Unreleased][:page_with_curl: DB migration script][unreleased-sql-migration]
99
### Added
10+
- Bot API 5.2 (Payments 2.0).
1011
### Changed
1112
### Deprecated
1213
### Removed
@@ -513,6 +514,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
513514
### Deprecated
514515
- Move `hideKeyboard` to `removeKeyboard`.
515516

517+
[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.72.0-unreleased.sql
516518
[0.72.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.71.0-0.72.0.sql
517519
[0.70.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/master/utils/db-schema-update/0.64.0-0.70.0.sql
518520
[0.70.0-bc-minimum-php-73]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#minimum-php-73

README.md

Lines changed: 5 additions & 5 deletions
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-5.1%20%28March%202021%29-32a2da.svg)](https://core.telegram.org/bots/api#march-9-2021)
10+
[![API Version](https://img.shields.io/badge/Bot%20API-5.2%20%28April%202021%29-32a2da.svg)](https://core.telegram.org/bots/api#april-26-2021)
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 5.1 (March 2021).
81+
- Supports all types and methods according to Telegram Bot API 5.2 (April 2021).
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 5.1 (March 2021).
392+
All types are implemented according to Telegram API 5.2 (April 2021).
393393

394394
### Inline Query
395395

396-
Full support for inline query according to Telegram API 5.1 (March 2021).
396+
Full support for inline query according to Telegram API 5.2 (April 2021).
397397

398398
### Methods
399399

400-
All methods are implemented according to Telegram API 5.1 (March 2021).
400+
All methods are implemented according to Telegram API 5.2 (April 2021).
401401

402402
#### Send Message
403403

src/ChatAction.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,27 @@ class ChatAction
3535

3636
/**
3737
* Record Audio chat action
38+
*
39+
* @deprecated Use ChatAction::RECORD_VOICE instead
3840
*/
39-
public const RECORD_AUDIO = 'record_audio';
41+
public const RECORD_AUDIO = 'record_voice';
42+
43+
/**
44+
* Record Voice chat action
45+
*/
46+
public const RECORD_VOICE = 'record_voice';
4047

4148
/**
4249
* Upload Audio chat action
50+
*
51+
* @deprecated Use ChatAction::UPLOAD_VOICE instead
52+
*/
53+
public const UPLOAD_AUDIO = 'upload_voice';
54+
55+
/**
56+
* Upload Voice chat action
4357
*/
44-
public const UPLOAD_AUDIO = 'upload_audio';
58+
public const UPLOAD_VOICE = 'upload_voice';
4559

4660
/**
4761
* Upload Document chat action

src/DB.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ public static function insertInlineQueryRequest(InlineQuery $inline_query): bool
613613
try {
614614
$sth = self::$pdo->prepare('
615615
INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
616-
(`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
616+
(`id`, `user_id`, `location`, `query`, `offset`, `chat_type`, `created_at`)
617617
VALUES
618-
(:id, :user_id, :location, :query, :offset, :created_at)
618+
(:id, :user_id, :location, :query, :offset, :chat_type, :created_at)
619619
');
620620

621621
$date = self::getTimestamp();
@@ -631,6 +631,7 @@ public static function insertInlineQueryRequest(InlineQuery $inline_query): bool
631631
$sth->bindValue(':location', $inline_query->getLocation());
632632
$sth->bindValue(':query', $inline_query->getQuery());
633633
$sth->bindValue(':offset', $inline_query->getOffset());
634+
$sth->bindValue(':chat_type', $inline_query->getChatType());
634635
$sth->bindValue(':created_at', $date);
635636

636637
return $sth->execute();
@@ -1065,7 +1066,7 @@ public static function insertMessageRequest(Message $message): bool
10651066
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
10661067
`supergroup_chat_created`, `channel_chat_created`, `message_auto_delete_timer_changed`, `migrate_to_chat_id`, `migrate_from_chat_id`,
10671068
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `proximity_alert_triggered`,
1068-
`voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
1069+
`voice_chat_scheduled`, `voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
10691070
) VALUES (
10701071
:message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
10711072
:forward_signature, :forward_sender_name, :forward_date,
@@ -1075,7 +1076,7 @@ public static function insertMessageRequest(Message $message): bool
10751076
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
10761077
:supergroup_chat_created, :channel_chat_created, :message_auto_delete_timer_changed, :migrate_to_chat_id, :migrate_from_chat_id,
10771078
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :proximity_alert_triggered,
1078-
:voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
1079+
:voice_chat_scheduled, :voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
10791080
)
10801081
');
10811082

@@ -1148,6 +1149,7 @@ public static function insertMessageRequest(Message $message): bool
11481149
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
11491150
$sth->bindValue(':passport_data', $message->getPassportData());
11501151
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
1152+
$sth->bindValue(':voice_chat_scheduled', $message->getVoiceChatScheduled());
11511153
$sth->bindValue(':voice_chat_started', $message->getVoiceChatStarted());
11521154
$sth->bindValue(':voice_chat_ended', $message->getVoiceChatEnded());
11531155
$sth->bindValue(':voice_chat_participants_invited', $message->getVoiceChatParticipantsInvited());

src/Entities/InlineQuery.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* @method Location getLocation() Optional. Sender location, only for bots that request user location
2525
* @method string getQuery() Text of the query (up to 512 characters)
2626
* @method string getOffset() Offset of the results to be returned, can be controlled by the bot
27+
* @method string getChatType() Optional. Type of the chat, from which the inline query was sent. Can be either “sender” for a private chat with the inline query sender, “private”, “group”, “supergroup”, or “channel”. The chat type should be always known for requests sent from official clients and most third-party clients, unless the request was sent from a secret chat
2728
*/
2829
class InlineQuery extends Entity
2930
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\InputMessageContent;
13+
14+
use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;
15+
16+
/**
17+
* Class InputTextMessageContent
18+
*
19+
* @link https://core.telegram.org/bots/api#inputinvoicemessagecontent
20+
*
21+
* @method string getTitle() Product name, 1-32 characters
22+
* @method string getDescription() Product description, 1-255 characters
23+
* @method string getPayload() Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
24+
* @method string getProviderToken() Payment provider token, obtained via Botfather
25+
* @method string getCurrency() Three-letter ISO 4217 currency code, see more on currencies
26+
* @method LabeledPrice[] getPrices() Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
27+
* @method int getMaxTipAmount() Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
28+
* @method int[] getSuggestedTipAmounts() Optional. A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
29+
* @method string getProviderData() Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider. A detailed description of the required fields should be provided by the payment provider.
30+
* @method string getPhotoUrl() Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
31+
* @method int getPhotoSize() Optional. Photo size
32+
* @method int getPhotoWidth() Optional. Photo width
33+
* @method int getPhotoHeight() Optional. Photo height
34+
* @method bool getNeedName() Optional. Pass True, if you require the user's full name to complete the order
35+
* @method bool getNeedPhoneNumber() Optional. Pass True, if you require the user's phone number to complete the order
36+
* @method bool getNeedEmail() Optional. Pass True, if you require the user's email address to complete the order
37+
* @method bool getNeedShippingAddress() Optional. Pass True, if you require the user's shipping address to complete the order
38+
* @method bool getSendPhoneNumberToProvider() Optional. Pass True, if user's phone number should be sent to provider
39+
* @method bool getSendEmailToProvider() Optional. Pass True, if user's email address should be sent to provider
40+
* @method bool getIsFlexible() Optional. Pass True, if the final price depends on the shipping method
41+
*
42+
* @method $this setTitle(string $title) Product name, 1-32 characters
43+
* @method $this setDescription(string $description) Product description, 1-255 characters
44+
* @method $this setPayload(string $payload) Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
45+
* @method $this setProviderToken(string $provider_token) Payment provider token, obtained via Botfather
46+
* @method $this setCurrency(string $currency) Three-letter ISO 4217 currency code, see more on currencies
47+
* @method $this setPrices(LabeledPrice[] $prices) Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
48+
* @method $this setMaxTipAmount(int $max_tip_amount) Optional. The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
49+
* @method $this setSuggestedTipAmounts(int[] $suggested_tip_amounts) Optional. A JSON-serialized array of suggested amounts of tip in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
50+
* @method $this setProviderData(string $provider_data) Optional. A JSON-serialized object for data about the invoice, which will be shared with the payment provider. A detailed description of the required fields should be provided by the payment provider.
51+
* @method $this setPhotoUrl(string $photo_url) Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
52+
* @method $this setPhotoSize(int $photo_size) Optional. Photo size
53+
* @method $this setPhotoWidth(int $photo_width) Optional. Photo width
54+
* @method $this setPhotoHeight(int $photo_height) Optional. Photo height
55+
* @method $this setNeedName(bool $need_name) Optional. Pass True, if you require the user's full name to complete the order
56+
* @method $this setNeedPhoneNumber(bool $need_phone_number) Optional. Pass True, if you require the user's phone number to complete the order
57+
* @method $this setNeedEmail(bool $need_email) Optional. Pass True, if you require the user's email address to complete the order
58+
* @method $this setNeedShippingAddress(bool $need_shipping_address) Optional. Pass True, if you require the user's shipping address to complete the order
59+
* @method $this setSendPhoneNumberToProvider(bool $send_phone_number_to_provider) Optional. Pass True, if user's phone number should be sent to provider
60+
* @method $this setSendEmailToProvider(bool $send_email_to_provider) Optional. Pass True, if user's email address should be sent to provider
61+
* @method $this setIsFlexible(bool $is_flexible) Optional. Pass True, if the final price depends on the shipping method
62+
*/
63+
class InputInvoiceMessageContent extends InlineEntity implements InputMessageContent
64+
{
65+
66+
}

src/Entities/Message.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
* @method string getConnectedWebsite() Optional. The domain name of the website on which the user has logged in.
7474
* @method PassportData getPassportData() Optional. Telegram Passport data
7575
* @method ProximityAlertTriggered getProximityAlertTriggered() Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live Location.
76+
* @method VoiceChatScheduled getVoiceChatScheduled() Optional. Service message: voice chat scheduled
7677
* @method VoiceChatStarted getVoiceChatStarted() Optional. Service message: voice chat started
7778
* @method VoiceChatEnded getVoiceChatEnded() Optional. Service message: voice chat ended
7879
* @method VoiceChatParticipantsInvited getVoiceChatParticipantsInvited() Optional. Service message: new participants invited to a voice chat
@@ -118,6 +119,7 @@ protected function subEntities(): array
118119
'successful_payment' => SuccessfulPayment::class,
119120
'passport_data' => PassportData::class,
120121
'proximity_alert_triggered' => ProximityAlertTriggered::class,
122+
'voice_chat_scheduled' => VoiceChatScheduled::class,
121123
'voice_chat_started' => VoiceChatStarted::class,
122124
'voice_chat_ended' => VoiceChatEnded::class,
123125
'voice_chat_participants_invited' => VoiceChatParticipantsInvited::class,
@@ -252,6 +254,7 @@ public function getType(): string
252254
'successful_payment',
253255
'passport_data',
254256
'proximity_alert_triggered',
257+
'voice_chat_scheduled',
255258
'voice_chat_started',
256259
'voice_chat_ended',
257260
'voice_chat_participants_invited',

src/Entities/VoiceChatScheduled.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
* Class VoiceChatScheduled
16+
*
17+
* Represents a service message about a voice chat scheduled in the chat.
18+
*
19+
* @link https://core.telegram.org/bots/api#voicechatscheduled
20+
*
21+
* @method int getStartDate() Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator
22+
*/
23+
class VoiceChatScheduled extends Entity
24+
{
25+
26+
}

structure.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
4444
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location of the user',
4545
`query` TEXT NOT NULL COMMENT 'Text of the query',
4646
`offset` CHAR(255) NULL DEFAULT NULL COMMENT 'Offset of the result',
47+
`chat_type` CHAR(255) NULL DEFAULT NULL COMMENT 'Optional. Type of the chat, from which the inline query was sent.',
4748
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
4849

4950
PRIMARY KEY (`id`),
@@ -120,6 +121,7 @@ CREATE TABLE IF NOT EXISTS `message` (
120121
`connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',
121122
`passport_data` TEXT NULL COMMENT 'Telegram Passport data',
122123
`proximity_alert_triggered` TEXT NULL COMMENT 'Service message. A user in the chat triggered another user''s proximity alert while sharing Live Location.',
124+
`voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled',
123125
`voice_chat_started` TEXT COMMENT 'VoiceChatStarted object. Message is a service message: voice chat started',
124126
`voice_chat_ended` TEXT COMMENT 'VoiceChatEnded object. Message is a service message: voice chat ended',
125127
`voice_chat_participants_invited` TEXT COMMENT 'VoiceChatParticipantsInvited object. Message is a service message: new participants invited to a voice chat',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE `message` ADD COLUMN `voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled' AFTER `proximity_alert_triggered`;
2+
ALTER TABLE `inline_query` ADD COLUMN `chat_type` CHAR(255) NULL DEFAULT NULL COMMENT 'Optional. Type of the chat, from which the inline query was sent.' AFTER `offset`;

0 commit comments

Comments
 (0)