From b0b6c15d34443cf75275bb42430838ab1432b70f Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 17:52:47 +0300 Subject: [PATCH 01/10] Update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 30e3b31..e20bdad 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ /gradlew.bat /package-lock.php.yml /out/** -/dn-sources/** \ No newline at end of file +/dn-sources/** +.phpintel/** From fffac70aed4b652c2e9315c298b3bc336616953b Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 17:53:22 +0300 Subject: [PATCH 02/10] Read input data from error stream --- src/telegram/TelegramBotApi.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/telegram/TelegramBotApi.php b/src/telegram/TelegramBotApi.php index 6748bcf..9ef7464 100644 --- a/src/telegram/TelegramBotApi.php +++ b/src/telegram/TelegramBotApi.php @@ -196,10 +196,14 @@ function query($method, array $args = [], bool $multipart = false){ else{ $connection->getOutputStream()->write($this->json->format($args)); } + if($connection->responseCode != 200){ - throw new TelegramException("Server response invalid status code {$connection->responseCode}"); + $rawResponse = $connection->getErrorStream()->readFully(); + if(strlen($rawResponse) == 0) throw new TelegramException("Server response invalid status code {$connection->responseCode}"); + } else { + $rawResponse = $connection->getInputStream()->readFully(); } - $rawResponse = $connection->getInputStream()->readFully(); + $connection->disconnect(); $response = $this->json->parse($rawResponse); if(!$response->ok){ From a6003eda44a4ebb43a8af033c0c89e8c4fcfba10 Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 19:24:32 +0300 Subject: [PATCH 03/10] Reply markup features --- src/telegram/object/TMarkup.php | 38 +++++++ src/telegram/object/markup/AbstractMarkup.php | 13 +++ src/telegram/object/markup/TForceReply.php | 25 +++++ .../object/markup/TInlineKeyboard.php | 40 ++++++++ src/telegram/object/markup/TReplyKeyboard.php | 99 +++++++++++++++++++ .../object/markup/TReplyKeyboardRemove.php | 25 +++++ src/telegram/query/TSendMessageQuery.php | 22 ++++- 7 files changed, 258 insertions(+), 4 deletions(-) create mode 100644 src/telegram/object/TMarkup.php create mode 100644 src/telegram/object/markup/AbstractMarkup.php create mode 100644 src/telegram/object/markup/TForceReply.php create mode 100644 src/telegram/object/markup/TInlineKeyboard.php create mode 100644 src/telegram/object/markup/TReplyKeyboard.php create mode 100644 src/telegram/object/markup/TReplyKeyboardRemove.php diff --git a/src/telegram/object/TMarkup.php b/src/telegram/object/TMarkup.php new file mode 100644 index 0000000..3177605 --- /dev/null +++ b/src/telegram/object/TMarkup.php @@ -0,0 +1,38 @@ +markup; + } +} \ No newline at end of file diff --git a/src/telegram/object/markup/TForceReply.php b/src/telegram/object/markup/TForceReply.php new file mode 100644 index 0000000..6bdfe6c --- /dev/null +++ b/src/telegram/object/markup/TForceReply.php @@ -0,0 +1,25 @@ +markup['force_reply'] = true; + } + + /** + * --EN-- + * Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @param bool $value + */ + public function setSelective(bool $value){ + $this->markup['selective'] = $value; + return $this; + } +} \ No newline at end of file diff --git a/src/telegram/object/markup/TInlineKeyboard.php b/src/telegram/object/markup/TInlineKeyboard.php new file mode 100644 index 0000000..0a97b7a --- /dev/null +++ b/src/telegram/object/markup/TInlineKeyboard.php @@ -0,0 +1,40 @@ + $text]; + + if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0){ + $btn['url'] = $data; + } else { + $btn['callback_data'] = $data; + } + + $this->buttons[$this->row][] = $btn; + + return $this; + } + + public function getMarkup(): array { + $markup = $this->params; + $markup['inline_keyboard'] = $this->buttons; + + return $markup; + } +} \ No newline at end of file diff --git a/src/telegram/object/markup/TReplyKeyboard.php b/src/telegram/object/markup/TReplyKeyboard.php new file mode 100644 index 0000000..cabbd77 --- /dev/null +++ b/src/telegram/object/markup/TReplyKeyboard.php @@ -0,0 +1,99 @@ +params = $params; + $this->row(); + } + + /** + * Добавить новую строку в панель кнопок + * @return TReplyKeyboard + */ + public function row(){ + $this->row++; + if(!isset($this->buttons[$this->row])) $this->buttons[$this->row] = []; + + return $this; + } + + /** + * Добавить кнопку + * @param string $text Текст кнопки + * @return TReplyKeyboard + */ + public function button(string $text){ + $this->buttons[$this->row][] = ['text' => $text]; + + return $this; + } + + /** + * Указывает клиенту подогнать высоту клавиатуры под количество кнопок + * (сделать её меньше, если кнопок мало и наоборот) + * @param bool $value + * @return TReplyKeyboard + */ + public function setResize(bool $value){ + $this->params['resize_keyboard'] = $value; + return $this; + } + + /** + * Указывает клиенту скрыть клавиатуру после использования (после нажатия на кнопку). + * Её по-прежнему можно будет открыть через иконку в поле ввода сообщения. + * @param bool $value + * @return TReplyKeyboard + */ + public function setOneTime(bool $value){ + $this->params['one_time_keyboard'] = $value; + return $this; + } + + /** + * @param bool $value + * @return TReplyKeyboard + */ + public function setSelective(bool $value){ + $this->params['selective'] = $value; + return $this; + } + + /** + * @return array + */ + public function getMarkup(): array { + $markup = $this->params; + $markup['keyboard'] = $this->buttons; + + return $markup; + } +} \ No newline at end of file diff --git a/src/telegram/object/markup/TReplyKeyboardRemove.php b/src/telegram/object/markup/TReplyKeyboardRemove.php new file mode 100644 index 0000000..17f61dd --- /dev/null +++ b/src/telegram/object/markup/TReplyKeyboardRemove.php @@ -0,0 +1,25 @@ +markup['remove_keyboard'] = true; + } + + /** + * --EN-- + * Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @param bool $value + */ + public function setSelective(bool $value){ + $this->markup['selective'] = $value; + return $this; + } +} \ No newline at end of file diff --git a/src/telegram/query/TSendMessageQuery.php b/src/telegram/query/TSendMessageQuery.php index 6b7769b..acf2e4d 100644 --- a/src/telegram/query/TSendMessageQuery.php +++ b/src/telegram/query/TSendMessageQuery.php @@ -4,8 +4,10 @@ namespace telegram\query; -use telegram\object\TMessage; use telegram\TelegramBotApi; +use telegram\exception\TelegramException; +use telegram\object\TMessage; +use telegram\object\markup\AbstractMarkup; class TSendMessageQuery extends TBaseQuery{ public function __construct(TelegramBotApi $api){ @@ -47,11 +49,23 @@ public function disable_notification($value){ public function reply_to_message_id($value){ return $this->put(__FUNCTION__, (int)$value); } - /* + + /** + * @param array|TAbstractMarkup + * @return TSendMessageQuery + */ public function reply_markup($value){ - return $this->put(__FUNCTION__, $value); + if(is_array($value)){ + return $this->put(__FUNCTION__, $value); + } + elseif($value instanceof AbstractMarkup){ + return $this->put(__FUNCTION__, $value->getMarkup()); + } + else { + throw new TelegramException('Invalid reply_markup parameter'); + } } - */ + /** * @return TMessage */ From f368bc3f9b2e015e422a6a9988c063cc5a4ac050 Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 19:51:58 +0300 Subject: [PATCH 04/10] Update TInlineKeyboard.php --- .../object/markup/TInlineKeyboard.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/telegram/object/markup/TInlineKeyboard.php b/src/telegram/object/markup/TInlineKeyboard.php index 0a97b7a..bd6237a 100644 --- a/src/telegram/object/markup/TInlineKeyboard.php +++ b/src/telegram/object/markup/TInlineKeyboard.php @@ -1,6 +1,8 @@ $text]; - if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0){ + if(func_num_args() < 2){ + throw new TelegramException('Parameter callback_data required for InlineKeyboard buttons'); + } else { + $data = func_get_arg(1); + } + + if(!is_string($data)){ + throw new TelegramException('Parameter callback_data should be a string'); + } + + if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0 || strpos($data, 'tg:') === 0){ $btn['url'] = $data; } else { + if(strlen($data) > self::MAX_CBDATA_LENGTH){ + throw new TelegramException('Parameter callback_data should be a string no more than ' . MAX_CBDATA_LENGTH . ' bytes in size'); + } + $btn['callback_data'] = $data; } From 246177940b673f2c9f5564e9c0da904d194bf97e Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 19:52:23 +0300 Subject: [PATCH 05/10] Method answerCallbackQuery --- src/telegram/TelegramBotApi.php | 8 +++ src/telegram/query/TAnswerCallbackQuery.php | 78 +++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/telegram/query/TAnswerCallbackQuery.php diff --git a/src/telegram/TelegramBotApi.php b/src/telegram/TelegramBotApi.php index 9ef7464..c1f9e31 100644 --- a/src/telegram/TelegramBotApi.php +++ b/src/telegram/TelegramBotApi.php @@ -17,6 +17,7 @@ use php\net\URLConnection; use telegram\exception\TelegramError; use telegram\exception\TelegramException; +use telegram\query\TAnswerCallbackQuery; use telegram\query\TForwardMessageQuery; use telegram\query\TGetFileQuery; use telegram\query\TGetMeQuery; @@ -163,6 +164,13 @@ function getUpdates(){ return new TGetUpdatesQuery($this); } + /** + * @return TAnswerCallbackQuery + */ + function answerCallbackQuery(){ + return new TAnswerCallbackQuery($this); + } + function setProxy(?Proxy $proxy){ $this->proxy = $proxy; diff --git a/src/telegram/query/TAnswerCallbackQuery.php b/src/telegram/query/TAnswerCallbackQuery.php new file mode 100644 index 0000000..d9803a0 --- /dev/null +++ b/src/telegram/query/TAnswerCallbackQuery.php @@ -0,0 +1,78 @@ +put(__FUNCTION__, $value); + } + + /** + * --EN-- + * Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function text(string $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * URL that will be opened by the user's client. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function url(string $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function show_alert(bool $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function cache_time(int $value){ + return $this->put(__FUNCTION__, $value); + } +} \ No newline at end of file From 43ef09720d5facbbbd1ad379fb32c1710f29014c Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 19:52:40 +0300 Subject: [PATCH 06/10] Version 1.1 --- package.php.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.php.yml b/package.php.yml index 53d6076..30d712e 100644 --- a/package.php.yml +++ b/package.php.yml @@ -1,5 +1,5 @@ name: telegram-bot-api -version: 1.0.0 +version: 1.1.0 deps: jphp-core: '*' jphp-json-ext: '*' @@ -19,6 +19,7 @@ config: - /.idea/** - /*.iml - /.git/** + - /.phpintel/** - /package.hub.yml - /bundle/** - /src-bundle/** From 003be0186a9ee79f5094578f3d5127fd46153c00 Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 20:02:30 +0300 Subject: [PATCH 07/10] Update README.MD --- README.MD | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/README.MD b/README.MD index 8ed9ec2..fcc5adc 100644 --- a/README.MD +++ b/README.MD @@ -41,6 +41,73 @@ $listener->addListener(function($update){ }); $listener->start(); ``` +### Использование клавиатуры +#### Клавиатура под полем ввода (ReplyKeyboard) +![ReplyKeyboard](https://sun9-45.userapi.com/c205624/v205624150/12151/u119tArN_LE.jpg) +```php +$api = new TelegramBotApi($bot_token); + +$keyboard = TMarkup::replyKeyboard() + ->button('Button 1')->button('Button 2') + ->row() + ->button('Row 2')->button('Hello world')->button('test 123') + ->row() + ->button('Button in row 3'); + +$api->sendMessage() + ->chat_id(123456) + ->text('Hello world') + ->reply_markup($keyboard) + ->query(); +``` + +#### Удаление клавиатуры под полем ввода (ReplyKeyboard) +```php +$api = new TelegramBotApi($bot_token); + +$hideKeyboard = TMarkup::removeKeyboard(); + +$api->sendMessage() + ->chat_id(123456) + ->text('Hello world') + ->reply_markup($hideKeyboard) + ->query(); +``` + +#### Клавиатура под сообщением (InlineKeyboard) +![InlineKeyboard](https://sun9-59.userapi.com/c205624/v205624829/11e6f/itNoz8qnyFE.jpg) +```php +$api = new TelegramBotApi($bot_token); + +// Обязательно вторым аргументом у button указывать данные для callback_data или url-ссылку +$keyboard = TMarkup::inlineKeyboard() + ->button('Button with callback', 'press_1')->button('Button 2', 'press_2') + ->row() + ->button('Link to google', 'https://google.com')->button('Link to git', 'http://github.com') + ->row() + ->button('1', 'btn_1')->button('2', 'btn_2')->button('3', 'btn_3')->button('4', 'btn_4')->button('5', 'btn_5')->button('6', 'btn_6')->button('7', 'btn_7')->button('8', 'btn_8'); + +$api->sendMessage() + ->chat_id(123456) + ->text('Hello world') + ->reply_markup($keyboard) + ->query(); +``` + +#### Ответ на сообщение (ForceReply) +![ForceReply](https://sun9-23.userapi.com/c205624/v205624829/11e98/pyW0VWHtPJ0.jpg) +```php +$api = new TelegramBotApi($bot_token); + +$reply = TMarkup::forceReply(); + +$api->sendMessage() + ->chat_id(123456) + ->text('Hello world') + ->reply_markup($reply) + ->query(); +``` + ## Расширение для DevelNext [Скачать](https://github.com/broelik/jphp-telegram-bot-api/releases/latest) From 7b038b02453690f82e03f2dfbf8dbaa278eca89d Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 20:12:19 +0300 Subject: [PATCH 08/10] api-docs --- api-docs/README.md | 14 ++- api-docs/classes/telegram/TelegramBotApi.md | 10 ++ api-docs/classes/telegram/object/TMarkup.md | 50 +++++++++ .../telegram/object/markup/AbstractMarkup.md | 30 +++++ .../telegram/object/markup/TForceReply.md | 36 ++++++ .../telegram/object/markup/TInlineKeyboard.md | 37 ++++++ .../telegram/object/markup/TReplyKeyboard.md | 105 ++++++++++++++++++ .../object/markup/TReplyKeyboardRemove.md | 36 ++++++ .../telegram/query/TAnswerCallbackQuery.md | 81 ++++++++++++++ api-docs/classes/telegram/query/TBaseQuery.md | 2 +- .../telegram/query/TSendMessageQuery.md | 10 ++ 11 files changed, 408 insertions(+), 3 deletions(-) create mode 100644 api-docs/classes/telegram/object/TMarkup.md create mode 100644 api-docs/classes/telegram/object/markup/AbstractMarkup.md create mode 100644 api-docs/classes/telegram/object/markup/TForceReply.md create mode 100644 api-docs/classes/telegram/object/markup/TInlineKeyboard.md create mode 100644 api-docs/classes/telegram/object/markup/TReplyKeyboard.md create mode 100644 api-docs/classes/telegram/object/markup/TReplyKeyboardRemove.md create mode 100644 api-docs/classes/telegram/query/TAnswerCallbackQuery.md diff --git a/api-docs/README.md b/api-docs/README.md index ab70d44..c7c8ba1 100644 --- a/api-docs/README.md +++ b/api-docs/README.md @@ -1,10 +1,10 @@ ## telegram-bot-api -> version 1.0.0, created by JPPM. +> version 1.1.0, created by JPPM. ### Install ``` -jppm add telegram-bot-api@1.0.0 +jppm add telegram-bot-api@1.1.0 ``` ### API @@ -15,6 +15,14 @@ jppm add telegram-bot-api@1.0.0 - [`TelegramError`](classes/telegram/exception/TelegramError.md) - [`TelegramException`](classes/telegram/exception/TelegramException.md) +#### `telegram\object\markup` + +- [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md) +- [`TForceReply`](classes/telegram/object/markup/TForceReply.md)- _Shows reply interface to the user, as if they manually selected the bot‘s message and tapped 'Reply'_ +- [`TInlineKeyboard`](classes/telegram/object/markup/TInlineKeyboard.md)- _This object represents an inline keyboard that appears right next to the message it belongs to._ +- [`TReplyKeyboard`](classes/telegram/object/markup/TReplyKeyboard.md)- _This object represents a custom keyboard with reply options_ +- [`TReplyKeyboardRemove`](classes/telegram/object/markup/TReplyKeyboardRemove.md)- _Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button_ + #### `telegram\object` - [`TAudio`](classes/telegram/object/TAudio.md) @@ -23,6 +31,7 @@ jppm add telegram-bot-api@1.0.0 - [`TDocument`](classes/telegram/object/TDocument.md) - [`TFile`](classes/telegram/object/TFile.md) - [`TLocation`](classes/telegram/object/TLocation.md) +- [`TMarkup`](classes/telegram/object/TMarkup.md) - [`TMessage`](classes/telegram/object/TMessage.md) - [`TMessageEntity`](classes/telegram/object/TMessageEntity.md) - [`TPhotoSize`](classes/telegram/object/TPhotoSize.md) @@ -36,6 +45,7 @@ jppm add telegram-bot-api@1.0.0 #### `telegram\query` +- [`TAnswerCallbackQuery`](classes/telegram/query/TAnswerCallbackQuery.md)- _Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned._ - [`TBaseQuery`](classes/telegram/query/TBaseQuery.md) - [`TEditMessageTextQuery`](classes/telegram/query/TEditMessageTextQuery.md) - [`TForwardMessageQuery`](classes/telegram/query/TForwardMessageQuery.md) diff --git a/api-docs/classes/telegram/TelegramBotApi.md b/api-docs/classes/telegram/TelegramBotApi.md index c7a4705..10a9a95 100644 --- a/api-docs/classes/telegram/TelegramBotApi.md +++ b/api-docs/classes/telegram/TelegramBotApi.md @@ -35,6 +35,7 @@ - `->`[`kickChatMember()`](#method-kickchatmember) - `->`[`unbanChatMember()`](#method-unbanchatmember) - `->`[`getUpdates()`](#method-getupdates) +- `->`[`answerCallbackQuery()`](#method-answercallbackquery) - `->`[`setProxy()`](#method-setproxy) - `->`[`getProxy()`](#method-getproxy) - `->`[`setToken()`](#method-settoken) @@ -217,6 +218,15 @@ getUpdates(): TGetUpdatesQuery --- + + +### answerCallbackQuery() +```php +answerCallbackQuery(): TAnswerCallbackQuery +``` + +--- + ### setProxy() diff --git a/api-docs/classes/telegram/object/TMarkup.md b/api-docs/classes/telegram/object/TMarkup.md new file mode 100644 index 0000000..c3c9e93 --- /dev/null +++ b/api-docs/classes/telegram/object/TMarkup.md @@ -0,0 +1,50 @@ +# TMarkup + +- **class** `TMarkup` (`telegram\object\TMarkup`) +- **source** `telegram/object/TMarkup.php` + +--- + +#### Static Methods + +- `TMarkup ::`[`replyKeyboard()`](#method-replykeyboard) +- `TMarkup ::`[`inlineKeyboard()`](#method-inlinekeyboard) +- `TMarkup ::`[`forceReply()`](#method-forcereply) +- `TMarkup ::`[`removeKeyboard()`](#method-removekeyboard) + +--- +# Static Methods + + + +### replyKeyboard() +```php +TMarkup::replyKeyboard(): TReplyKeyboard +``` + +--- + + + +### inlineKeyboard() +```php +TMarkup::inlineKeyboard(): TInlineKeyboard +``` + +--- + + + +### forceReply() +```php +TMarkup::forceReply(): TForceReply +``` + +--- + + + +### removeKeyboard() +```php +TMarkup::removeKeyboard(): TReplyKeyboardRemove +``` \ No newline at end of file diff --git a/api-docs/classes/telegram/object/markup/AbstractMarkup.md b/api-docs/classes/telegram/object/markup/AbstractMarkup.md new file mode 100644 index 0000000..511a75f --- /dev/null +++ b/api-docs/classes/telegram/object/markup/AbstractMarkup.md @@ -0,0 +1,30 @@ +# AbstractMarkup + +- **class** `AbstractMarkup` (`telegram\object\markup\AbstractMarkup`) +- **source** `telegram/object/markup/AbstractMarkup.php` + +**Child Classes** + +> [TForceReply](classes/telegram/object/markup/TForceReply.md), [TReplyKeyboard](classes/telegram/object/markup/TReplyKeyboard.md), [TReplyKeyboardRemove](classes/telegram/object/markup/TReplyKeyboardRemove.md) + +--- + +#### Properties + +- `->`[`markup`](#prop-markup) : `array` + +--- + +#### Methods + +- `->`[`getMarkup()`](#method-getmarkup) + +--- +# Methods + + + +### getMarkup() +```php +getMarkup(): array +``` \ No newline at end of file diff --git a/api-docs/classes/telegram/object/markup/TForceReply.md b/api-docs/classes/telegram/object/markup/TForceReply.md new file mode 100644 index 0000000..0445e9e --- /dev/null +++ b/api-docs/classes/telegram/object/markup/TForceReply.md @@ -0,0 +1,36 @@ +# TForceReply + +- **class** `TForceReply` (`telegram\object\markup\TForceReply`) **extends** [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md) +- **source** `telegram/object/markup/TForceReply.php` + +**Description** + +Shows reply interface to the user, as if they manually selected the bot‘s message and tapped 'Reply' + +--- + +#### Methods + +- `->`[`__construct()`](#method-__construct) +- `->`[`setSelective()`](#method-setselective) - _Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message._ +- See also in the parent class [AbstractMarkup](classes/telegram/object/markup/AbstractMarkup.md) + +--- +# Methods + + + +### __construct() +```php +__construct(): void +``` + +--- + + + +### setSelective() +```php +setSelective(bool $value): void +``` +Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. \ No newline at end of file diff --git a/api-docs/classes/telegram/object/markup/TInlineKeyboard.md b/api-docs/classes/telegram/object/markup/TInlineKeyboard.md new file mode 100644 index 0000000..4d675d5 --- /dev/null +++ b/api-docs/classes/telegram/object/markup/TInlineKeyboard.md @@ -0,0 +1,37 @@ +# TInlineKeyboard + +- **class** `TInlineKeyboard` (`telegram\object\markup\TInlineKeyboard`) **extends** [`TReplyKeyboard`](classes/telegram/object/markup/TReplyKeyboard.md) +- **source** `telegram/object/markup/TInlineKeyboard.php` + +**Description** + +This object represents an inline keyboard that appears right next to the message it belongs to. + + +--- + +#### Methods + +- `->`[`button()`](#method-button) - _Добавить кнопку_ +- `->`[`getMarkup()`](#method-getmarkup) +- See also in the parent class [TReplyKeyboard](classes/telegram/object/markup/TReplyKeyboard.md) + +--- +# Methods + + + +### button() +```php +button(string $text): TInlineKeyboard +``` +Добавить кнопку + +--- + + + +### getMarkup() +```php +getMarkup(): array +``` \ No newline at end of file diff --git a/api-docs/classes/telegram/object/markup/TReplyKeyboard.md b/api-docs/classes/telegram/object/markup/TReplyKeyboard.md new file mode 100644 index 0000000..edbeaa6 --- /dev/null +++ b/api-docs/classes/telegram/object/markup/TReplyKeyboard.md @@ -0,0 +1,105 @@ +# TReplyKeyboard + +- **class** `TReplyKeyboard` (`telegram\object\markup\TReplyKeyboard`) **extends** [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md) +- **source** `telegram/object/markup/TReplyKeyboard.php` + +**Child Classes** + +> [TInlineKeyboard](classes/telegram/object/markup/TInlineKeyboard.md) + +**Description** + +This object represents a custom keyboard with reply options + + +--- + +#### Properties + +- `->`[`params`](#prop-params) : `array` +- `->`[`buttons`](#prop-buttons) : `array` - _Кнопки_ +- `->`[`row`](#prop-row) : `int` - _Указатель текущей строки в кнопках_ +- *See also in the parent class* [AbstractMarkup](classes/telegram/object/markup/AbstractMarkup.md). + +--- + +#### Methods + +- `->`[`__construct()`](#method-__construct) +- `->`[`row()`](#method-row) - _Добавить новую строку в панель кнопок_ +- `->`[`button()`](#method-button) - _Добавить кнопку_ +- `->`[`setResize()`](#method-setresize) - _Указывает клиенту подогнать высоту клавиатуры под количество кнопок_ +- `->`[`setOneTime()`](#method-setonetime) - _Указывает клиенту скрыть клавиатуру после использования (после нажатия на кнопку)._ +- `->`[`setSelective()`](#method-setselective) +- `->`[`getMarkup()`](#method-getmarkup) +- See also in the parent class [AbstractMarkup](classes/telegram/object/markup/AbstractMarkup.md) + +--- +# Methods + + + +### __construct() +```php +__construct(array $params): void +``` + +--- + + + +### row() +```php +row(): TReplyKeyboard +``` +Добавить новую строку в панель кнопок + +--- + + + +### button() +```php +button(string $text): TReplyKeyboard +``` +Добавить кнопку + +--- + + + +### setResize() +```php +setResize(bool $value): TReplyKeyboard +``` +Указывает клиенту подогнать высоту клавиатуры под количество кнопок +(сделать её меньше, если кнопок мало и наоборот) + +--- + + + +### setOneTime() +```php +setOneTime(bool $value): TReplyKeyboard +``` +Указывает клиенту скрыть клавиатуру после использования (после нажатия на кнопку). +Её по-прежнему можно будет открыть через иконку в поле ввода сообщения. + +--- + + + +### setSelective() +```php +setSelective(bool $value): TReplyKeyboard +``` + +--- + + + +### getMarkup() +```php +getMarkup(): array +``` \ No newline at end of file diff --git a/api-docs/classes/telegram/object/markup/TReplyKeyboardRemove.md b/api-docs/classes/telegram/object/markup/TReplyKeyboardRemove.md new file mode 100644 index 0000000..0f0e997 --- /dev/null +++ b/api-docs/classes/telegram/object/markup/TReplyKeyboardRemove.md @@ -0,0 +1,36 @@ +# TReplyKeyboardRemove + +- **class** `TReplyKeyboardRemove` (`telegram\object\markup\TReplyKeyboardRemove`) **extends** [`AbstractMarkup`](classes/telegram/object/markup/AbstractMarkup.md) +- **source** `telegram/object/markup/TReplyKeyboardRemove.php` + +**Description** + +Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button + +--- + +#### Methods + +- `->`[`__construct()`](#method-__construct) +- `->`[`setSelective()`](#method-setselective) - _Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message._ +- See also in the parent class [AbstractMarkup](classes/telegram/object/markup/AbstractMarkup.md) + +--- +# Methods + + + +### __construct() +```php +__construct(): void +``` + +--- + + + +### setSelective() +```php +setSelective(bool $value): void +``` +Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. \ No newline at end of file diff --git a/api-docs/classes/telegram/query/TAnswerCallbackQuery.md b/api-docs/classes/telegram/query/TAnswerCallbackQuery.md new file mode 100644 index 0000000..5bdd160 --- /dev/null +++ b/api-docs/classes/telegram/query/TAnswerCallbackQuery.md @@ -0,0 +1,81 @@ +# TAnswerCallbackQuery + +- **class** `TAnswerCallbackQuery` (`telegram\query\TAnswerCallbackQuery`) **extends** [`TBaseQuery`](classes/telegram/query/TBaseQuery.md) +- **source** `telegram/query/TAnswerCallbackQuery.php` + +**Description** + +Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. + + +--- + +#### Methods + +- `->`[`__construct()`](#method-__construct) +- `->`[`callback_query_id()`](#method-callback_query_id) - _Unique identifier for the query to be answered_ +- `->`[`text()`](#method-text) - _Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters_ +- `->`[`url()`](#method-url) - _URL that will be opened by the user's client._ +- `->`[`show_alert()`](#method-show_alert) - _If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false._ +- `->`[`cache_time()`](#method-cache_time) - _The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0._ +- See also in the parent class [TBaseQuery](classes/telegram/query/TBaseQuery.md) + +--- +# Methods + + + +### __construct() +```php +__construct(telegram\TelegramBotApi $api): void +``` + +--- + + + +### callback_query_id() +```php +callback_query_id(string $value): TAnswerCallbackQuery +``` +Unique identifier for the query to be answered + +--- + + + +### text() +```php +text(string $value): TAnswerCallbackQuery +``` +Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + +--- + + + +### url() +```php +url(string $value): TAnswerCallbackQuery +``` +URL that will be opened by the user's client. + +--- + + + +### show_alert() +```php +show_alert(string $value): TAnswerCallbackQuery +``` +If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + +--- + + + +### cache_time() +```php +cache_time(string $value): TAnswerCallbackQuery +``` +The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. \ No newline at end of file diff --git a/api-docs/classes/telegram/query/TBaseQuery.md b/api-docs/classes/telegram/query/TBaseQuery.md index 42ada27..e9b26a9 100644 --- a/api-docs/classes/telegram/query/TBaseQuery.md +++ b/api-docs/classes/telegram/query/TBaseQuery.md @@ -5,7 +5,7 @@ **Child Classes** -> [TEditMessageTextQuery](classes/telegram/query/TEditMessageTextQuery.md), [TForwardMessageQuery](classes/telegram/query/TForwardMessageQuery.md), [TGetFileQuery](classes/telegram/query/TGetFileQuery.md), [TGetMeQuery](classes/telegram/query/TGetMeQuery.md), [TGetUpdatesQuery](classes/telegram/query/TGetUpdatesQuery.md), [TGetUserProfilePhotosQuery](classes/telegram/query/TGetUserProfilePhotosQuery.md), [TKickChatMemberQuery](classes/telegram/query/TKickChatMemberQuery.md), [TSendAudioQuery](classes/telegram/query/TSendAudioQuery.md), [TSendChatActionQuery](classes/telegram/query/TSendChatActionQuery.md), [TSendContactQuery](classes/telegram/query/TSendContactQuery.md), [TSendDocumentQuery](classes/telegram/query/TSendDocumentQuery.md), [TSendLocationQuery](classes/telegram/query/TSendLocationQuery.md), [TSendMessageQuery](classes/telegram/query/TSendMessageQuery.md), [TSendPhotoQuery](classes/telegram/query/TSendPhotoQuery.md), [TSendStickerQuery](classes/telegram/query/TSendStickerQuery.md), [TSendVenueQuery](classes/telegram/query/TSendVenueQuery.md), [TSendVideoQuery](classes/telegram/query/TSendVideoQuery.md), [TSendVoiceQuery](classes/telegram/query/TSendVoiceQuery.md), [TUnbanChatMemberQuery](classes/telegram/query/TUnbanChatMemberQuery.md) +> [TAnswerCallbackQuery](classes/telegram/query/TAnswerCallbackQuery.md), [TEditMessageTextQuery](classes/telegram/query/TEditMessageTextQuery.md), [TForwardMessageQuery](classes/telegram/query/TForwardMessageQuery.md), [TGetFileQuery](classes/telegram/query/TGetFileQuery.md), [TGetMeQuery](classes/telegram/query/TGetMeQuery.md), [TGetUpdatesQuery](classes/telegram/query/TGetUpdatesQuery.md), [TGetUserProfilePhotosQuery](classes/telegram/query/TGetUserProfilePhotosQuery.md), [TKickChatMemberQuery](classes/telegram/query/TKickChatMemberQuery.md), [TSendAudioQuery](classes/telegram/query/TSendAudioQuery.md), [TSendChatActionQuery](classes/telegram/query/TSendChatActionQuery.md), [TSendContactQuery](classes/telegram/query/TSendContactQuery.md), [TSendDocumentQuery](classes/telegram/query/TSendDocumentQuery.md), [TSendLocationQuery](classes/telegram/query/TSendLocationQuery.md), [TSendMessageQuery](classes/telegram/query/TSendMessageQuery.md), [TSendPhotoQuery](classes/telegram/query/TSendPhotoQuery.md), [TSendStickerQuery](classes/telegram/query/TSendStickerQuery.md), [TSendVenueQuery](classes/telegram/query/TSendVenueQuery.md), [TSendVideoQuery](classes/telegram/query/TSendVideoQuery.md), [TSendVoiceQuery](classes/telegram/query/TSendVoiceQuery.md), [TUnbanChatMemberQuery](classes/telegram/query/TUnbanChatMemberQuery.md) --- diff --git a/api-docs/classes/telegram/query/TSendMessageQuery.md b/api-docs/classes/telegram/query/TSendMessageQuery.md index 94f2212..0055850 100644 --- a/api-docs/classes/telegram/query/TSendMessageQuery.md +++ b/api-docs/classes/telegram/query/TSendMessageQuery.md @@ -14,6 +14,7 @@ - `->`[`disable_web_page_preview()`](#method-disable_web_page_preview) - `->`[`disable_notification()`](#method-disable_notification) - `->`[`reply_to_message_id()`](#method-reply_to_message_id) +- `->`[`reply_markup()`](#method-reply_markup) - `->`[`query()`](#method-query) - See also in the parent class [TBaseQuery](classes/telegram/query/TBaseQuery.md) @@ -83,6 +84,15 @@ reply_to_message_id(mixed $value): TSendMessageQuery --- + + +### reply_markup() +```php +reply_markup(mixed $value): TSendMessageQuery +``` + +--- + ### query() From 7a1f346563e1cdc48893bbf4d19575012ed29fa8 Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 20:21:54 +0300 Subject: [PATCH 09/10] apply changes to develnext-bundle --- package.php.yml | 2 +- .../telegram/TelegramBotApi.php | 16 ++- .../telegram/object/TMarkup.php | 38 +++++++ .../telegram/object/markup/AbstractMarkup.php | 13 +++ .../telegram/object/markup/TForceReply.php | 25 +++++ .../object/markup/TInlineKeyboard.php | 61 ++++++++++++ .../telegram/object/markup/TReplyKeyboard.php | 99 +++++++++++++++++++ .../object/markup/TReplyKeyboardRemove.php | 25 +++++ .../telegram/query/TAnswerCallbackQuery.php | 78 +++++++++++++++ .../telegram/query/TSendMessageQuery.php | 22 ++++- 10 files changed, 372 insertions(+), 7 deletions(-) create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/TMarkup.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/AbstractMarkup.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TForceReply.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TInlineKeyboard.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboard.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboardRemove.php create mode 100644 src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TAnswerCallbackQuery.php diff --git a/package.php.yml b/package.php.yml index 30d712e..d0516c4 100644 --- a/package.php.yml +++ b/package.php.yml @@ -33,7 +33,7 @@ config: - /LICENSE develnext-bundle: - version: 1.0.0 + version: 1.1.0 name: Telegram Bot API author: broelik icon: "develnext/bundle/telegram/icon32.png" diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/TelegramBotApi.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/TelegramBotApi.php index 6748bcf..c1f9e31 100644 --- a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/TelegramBotApi.php +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/TelegramBotApi.php @@ -17,6 +17,7 @@ use php\net\URLConnection; use telegram\exception\TelegramError; use telegram\exception\TelegramException; +use telegram\query\TAnswerCallbackQuery; use telegram\query\TForwardMessageQuery; use telegram\query\TGetFileQuery; use telegram\query\TGetMeQuery; @@ -163,6 +164,13 @@ function getUpdates(){ return new TGetUpdatesQuery($this); } + /** + * @return TAnswerCallbackQuery + */ + function answerCallbackQuery(){ + return new TAnswerCallbackQuery($this); + } + function setProxy(?Proxy $proxy){ $this->proxy = $proxy; @@ -196,10 +204,14 @@ function query($method, array $args = [], bool $multipart = false){ else{ $connection->getOutputStream()->write($this->json->format($args)); } + if($connection->responseCode != 200){ - throw new TelegramException("Server response invalid status code {$connection->responseCode}"); + $rawResponse = $connection->getErrorStream()->readFully(); + if(strlen($rawResponse) == 0) throw new TelegramException("Server response invalid status code {$connection->responseCode}"); + } else { + $rawResponse = $connection->getInputStream()->readFully(); } - $rawResponse = $connection->getInputStream()->readFully(); + $connection->disconnect(); $response = $this->json->parse($rawResponse); if(!$response->ok){ diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/TMarkup.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/TMarkup.php new file mode 100644 index 0000000..3177605 --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/TMarkup.php @@ -0,0 +1,38 @@ +markup; + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TForceReply.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TForceReply.php new file mode 100644 index 0000000..6bdfe6c --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TForceReply.php @@ -0,0 +1,25 @@ +markup['force_reply'] = true; + } + + /** + * --EN-- + * Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @param bool $value + */ + public function setSelective(bool $value){ + $this->markup['selective'] = $value; + return $this; + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TInlineKeyboard.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TInlineKeyboard.php new file mode 100644 index 0000000..bd6237a --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TInlineKeyboard.php @@ -0,0 +1,61 @@ + $text]; + + if(func_num_args() < 2){ + throw new TelegramException('Parameter callback_data required for InlineKeyboard buttons'); + } else { + $data = func_get_arg(1); + } + + if(!is_string($data)){ + throw new TelegramException('Parameter callback_data should be a string'); + } + + if(strpos($data, 'http:') === 0 || strpos($data, 'https:') === 0 || strpos($data, 'tg:') === 0){ + $btn['url'] = $data; + } else { + if(strlen($data) > self::MAX_CBDATA_LENGTH){ + throw new TelegramException('Parameter callback_data should be a string no more than ' . MAX_CBDATA_LENGTH . ' bytes in size'); + } + + $btn['callback_data'] = $data; + } + + $this->buttons[$this->row][] = $btn; + + return $this; + } + + public function getMarkup(): array { + $markup = $this->params; + $markup['inline_keyboard'] = $this->buttons; + + return $markup; + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboard.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboard.php new file mode 100644 index 0000000..cabbd77 --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboard.php @@ -0,0 +1,99 @@ +params = $params; + $this->row(); + } + + /** + * Добавить новую строку в панель кнопок + * @return TReplyKeyboard + */ + public function row(){ + $this->row++; + if(!isset($this->buttons[$this->row])) $this->buttons[$this->row] = []; + + return $this; + } + + /** + * Добавить кнопку + * @param string $text Текст кнопки + * @return TReplyKeyboard + */ + public function button(string $text){ + $this->buttons[$this->row][] = ['text' => $text]; + + return $this; + } + + /** + * Указывает клиенту подогнать высоту клавиатуры под количество кнопок + * (сделать её меньше, если кнопок мало и наоборот) + * @param bool $value + * @return TReplyKeyboard + */ + public function setResize(bool $value){ + $this->params['resize_keyboard'] = $value; + return $this; + } + + /** + * Указывает клиенту скрыть клавиатуру после использования (после нажатия на кнопку). + * Её по-прежнему можно будет открыть через иконку в поле ввода сообщения. + * @param bool $value + * @return TReplyKeyboard + */ + public function setOneTime(bool $value){ + $this->params['one_time_keyboard'] = $value; + return $this; + } + + /** + * @param bool $value + * @return TReplyKeyboard + */ + public function setSelective(bool $value){ + $this->params['selective'] = $value; + return $this; + } + + /** + * @return array + */ + public function getMarkup(): array { + $markup = $this->params; + $markup['keyboard'] = $this->buttons; + + return $markup; + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboardRemove.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboardRemove.php new file mode 100644 index 0000000..17f61dd --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/object/markup/TReplyKeyboardRemove.php @@ -0,0 +1,25 @@ +markup['remove_keyboard'] = true; + } + + /** + * --EN-- + * Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message. + * + * @param bool $value + */ + public function setSelective(bool $value){ + $this->markup['selective'] = $value; + return $this; + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TAnswerCallbackQuery.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TAnswerCallbackQuery.php new file mode 100644 index 0000000..d9803a0 --- /dev/null +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TAnswerCallbackQuery.php @@ -0,0 +1,78 @@ +put(__FUNCTION__, $value); + } + + /** + * --EN-- + * Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function text(string $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * URL that will be opened by the user's client. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function url(string $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function show_alert(bool $value){ + return $this->put(__FUNCTION__, $value); + } + + /** + * --EN-- + * The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0. + * + * @param string $value + * @return TAnswerCallbackQuery + */ + public function cache_time(int $value){ + return $this->put(__FUNCTION__, $value); + } +} \ No newline at end of file diff --git a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TSendMessageQuery.php b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TSendMessageQuery.php index 6b7769b..acf2e4d 100644 --- a/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TSendMessageQuery.php +++ b/src-bundle/vendor/develnext.bundle.telegram.TelegramBotAPIBundle/telegram/query/TSendMessageQuery.php @@ -4,8 +4,10 @@ namespace telegram\query; -use telegram\object\TMessage; use telegram\TelegramBotApi; +use telegram\exception\TelegramException; +use telegram\object\TMessage; +use telegram\object\markup\AbstractMarkup; class TSendMessageQuery extends TBaseQuery{ public function __construct(TelegramBotApi $api){ @@ -47,11 +49,23 @@ public function disable_notification($value){ public function reply_to_message_id($value){ return $this->put(__FUNCTION__, (int)$value); } - /* + + /** + * @param array|TAbstractMarkup + * @return TSendMessageQuery + */ public function reply_markup($value){ - return $this->put(__FUNCTION__, $value); + if(is_array($value)){ + return $this->put(__FUNCTION__, $value); + } + elseif($value instanceof AbstractMarkup){ + return $this->put(__FUNCTION__, $value->getMarkup()); + } + else { + throw new TelegramException('Invalid reply_markup parameter'); + } } - */ + /** * @return TMessage */ From 8728aab4dd7a8ba9db551658caecf33c418533ec Mon Sep 17 00:00:00 2001 From: "Ts.Saltan" Date: Mon, 16 Dec 2019 21:05:39 +0300 Subject: [PATCH 10/10] Develnext bundle builder --- package.build.php | 2 +- package.php.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.build.php b/package.build.php index c791220..3d9b7ab 100644 --- a/package.build.php +++ b/package.build.php @@ -8,7 +8,7 @@ /** * @jppm-task create-bundle */ -function task_hubPublish(Event $e) +function task_CreateBundle(Event $e) { $package = $e->package(); $data = $package->getAny('develnext-bundle'); diff --git a/package.php.yml b/package.php.yml index d0516c4..db9ba38 100644 --- a/package.php.yml +++ b/package.php.yml @@ -12,6 +12,7 @@ sources: plugins: - Doc - Hub +- DevelNextBundle config: ignore: