Unverified Commit ac4c5061 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #957 from noplanman/955-bot_api_4.3

API 4.3 - Seamless Telegram Login
parents 2e57ef04 d14fc93d
......@@ -7,6 +7,8 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Added
- New funding and support details.
- Custom issue templates. (#972)
- Bot API 4.3 (Seamless Telegram Login, `LoginUrl`)
- `reply_markup` field to `Message` entity.
### Changed
- Use PSR-12 for code style.
- Some general housekeeping. (#972)
......
......@@ -926,7 +926,7 @@ class DB
`location`, `venue`, `poll`, `new_chat_members`, `left_chat_member`,
`new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
`supergroup_chat_created`, `channel_chat_created`, `migrate_to_chat_id`, `migrate_from_chat_id`,
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`
`pinned_message`, `invoice`, `successful_payment`, `connected_website`, `passport_data`, `reply_markup`
) VALUES (
:message_id, :user_id, :chat_id, :date, :forward_from, :forward_from_chat, :forward_from_message_id,
:forward_signature, :forward_sender_name, :forward_date,
......@@ -935,7 +935,7 @@ class DB
:location, :venue, :poll, :new_chat_members, :left_chat_member,
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
:supergroup_chat_created, :channel_chat_created, :migrate_to_chat_id, :migrate_from_chat_id,
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data
:pinned_message, :invoice, :successful_payment, :connected_website, :passport_data, :reply_markup
)
');
......@@ -1007,6 +1007,7 @@ class DB
$sth->bindValue(':successful_payment', $message->getSuccessfulPayment());
$sth->bindValue(':connected_website', $message->getConnectedWebsite());
$sth->bindValue(':passport_data', $message->getPassportData());
$sth->bindValue(':reply_markup', $message->getReplyMarkup());
return $sth->execute();
} catch (PDOException $e) {
......
......@@ -20,6 +20,7 @@ use Longman\TelegramBot\Exception\TelegramException;
*
* @method string getText() Label text on the button
* @method string getUrl() Optional. HTTP url to be opened when button is pressed
* @method LoginUrl getLoginUrl() Optional. An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
* @method string getCallbackData() Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @method string getSwitchInlineQuery() Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
* @method string getSwitchInlineQueryCurrentChat() Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
......@@ -28,6 +29,7 @@ use Longman\TelegramBot\Exception\TelegramException;
*
* @method $this setText(string $text) Label text on the button
* @method $this setUrl(string $url) Optional. HTTP url to be opened when button is pressed
* @method $this setLoginUrl(LoginUrl $login_url) Optional. HTTP url to be opened when button is pressed
* @method $this setCallbackData(string $callback_data) Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
* @method $this setSwitchInlineQuery(string $switch_inline_query) Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
* @method $this setSwitchInlineQueryCurrentChat(string $switch_inline_query_current_chat) Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
......@@ -48,6 +50,7 @@ class InlineKeyboardButton extends KeyboardButton
return is_array($data) &&
array_key_exists('text', $data) && (
array_key_exists('url', $data) ||
array_key_exists('login_url', $data) ||
array_key_exists('callback_data', $data) ||
array_key_exists('switch_inline_query', $data) ||
array_key_exists('switch_inline_query_current_chat', $data) ||
......@@ -67,7 +70,7 @@ class InlineKeyboardButton extends KeyboardButton
$num_params = 0;
foreach (['url', 'callback_data', 'callback_game', 'pay'] as $param) {
foreach (['url', 'login_url', 'callback_data', 'callback_game', 'pay'] as $param) {
if ($this->getProperty($param, '') !== '') {
$num_params++;
}
......@@ -80,7 +83,7 @@ class InlineKeyboardButton extends KeyboardButton
}
if ($num_params !== 1) {
throw new TelegramException('You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!');
throw new TelegramException('You must use only one of these fields: url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!');
}
}
......@@ -90,8 +93,8 @@ class InlineKeyboardButton extends KeyboardButton
public function __call($method, $args)
{
// Only 1 of these can be set, so clear the others when setting a new one.
if (in_array($method, ['setUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
unset($this->url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
if (in_array($method, ['setUrl', 'setLoginUrl', 'setCallbackData', 'setSwitchInlineQuery', 'setSwitchInlineQueryCurrentChat', 'setCallbackGame', 'setPay'], true)) {
unset($this->url, $this->login_url, $this->callback_data, $this->switch_inline_query, $this->switch_inline_query_current_chat, $this->callback_game, $this->pay);
}
return parent::__call($method, $args);
......
<?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;
/**
* Class LoginUrl
*
* This object represents a parameter of the inline keyboard button used to automatically authorize a user.
*
* @link https://core.telegram.org/bots/api#loginurl
*
* @method string getUrl() An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data.
* @method string getForwardText() Optional. New text of the button in forwarded messages.
* @method string getBotUsername() Optional. Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the bot. See Linking your domain to the bot for more details.
* @method bool getRequestWriteAccess() Optional. Pass True to request the permission for your bot to send messages to the user.
*/
class LoginUrl extends Entity
{
}
......@@ -65,6 +65,7 @@ use Longman\TelegramBot\Entities\TelegramPassport\PassportData;
* @method SuccessfulPayment getSuccessfulPayment() Optional. Message is a service message about a successful payment, information about the payment.
* @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 InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.
*/
class Message extends Entity
{
......@@ -101,6 +102,7 @@ class Message extends Entity
'invoice' => Invoice::class,
'successful_payment' => SuccessfulPayment::class,
'passport_data' => PassportData::class,
'reply_markup' => InlineKeyboard::class,
];
}
......@@ -229,6 +231,7 @@ class Message extends Entity
'invoice',
'successful_payment',
'passport_data',
'reply_markup',
];
$is_command = strlen($this->getCommand()) > 0;
......
......@@ -115,6 +115,7 @@ CREATE TABLE IF NOT EXISTS `message` (
`successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment',
`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',
`reply_markup` TEXT NULL COMMENT 'Inline keyboard attached to the message',
PRIMARY KEY (`chat_id`, `id`),
KEY `user_id` (`user_id`),
......
......@@ -33,7 +33,7 @@ class InlineKeyboardButtonTest extends TestCase
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
* @expectedExceptionMessage You must use only one of these fields: url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
*/
public function testInlineKeyboardButtonNoParameterFail()
{
......@@ -42,7 +42,7 @@ class InlineKeyboardButtonTest extends TestCase
/**
* @expectedException \Longman\TelegramBot\Exception\TelegramException
* @expectedExceptionMessage You must use only one of these fields: url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
* @expectedExceptionMessage You must use only one of these fields: url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, pay!
*/
public function testInlineKeyboardButtonTooManyParametersFail()
{
......
ALTER TABLE `message` ADD COLUMN `reply_markup` TEXT NULL COMMENT 'Inline keyboard attached to the message' AFTER `passport_data`;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment