Skip to content

Commit a6cda5a

Browse files
authored
Merge pull request #32 from tg-bot-api/feature/#31-bot-api-v-4.8
Feature/#31 bot api v 4.8
2 parents bd5fabf + 40acf3b commit a6cda5a

File tree

7 files changed

+166
-27
lines changed

7 files changed

+166
-27
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
2222
### Security
2323
- Nothing
2424
--->
25+
## 1.5.0 - 2020-04-24
26+
27+
#### April 24, 2020
28+
#### Bot API 4.8
29+
30+
### Added
31+
- Supported explanations for
32+
[**Quizzes 2.0**](https://telegram.org/blog/400-million#better-quizzes).
33+
Add explanations by specifying the parameters
34+
explanation and `explanationParseMode` in the method `SendPollMethod`.
35+
- Added the fields explanation and `explanationEntities` to the `PollType` class.
36+
- Supported timed polls that automatically close at a certain date and time.
37+
Set up by specifying the parameter `openPeriod` or `closeDate` in the `SendPollMethod`.
38+
- Added the fields `openPeriod` and `closeDate` to the `PollType` class.
39+
- Supported the new darts animation for the dice mini-game.
40+
Choose between the default dice animation and darts animation
41+
by specifying the parameter `emoji` in the `SendDiceMethod`.
42+
Added two factory methods `createWithDice` and `createWithDarts` for `SendDiceMethod`.
43+
- Added the field `emoji` to the `DiceType` class.
2544

2645
## 1.4.0 - 2020-03-31
2746

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![Duplicated Lines (%)][sonar-duplicated-lines-icon]][sonar-path]
1515
[![Security Rating][sonar-security-rating-icon]][sonar-path]
1616

17-
#### Supported Telegram Bot API v4.6 (January 23, 2020 update)
17+
#### Supported Telegram Bot API v4.8 (April 24, 2020)
1818

1919
## Installation
2020

@@ -146,7 +146,7 @@ If you discover any security related issues, please email [email protected] inst
146146
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
147147

148148
[ico-php-v]: https://img.shields.io/travis/php-v/tg-bot-api/bot-api-base.svg?style=flat-square
149-
[ico-bot-api]: https://img.shields.io/badge/Bot%20API-4.7-blue.svg?style=flat-square
149+
[ico-bot-api]: https://img.shields.io/badge/Bot%20API-4.8-blue.svg?style=flat-square
150150
[ico-version]: https://img.shields.io/packagist/v/tg-bot-api/bot-api-base.svg?style=flat-square
151151
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
152152
[ico-travis]: https://img.shields.io/travis/tg-bot-api/bot-api-base/master.svg?style=flat-square

src/Method/SendDiceMethod.php

+36
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ class SendDiceMethod implements SendMethodAliasInterface
2525
use SendToChatVariablesTrait;
2626
use FillFromArrayTrait;
2727

28+
public const EMOJI_DICE = '🎲';
29+
public const EMOJI_DARTS = '🎯';
30+
31+
/**
32+
* Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”.
33+
*
34+
* @var string|null
35+
*/
36+
public $emoji;
37+
2838
/**
2939
* @param int|string $chatId
3040
*
@@ -41,4 +51,30 @@ public static function create($chatId, array $data = null): SendDiceMethod
4151

4252
return $instance;
4353
}
54+
55+
/**
56+
* @param $chatId
57+
*
58+
* @throws BadArgumentException
59+
*/
60+
public static function createWithDice($chatId, array $data = null): SendDiceMethod
61+
{
62+
$instance = static::create($chatId, $data);
63+
$instance->emoji = static::EMOJI_DICE;
64+
65+
return $instance;
66+
}
67+
68+
/**
69+
* @param $chatId
70+
*
71+
* @throws BadArgumentException
72+
*/
73+
public static function createWithDarts($chatId, array $data = null): SendDiceMethod
74+
{
75+
$instance = static::create($chatId, $data);
76+
$instance->emoji = self::EMOJI_DARTS;
77+
78+
return $instance;
79+
}
4480
}

src/Method/SendPollMethod.php

+33-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use TgBotApi\BotApiBase\Exception\BadArgumentException;
88
use TgBotApi\BotApiBase\Interfaces\PollTypeInterface;
9+
use TgBotApi\BotApiBase\Method\Interfaces\HasParseModeVariableInterface;
910
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface;
1011
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
1112
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait;
@@ -17,7 +18,7 @@
1718
*
1819
* @see https://core.telegram.org/bots/api#sendpoll
1920
*/
20-
class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface
21+
class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface, HasParseModeVariableInterface
2122
{
2223
use FillFromArrayTrait;
2324
use SendToChatVariablesTrait;
@@ -64,6 +65,37 @@ class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface
6465
*/
6566
public $correctOptionId;
6667

68+
/**
69+
* Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon
70+
* in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing.
71+
*
72+
* @var string|null
73+
*/
74+
public $explanation;
75+
76+
/**
77+
* Optional. Mode for parsing entities in the explanation. See formatting options for more details.
78+
*
79+
* @var string|null
80+
*/
81+
public $explanationParseMode;
82+
83+
/**
84+
* Optional. Amount of time in seconds the poll will be active after creation, 5-600.
85+
* Can't be used together with close_date.
86+
*
87+
* @var int|null
88+
*/
89+
public $openPeriod;
90+
91+
/**
92+
* Point in time (will be transformed to Unix timestamp on send) when the poll will be automatically closed.
93+
* Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
94+
*
95+
* @var \DateTimeInterface|null
96+
*/
97+
public $closeDate;
98+
6799
/**
68100
* Optional. Pass True, if the poll needs to be immediately closed.
69101
*

src/Type/DiceType.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Class DiceType.
99
*
10-
* This object represents a dice with random value from 1 to 6.
10+
* This object represents a dice with random value from 1 to 6 for currently supported base emoji.
1111
* (Yes, we're aware of the “proper” singular of die.
1212
* But it's awkward, and we decided to help it change.
1313
* One dice at a time!)
@@ -22,4 +22,11 @@ class DiceType
2222
* Value of the dice, 1-6
2323
*/
2424
public $value;
25+
26+
/**
27+
* Emoji on which the dice throw animation is based.
28+
*
29+
* @var string|null
30+
*/
31+
public $emoji;
2532
}

src/Type/PollType.php

+29
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,33 @@ class PollType implements PollTypeInterface
7878
* @var int|null
7979
*/
8080
public $correctOptionId;
81+
82+
/**
83+
* Optional. Text that is shown when a user chooses an incorrect answer or taps
84+
* on the lamp icon in a quiz-style poll, 0-200 characters.
85+
*
86+
* @var string|null
87+
*/
88+
public $explanation;
89+
90+
/**
91+
* Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation.
92+
*
93+
* @var MessageEntityType|null
94+
*/
95+
public $explanationEntities;
96+
97+
/**
98+
* Optional. Amount of time in seconds the poll will be active after creation.
99+
*
100+
* @var int|null
101+
*/
102+
public $openPeriod;
103+
104+
/**
105+
* Optional. Point in time (Unix timestamp) when the poll will be automatically closed.
106+
*
107+
* @var \DateTimeInterface|null
108+
*/
109+
public $closeDate;
81110
}

tests/Method/SendDiceMethodTest.php

+39-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace TgBotApi\BotApiBase\Tests\Method;
66

77
use TgBotApi\BotApiBase\BotApiComplete;
8-
use TgBotApi\BotApiBase\Method\SendContactMethod;
98
use TgBotApi\BotApiBase\Method\SendDiceMethod;
109
use TgBotApi\BotApiBase\Tests\Method\Traits\InlineKeyboardMarkupTrait;
1110

@@ -14,39 +13,56 @@ class SendDiceMethodTest extends MethodTestCase
1413
use InlineKeyboardMarkupTrait;
1514

1615
/**
17-
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
16+
* @dataProvider dataProvider
17+
*
1818
* @throws \TgBotApi\BotApiBase\Exception\ResponseException
1919
*/
20-
public function testEncode()
20+
public function testEncode(BotApiComplete $bot, SendDiceMethod $method): void
2121
{
22-
$this->getApi()->sendDice($this->getMethod());
23-
$this->getApi()->send($this->getMethod());
22+
$bot->sendDice($method);
2423
}
2524

26-
private function getApi(): BotApiComplete
25+
/**
26+
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
27+
*
28+
* @return array[]
29+
*/
30+
public function dataProvider(): array
31+
{
32+
return [
33+
[
34+
$this->getApi(SendDiceMethod::EMOJI_DICE),
35+
SendDiceMethod::createWithDice(
36+
'chat_id',
37+
[
38+
'disableNotification' => true,
39+
'replyToMessageId' => 1,
40+
'replyMarkup' => $this->buildInlineMarkupObject(),
41+
]
42+
),
43+
],
44+
[
45+
$this->getApi(SendDiceMethod::EMOJI_DARTS),
46+
SendDiceMethod::createWithDarts(
47+
'chat_id',
48+
[
49+
'disableNotification' => true,
50+
'replyToMessageId' => 1,
51+
'replyMarkup' => $this->buildInlineMarkupObject(),
52+
]
53+
),
54+
],
55+
];
56+
}
57+
58+
private function getApi(string $emoji): BotApiComplete
2759
{
2860
return $this->getBot('sendDice', [
2961
'chat_id' => 'chat_id',
3062
'disable_notification' => true,
3163
'reply_to_message_id' => 1,
64+
'emoji' => $emoji,
3265
'reply_markup' => $this->buildInlineMarkupArray(),
3366
], [], ['reply_markup']);
3467
}
35-
36-
/**
37-
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
38-
*
39-
* @return SendContactMethod
40-
*/
41-
private function getMethod(): SendDiceMethod
42-
{
43-
return SendDiceMethod::create(
44-
'chat_id',
45-
[
46-
'disableNotification' => true,
47-
'replyToMessageId' => 1,
48-
'replyMarkup' => $this->buildInlineMarkupObject(),
49-
]
50-
);
51-
}
5268
}

0 commit comments

Comments
 (0)