Skip to content

Feature/#31 bot api v 4.8 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
### Security
- Nothing
--->
## 1.5.0 - 2020-04-24

#### April 24, 2020
#### Bot API 4.8

### Added
- Supported explanations for
[**Quizzes 2.0**](https://telegram.org/blog/400-million#better-quizzes).
Add explanations by specifying the parameters
explanation and `explanationParseMode` in the method `SendPollMethod`.
- Added the fields explanation and `explanationEntities` to the `PollType` class.
- Supported timed polls that automatically close at a certain date and time.
Set up by specifying the parameter `openPeriod` or `closeDate` in the `SendPollMethod`.
- Added the fields `openPeriod` and `closeDate` to the `PollType` class.
- Supported the new darts animation for the dice mini-game.
Choose between the default dice animation and darts animation
by specifying the parameter `emoji` in the `SendDiceMethod`.
Added two factory methods `createWithDice` and `createWithDarts` for `SendDiceMethod`.
- Added the field `emoji` to the `DiceType` class.

## 1.4.0 - 2020-03-31

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![Duplicated Lines (%)][sonar-duplicated-lines-icon]][sonar-path]
[![Security Rating][sonar-security-rating-icon]][sonar-path]

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

## Installation

Expand Down Expand Up @@ -146,7 +146,7 @@ If you discover any security related issues, please email wformps@gmail.com inst
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-php-v]: https://img.shields.io/travis/php-v/tg-bot-api/bot-api-base.svg?style=flat-square
[ico-bot-api]: https://img.shields.io/badge/Bot%20API-4.7-blue.svg?style=flat-square
[ico-bot-api]: https://img.shields.io/badge/Bot%20API-4.8-blue.svg?style=flat-square
[ico-version]: https://img.shields.io/packagist/v/tg-bot-api/bot-api-base.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/tg-bot-api/bot-api-base/master.svg?style=flat-square
Expand Down
36 changes: 36 additions & 0 deletions src/Method/SendDiceMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ class SendDiceMethod implements SendMethodAliasInterface
use SendToChatVariablesTrait;
use FillFromArrayTrait;

public const EMOJI_DICE = '🎲';
public const EMOJI_DARTS = '🎯';

/**
* Emoji on which the dice throw animation is based. Currently, must be one of “🎲” or “🎯”. Defauts to “🎲”.
*
* @var string|null
*/
public $emoji;

/**
* @param int|string $chatId
*
Expand All @@ -41,4 +51,30 @@ public static function create($chatId, array $data = null): SendDiceMethod

return $instance;
}

/**
* @param $chatId
*
* @throws BadArgumentException
*/
public static function createWithDice($chatId, array $data = null): SendDiceMethod
{
$instance = static::create($chatId, $data);
$instance->emoji = static::EMOJI_DICE;

return $instance;
}

/**
* @param $chatId
*
* @throws BadArgumentException
*/
public static function createWithDarts($chatId, array $data = null): SendDiceMethod
{
$instance = static::create($chatId, $data);
$instance->emoji = self::EMOJI_DARTS;

return $instance;
}
}
34 changes: 33 additions & 1 deletion src/Method/SendPollMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use TgBotApi\BotApiBase\Exception\BadArgumentException;
use TgBotApi\BotApiBase\Interfaces\PollTypeInterface;
use TgBotApi\BotApiBase\Method\Interfaces\HasParseModeVariableInterface;
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface;
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait;
Expand All @@ -17,7 +18,7 @@
*
* @see https://core.telegram.org/bots/api#sendpoll
*/
class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface
class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface, HasParseModeVariableInterface
{
use FillFromArrayTrait;
use SendToChatVariablesTrait;
Expand Down Expand Up @@ -64,6 +65,37 @@ class SendPollMethod implements SendMethodAliasInterface, PollTypeInterface
*/
public $correctOptionId;

/**
* 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 with at most 2 line feeds after entities parsing.
*
* @var string|null
*/
public $explanation;

/**
* Optional. Mode for parsing entities in the explanation. See formatting options for more details.
*
* @var string|null
*/
public $explanationParseMode;

/**
* Optional. Amount of time in seconds the poll will be active after creation, 5-600.
* Can't be used together with close_date.
*
* @var int|null
*/
public $openPeriod;

/**
* Point in time (will be transformed to Unix timestamp on send) when the poll will be automatically closed.
* Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period.
*
* @var \DateTimeInterface|null
*/
public $closeDate;

/**
* Optional. Pass True, if the poll needs to be immediately closed.
*
Expand Down
9 changes: 8 additions & 1 deletion src/Type/DiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Class DiceType.
*
* This object represents a dice with random value from 1 to 6.
* This object represents a dice with random value from 1 to 6 for currently supported base emoji.
* (Yes, we're aware of the “proper” singular of die.
* But it's awkward, and we decided to help it change.
* One dice at a time!)
Expand All @@ -22,4 +22,11 @@ class DiceType
* Value of the dice, 1-6
*/
public $value;

/**
* Emoji on which the dice throw animation is based.
*
* @var string|null
*/
public $emoji;
}
29 changes: 29 additions & 0 deletions src/Type/PollType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,33 @@ class PollType implements PollTypeInterface
* @var int|null
*/
public $correctOptionId;

/**
* 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.
*
* @var string|null
*/
public $explanation;

/**
* Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation.
*
* @var MessageEntityType|null
*/
public $explanationEntities;

/**
* Optional. Amount of time in seconds the poll will be active after creation.
*
* @var int|null
*/
public $openPeriod;

/**
* Optional. Point in time (Unix timestamp) when the poll will be automatically closed.
*
* @var \DateTimeInterface|null
*/
public $closeDate;
}
62 changes: 39 additions & 23 deletions tests/Method/SendDiceMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace TgBotApi\BotApiBase\Tests\Method;

use TgBotApi\BotApiBase\BotApiComplete;
use TgBotApi\BotApiBase\Method\SendContactMethod;
use TgBotApi\BotApiBase\Method\SendDiceMethod;
use TgBotApi\BotApiBase\Tests\Method\Traits\InlineKeyboardMarkupTrait;

Expand All @@ -14,39 +13,56 @@ class SendDiceMethodTest extends MethodTestCase
use InlineKeyboardMarkupTrait;

/**
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
* @dataProvider dataProvider
*
* @throws \TgBotApi\BotApiBase\Exception\ResponseException
*/
public function testEncode()
public function testEncode(BotApiComplete $bot, SendDiceMethod $method): void
{
$this->getApi()->sendDice($this->getMethod());
$this->getApi()->send($this->getMethod());
$bot->sendDice($method);
}

private function getApi(): BotApiComplete
/**
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
*
* @return array[]
*/
public function dataProvider(): array
{
return [
[
$this->getApi(SendDiceMethod::EMOJI_DICE),
SendDiceMethod::createWithDice(
'chat_id',
[
'disableNotification' => true,
'replyToMessageId' => 1,
'replyMarkup' => $this->buildInlineMarkupObject(),
]
),
],
[
$this->getApi(SendDiceMethod::EMOJI_DARTS),
SendDiceMethod::createWithDarts(
'chat_id',
[
'disableNotification' => true,
'replyToMessageId' => 1,
'replyMarkup' => $this->buildInlineMarkupObject(),
]
),
],
];
}

private function getApi(string $emoji): BotApiComplete
{
return $this->getBot('sendDice', [
'chat_id' => 'chat_id',
'disable_notification' => true,
'reply_to_message_id' => 1,
'emoji' => $emoji,
'reply_markup' => $this->buildInlineMarkupArray(),
], [], ['reply_markup']);
}

/**
* @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
*
* @return SendContactMethod
*/
private function getMethod(): SendDiceMethod
{
return SendDiceMethod::create(
'chat_id',
[
'disableNotification' => true,
'replyToMessageId' => 1,
'replyMarkup' => $this->buildInlineMarkupObject(),
]
);
}
}