Skip to content

Add Bot API 5.2, Payments 2.0 and various fixes #1216

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

Merged
merged 1 commit into from
May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c

## [Unreleased]
### Notes
- [:ledger: View file changes][Unreleased]
- [:ledger: View file changes][Unreleased] ∙ [:page_with_curl: DB migration script][unreleased-sql-migration]
### Added
- Bot API 5.2 (Payments 2.0).
### Changed
### Deprecated
### Removed
Expand Down Expand Up @@ -513,6 +514,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.

[unreleased-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.72.0-unreleased.sql
[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
[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
[0.70.0-bc-minimum-php-73]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#minimum-php-73
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-5.1%20%28March%202021%29-32a2da.svg)](https://core.telegram.org/bots/api#march-9-2021)
[![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)
[![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 5.1 (March 2021).
- Supports all types and methods according to Telegram Bot API 5.2 (April 2021).
- 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 5.1 (March 2021).
All types are implemented according to Telegram API 5.2 (April 2021).

### Inline Query

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

### Methods

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

#### Send Message

Expand Down
18 changes: 16 additions & 2 deletions src/ChatAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,27 @@ class ChatAction

/**
* Record Audio chat action
*
* @deprecated Use ChatAction::RECORD_VOICE instead
*/
public const RECORD_AUDIO = 'record_audio';
public const RECORD_AUDIO = 'record_voice';

/**
* Record Voice chat action
*/
public const RECORD_VOICE = 'record_voice';

/**
* Upload Audio chat action
*
* @deprecated Use ChatAction::UPLOAD_VOICE instead
*/
public const UPLOAD_AUDIO = 'upload_voice';

/**
* Upload Voice chat action
*/
public const UPLOAD_AUDIO = 'upload_audio';
public const UPLOAD_VOICE = 'upload_voice';

/**
* Upload Document chat action
Expand Down
10 changes: 6 additions & 4 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ public static function insertInlineQueryRequest(InlineQuery $inline_query): bool
try {
$sth = self::$pdo->prepare('
INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
(`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
(`id`, `user_id`, `location`, `query`, `offset`, `chat_type`, `created_at`)
VALUES
(:id, :user_id, :location, :query, :offset, :created_at)
(:id, :user_id, :location, :query, :offset, :chat_type, :created_at)
');

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

return $sth->execute();
Expand Down Expand Up @@ -1065,7 +1066,7 @@ public static function insertMessageRequest(Message $message): bool
`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`, `connected_website`, `passport_data`, `proximity_alert_triggered`,
`voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
`voice_chat_scheduled`, `voice_chat_started`, `voice_chat_ended`, `voice_chat_participants_invited`, `reply_markup`
) VALUES (
:message_id, :user_id, :chat_id, :sender_chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_signature, :forward_sender_name, :forward_date,
Expand All @@ -1075,7 +1076,7 @@ public static function insertMessageRequest(Message $message): bool
: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, :connected_website, :passport_data, :proximity_alert_triggered,
:voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
:voice_chat_scheduled, :voice_chat_started, :voice_chat_ended, :voice_chat_participants_invited, :reply_markup
)
');

Expand Down Expand Up @@ -1148,6 +1149,7 @@ public static function insertMessageRequest(Message $message): bool
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
$sth->bindValue(':passport_data', $message->getPassportData());
$sth->bindValue(':proximity_alert_triggered', $message->getProximityAlertTriggered());
$sth->bindValue(':voice_chat_scheduled', $message->getVoiceChatScheduled());
$sth->bindValue(':voice_chat_started', $message->getVoiceChatStarted());
$sth->bindValue(':voice_chat_ended', $message->getVoiceChatEnded());
$sth->bindValue(':voice_chat_participants_invited', $message->getVoiceChatParticipantsInvited());
Expand Down
1 change: 1 addition & 0 deletions src/Entities/InlineQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @method Location getLocation() Optional. Sender location, only for bots that request user location
* @method string getQuery() Text of the query (up to 512 characters)
* @method string getOffset() Offset of the results to be returned, can be controlled by the bot
* @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
*/
class InlineQuery extends Entity
{
Expand Down
66 changes: 66 additions & 0 deletions src/Entities/InputMessageContent/InputInvoiceMessageContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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\InputMessageContent;

use Longman\TelegramBot\Entities\InlineQuery\InlineEntity;

/**
* Class InputTextMessageContent
*
* @link https://core.telegram.org/bots/api#inputinvoicemessagecontent
*
* @method string getTitle() Product name, 1-32 characters
* @method string getDescription() Product description, 1-255 characters
* @method string getPayload() Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
* @method string getProviderToken() Payment provider token, obtained via Botfather
* @method string getCurrency() Three-letter ISO 4217 currency code, see more on currencies
* @method LabeledPrice[] getPrices() Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
* @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
* @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.
* @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.
* @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.
* @method int getPhotoSize() Optional. Photo size
* @method int getPhotoWidth() Optional. Photo width
* @method int getPhotoHeight() Optional. Photo height
* @method bool getNeedName() Optional. Pass True, if you require the user's full name to complete the order
* @method bool getNeedPhoneNumber() Optional. Pass True, if you require the user's phone number to complete the order
* @method bool getNeedEmail() Optional. Pass True, if you require the user's email address to complete the order
* @method bool getNeedShippingAddress() Optional. Pass True, if you require the user's shipping address to complete the order
* @method bool getSendPhoneNumberToProvider() Optional. Pass True, if user's phone number should be sent to provider
* @method bool getSendEmailToProvider() Optional. Pass True, if user's email address should be sent to provider
* @method bool getIsFlexible() Optional. Pass True, if the final price depends on the shipping method
*
* @method $this setTitle(string $title) Product name, 1-32 characters
* @method $this setDescription(string $description) Product description, 1-255 characters
* @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.
* @method $this setProviderToken(string $provider_token) Payment provider token, obtained via Botfather
* @method $this setCurrency(string $currency) Three-letter ISO 4217 currency code, see more on currencies
* @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.)
* @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
* @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.
* @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.
* @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.
* @method $this setPhotoSize(int $photo_size) Optional. Photo size
* @method $this setPhotoWidth(int $photo_width) Optional. Photo width
* @method $this setPhotoHeight(int $photo_height) Optional. Photo height
* @method $this setNeedName(bool $need_name) Optional. Pass True, if you require the user's full name to complete the order
* @method $this setNeedPhoneNumber(bool $need_phone_number) Optional. Pass True, if you require the user's phone number to complete the order
* @method $this setNeedEmail(bool $need_email) Optional. Pass True, if you require the user's email address to complete the order
* @method $this setNeedShippingAddress(bool $need_shipping_address) Optional. Pass True, if you require the user's shipping address to complete the order
* @method $this setSendPhoneNumberToProvider(bool $send_phone_number_to_provider) Optional. Pass True, if user's phone number should be sent to provider
* @method $this setSendEmailToProvider(bool $send_email_to_provider) Optional. Pass True, if user's email address should be sent to provider
* @method $this setIsFlexible(bool $is_flexible) Optional. Pass True, if the final price depends on the shipping method
*/
class InputInvoiceMessageContent extends InlineEntity implements InputMessageContent
{

}
3 changes: 3 additions & 0 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* @method string getConnectedWebsite() Optional. The domain name of the website on which the user has logged in.
* @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 VoiceChatScheduled getVoiceChatScheduled() Optional. Service message: voice chat scheduled
* @method VoiceChatStarted getVoiceChatStarted() Optional. Service message: voice chat started
* @method VoiceChatEnded getVoiceChatEnded() Optional. Service message: voice chat ended
* @method VoiceChatParticipantsInvited getVoiceChatParticipantsInvited() Optional. Service message: new participants invited to a voice chat
Expand Down Expand Up @@ -118,6 +119,7 @@ protected function subEntities(): array
'successful_payment' => SuccessfulPayment::class,
'passport_data' => PassportData::class,
'proximity_alert_triggered' => ProximityAlertTriggered::class,
'voice_chat_scheduled' => VoiceChatScheduled::class,
'voice_chat_started' => VoiceChatStarted::class,
'voice_chat_ended' => VoiceChatEnded::class,
'voice_chat_participants_invited' => VoiceChatParticipantsInvited::class,
Expand Down Expand Up @@ -252,6 +254,7 @@ public function getType(): string
'successful_payment',
'passport_data',
'proximity_alert_triggered',
'voice_chat_scheduled',
'voice_chat_started',
'voice_chat_ended',
'voice_chat_participants_invited',
Expand Down
26 changes: 26 additions & 0 deletions src/Entities/VoiceChatScheduled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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;

/**
* Class VoiceChatScheduled
*
* Represents a service message about a voice chat scheduled in the chat.
*
* @link https://core.telegram.org/bots/api#voicechatscheduled
*
* @method int getStartDate() Point in time (Unix timestamp) when the voice chat is supposed to be started by a chat administrator
*/
class VoiceChatScheduled extends Entity
{

}
2 changes: 2 additions & 0 deletions structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
`location` CHAR(255) NULL DEFAULT NULL COMMENT 'Location of the user',
`query` TEXT NOT NULL COMMENT 'Text of the query',
`offset` CHAR(255) NULL DEFAULT NULL COMMENT 'Offset of the result',
`chat_type` CHAR(255) NULL DEFAULT NULL COMMENT 'Optional. Type of the chat, from which the inline query was sent.',
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',

PRIMARY KEY (`id`),
Expand Down Expand Up @@ -120,6 +121,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',
`passport_data` TEXT NULL COMMENT 'Telegram Passport data',
`proximity_alert_triggered` TEXT NULL COMMENT 'Service message. A user in the chat triggered another user''s proximity alert while sharing Live Location.',
`voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled',
`voice_chat_started` TEXT COMMENT 'VoiceChatStarted object. Message is a service message: voice chat started',
`voice_chat_ended` TEXT COMMENT 'VoiceChatEnded object. Message is a service message: voice chat ended',
`voice_chat_participants_invited` TEXT COMMENT 'VoiceChatParticipantsInvited object. Message is a service message: new participants invited to a voice chat',
Expand Down
2 changes: 2 additions & 0 deletions utils/db-schema-update/0.72.0-unreleased.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `message` ADD COLUMN `voice_chat_scheduled` TEXT COMMENT 'VoiceChatScheduled object. Message is a service message: voice chat scheduled' AFTER `proximity_alert_triggered`;
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`;