Skip to content

Commit 1c8f50f

Browse files
committed
#31: Bot api update April 24, 2020. Implemented all update changes
1 parent bd5fabf commit 1c8f50f

File tree

5 files changed

+145
-25
lines changed

5 files changed

+145
-25
lines changed

src/Method/SendDiceMethod.php

Lines changed: 36 additions & 0 deletions
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

Lines changed: 33 additions & 1 deletion
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 29 additions & 0 deletions
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

Lines changed: 39 additions & 23 deletions
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)