Skip to content

Commit a3ef2f4

Browse files
authored
Merge pull request #1082 from noplanman/1081-bot_api_4.8
Add new Bot API 4.8 fields to Poll and Dice entities and DB.
2 parents 5f1afb0 + 9ac0dd3 commit a3ef2f4

File tree

7 files changed

+39
-17
lines changed

7 files changed

+39
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
88
- [:ledger: View file changes][Unreleased]
99
### Added
1010
- Replaced 'generic' and 'genericmessage' strings with Telegram::GENERIC_COMMAND and Telegram::GENERIC_MESSAGE_COMMAND constants (@1int)
11+
- Bot API 4.8 (Extra Poll and Dice features).
1112
### Changed
1213
### Deprecated
1314
### Removed

README.md

Lines changed: 2 additions & 2 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-4.7%20%28March%202020%29-32a2da.svg)](https://core.telegram.org/bots/api#december-31-2019)
10+
[![API Version](https://img.shields.io/badge/Bot%20API-4.8%20%28April%202020%29-32a2da.svg)](https://core.telegram.org/bots/api#april-24-2020)
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

@@ -76,7 +76,7 @@ This Bot aims to provide a platform where one can simply write a bot and have in
7676

7777
The Bot can:
7878
- Retrieve updates with [webhook](#webhook-installation) and [getUpdates](#getupdates-installation) methods.
79-
- Supports all types and methods according to Telegram API 4.7 (March 2020).
79+
- Supports all types and methods according to Telegram Bot API 4.8 (April 2020).
8080
- Supports supergroups.
8181
- Handle commands in chat with other bots.
8282
- Manage Channel from the bot admin interface.

src/DB.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,17 +837,21 @@ public static function insertPollRequest(Poll $poll)
837837
try {
838838
$sth = self::$pdo->prepare('
839839
INSERT INTO `' . TB_POLL . '`
840-
(`id`, `question`, `options`, `total_voter_count`, `is_closed`, `is_anonymous`, `type`, `allows_multiple_answers`, `correct_option_id`, `created_at`)
840+
(`id`, `question`, `options`, `total_voter_count`, `is_closed`, `is_anonymous`, `type`, `allows_multiple_answers`, `correct_option_id`, `explanation`, `explanation_entities`, `open_period`, `close_date`, `created_at`)
841841
VALUES
842-
(:id, :question, :options, :total_voter_count, :is_closed, :is_anonymous, :type, :allows_multiple_answers, :correct_option_id, :created_at)
842+
(:id, :question, :options, :total_voter_count, :is_closed, :is_anonymous, :type, :allows_multiple_answers, :correct_option_id, :explanation, :explanation_entities, :open_period, :close_date, :created_at)
843843
ON DUPLICATE KEY UPDATE
844844
`options` = VALUES(`options`),
845845
`total_voter_count` = VALUES(`total_voter_count`),
846846
`is_closed` = VALUES(`is_closed`),
847847
`is_anonymous` = VALUES(`is_anonymous`),
848848
`type` = VALUES(`type`),
849849
`allows_multiple_answers` = VALUES(`allows_multiple_answers`),
850-
`correct_option_id` = VALUES(`correct_option_id`)
850+
`correct_option_id` = VALUES(`correct_option_id`),
851+
`explanation` = VALUES(`explanation`),
852+
`explanation_entities` = VALUES(`explanation_entities`),
853+
`open_period` = VALUES(`open_period`),
854+
`close_date` = VALUES(`close_date`)
851855
');
852856

853857
$sth->bindValue(':id', $poll->getId());
@@ -859,6 +863,10 @@ public static function insertPollRequest(Poll $poll)
859863
$sth->bindValue(':type', $poll->getType());
860864
$sth->bindValue(':allows_multiple_answers', $poll->getAllowsMultipleAnswers(), PDO::PARAM_INT);
861865
$sth->bindValue(':correct_option_id', $poll->getCorrectOptionId());
866+
$sth->bindValue(':explanation', $poll->getExplanation());
867+
$sth->bindValue(':explanation_entities', self::entitiesArrayToJson($poll->getExplanationEntities() ?: null));
868+
$sth->bindValue(':open_period', $poll->getOpenPeriod());
869+
$sth->bindValue(':close_date', self::getTimestamp($poll->getCloseDate()));
862870
$sth->bindValue(':created_at', self::getTimestamp());
863871

864872
return $sth->execute();

src/Entities/Dice.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*
1919
* @link https://core.telegram.org/bots/api#dice
2020
*
21-
* @method int getValue() Value of the dice, 1-6
21+
* @method string getEmoji() Emoji on which the dice throw animation is based
22+
* @method int getValue() Value of the dice, 1-6
2223
*/
2324
class Dice extends Entity
2425
{

src/Entities/Poll.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
*
1919
* @link https://core.telegram.org/bots/api#poll
2020
*
21-
* @method string getId() Unique poll identifier
22-
* @method string getQuestion() Poll question, 1-255 characters
23-
* @method PollOption[] getOptions() List of poll options
24-
* @method int getTotalVoterCount() Total number of users that voted in the poll
25-
* @method bool getIsClosed() True, if the poll is closed
26-
* @method bool getIsAnonymous() True, if the poll is anonymous
27-
* @method string getType() Poll type, currently can be “regular” or “quiz”
28-
* @method bool getAllowsMultipleAnswers() True, if the poll allows multiple answers
29-
* @method int getCorrectOptionId() Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.
30-
21+
* @method string getId() Unique poll identifier
22+
* @method string getQuestion() Poll question, 1-255 characters
23+
* @method PollOption[] getOptions() List of poll options
24+
* @method int getTotalVoterCount() Total number of users that voted in the poll
25+
* @method bool getIsClosed() True, if the poll is closed
26+
* @method bool getIsAnonymous() True, if the poll is anonymous
27+
* @method string getType() Poll type, currently can be “regular” or “quiz”
28+
* @method bool getAllowsMultipleAnswers() True, if the poll allows multiple answers
29+
* @method int getCorrectOptionId() Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.
30+
* @method string getExplanation() Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters
31+
* @method MessageEntity[] getExplanationEntities() Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
32+
* @method int getOpenPeriod() Optional. Amount of time in seconds the poll will be active after creation
33+
* @method int getCloseDate() Optional. Point in time (Unix timestamp) when the poll will be automatically closed
3134
*/
3235
class Poll extends Entity
3336
{
@@ -37,7 +40,8 @@ class Poll extends Entity
3740
protected function subEntities()
3841
{
3942
return [
40-
'options' => [PollOption::class],
43+
'options' => [PollOption::class],
44+
'explanation_entities' => [MessageEntity::class],
4145
];
4246
}
4347
}

structure.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ CREATE TABLE IF NOT EXISTS `poll` (
216216
`type` char(255) COMMENT 'Poll type, currently can be “regular” or “quiz”',
217217
`allows_multiple_answers` tinyint(1) DEFAULT 0 COMMENT 'True, if the poll allows multiple answers',
218218
`correct_option_id` int UNSIGNED COMMENT '0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.',
219+
`explanation` varchar(255) DEFAULT NULL COMMENT 'Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters',
220+
`explanation_entities` text DEFAULT NULL COMMENT 'Special entities like usernames, URLs, bot commands, etc. that appear in the explanation',
221+
`open_period` int UNSIGNED DEFAULT NULL COMMENT 'Amount of time in seconds the poll will be active after creation',
222+
`close_date` timestamp NULL DEFAULT NULL COMMENT 'Point in time (Unix timestamp) when the poll will be automatically closed',
219223
`created_at` timestamp NULL DEFAULT NULL COMMENT 'Entry date creation',
220224

221225
PRIMARY KEY (`id`)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE `poll` ADD COLUMN `explanation` varchar(255) DEFAULT NULL COMMENT 'Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters' AFTER `correct_option_id`;
2+
ALTER TABLE `poll` ADD COLUMN `explanation_entities` text DEFAULT NULL COMMENT 'Special entities like usernames, URLs, bot commands, etc. that appear in the explanation' AFTER `explanation`;
3+
ALTER TABLE `poll` ADD COLUMN `open_period` int UNSIGNED DEFAULT NULL COMMENT 'Amount of time in seconds the poll will be active after creation' AFTER `explanation_entities`;
4+
ALTER TABLE `poll` ADD COLUMN `close_date` timestamp NULL DEFAULT NULL COMMENT 'Point in time (Unix timestamp) when the poll will be automatically closed' AFTER `open_period`;

0 commit comments

Comments
 (0)