Skip to content

Commit 9a69f82

Browse files
authored
Merge pull request #322 from TelegramBot/updateMethods
Update sendVoice & sendDice methods
2 parents dafad7c + 804ee2a commit 9a69f82

File tree

4 files changed

+96
-12
lines changed

4 files changed

+96
-12
lines changed

src/BotApi.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -812,14 +812,17 @@ public function sendAnimation(
812812
* On success, the sent Message is returned.
813813
* Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
814814
*
815-
* @param int|string $chatId chat_id or @channel_name
815+
* @param int|string $chatId chat_id or @channel_name
816816
* @param \CURLFile|string $voice
817-
* @param int|null $duration
818-
* @param int|null $replyToMessageId
817+
* @param string $caption Voice message caption, 0-1024 characters after entities parsing
818+
* @param int|null $duration
819+
* @param int|null $replyToMessageId
819820
* @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|
820821
* Types\ReplyKeyboardRemove|null $replyMarkup
821-
* @param bool $disableNotification
822-
* @param string|null $parseMode
822+
* @param bool $disableNotification
823+
* @param bool $allowSendingWithoutReply Pass True, if the message should be sent even if the specified
824+
* replied-to message is not found
825+
* @param string|null $parseMode
823826
*
824827
* @return \TelegramBot\Api\Types\Message
825828
* @throws \TelegramBot\Api\InvalidArgumentException
@@ -828,19 +831,23 @@ public function sendAnimation(
828831
public function sendVoice(
829832
$chatId,
830833
$voice,
834+
$caption = null,
831835
$duration = null,
832836
$replyToMessageId = null,
833837
$replyMarkup = null,
834838
$disableNotification = false,
839+
$allowSendingWithoutReply = false,
835840
$parseMode = null
836841
) {
837842
return Message::fromResponse($this->call('sendVoice', [
838843
'chat_id' => $chatId,
839844
'voice' => $voice,
845+
'caption' => $caption,
840846
'duration' => $duration,
841847
'reply_to_message_id' => $replyToMessageId,
842848
'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
843849
'disable_notification' => (bool)$disableNotification,
850+
'allow_sending_without_reply' => $allowSendingWithoutReply,
844851
'parse_mode' => $parseMode
845852
]));
846853
}
@@ -1943,28 +1950,38 @@ public function sendPoll(
19431950
* On success, the sent Message is returned. (Yes, we're aware of the “proper” singular of die.
19441951
* But it's awkward, and we decided to help it change. One dice at a time!)
19451952
*
1946-
* @param $chatId string|int Unique identifier for the target chat or username of the target channel
1953+
* @param $chatId string|int Unique identifier for the target chat or username of the target channel
19471954
* (in the format @channelusername)
1955+
* @param $emoji string Emoji on which the dice throw animation is based. Currently, must be one of “🎲”,
1956+
* “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and
1957+
* values 1-64 for “🎰”. Defaults to “🎲
19481958
* @param bool $disableNotification Sends the message silently. Users will receive a notification with no sound.
19491959
* @param null $replyToMessageId If the message is a reply, ID of the original message
1960+
* @param bool $$allowSendingWithoutReply Pass True, if the message should be sent even if the specified replied-to
1961+
* message is not found,
19501962
* @param null $replyMarkup Additional interface options. A JSON-serialized object for an inline keyboard,
19511963
* custom reply keyboard, instructions to remove reply
19521964
* keyboard or to force a reply from the user.
1965+
*
19531966
* @return bool|Message
19541967
* @throws Exception
19551968
* @throws HttpException
19561969
* @throws InvalidJsonException
19571970
*/
19581971
public function sendDice(
19591972
$chatId,
1973+
$emoji,
19601974
$disableNotification = false,
19611975
$replyToMessageId = null,
1976+
$allowSendingWithoutReply = false,
19621977
$replyMarkup = null
19631978
) {
19641979
return Message::fromResponse($this->call('sendDice', [
19651980
'chat_id' => $chatId,
1981+
'emoji' => $emoji,
19661982
'disable_notification' => (bool) $disableNotification,
19671983
'reply_to_message_id' => (int) $replyToMessageId,
1984+
'allow_sending_without_reply' => (bool) $allowSendingWithoutReply,
19681985
'reply_markup' => $replyMarkup === null ? $replyMarkup : $replyMarkup->toJson(),
19691986
]));
19701987
}

src/Types/Voice.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,36 @@ class Voice extends BaseType implements TypeInterface
1919
*
2020
* @var array
2121
*/
22-
static protected $requiredParams = ['file_id', 'duration'];
22+
static protected $requiredParams = ['file_id', 'file_unique_id', 'duration'];
2323

2424
/**
2525
* {@inheritdoc}
2626
*
2727
* @var array
2828
*/
2929
static protected $map = [
30-
'file_id' => true,
31-
'duration' => true,
32-
'mime_type' => true,
33-
'file_size' => true
30+
'file_id' => true,
31+
'file_unique_id' => true,
32+
'duration' => true,
33+
'mime_type' => true,
34+
'file_size' => true,
3435
];
3536

3637
/**
37-
* Unique identifier for this file
38+
* Identifier for this file, which can be used to download or reuse the file
3839
*
3940
* @var string
4041
*/
4142
protected $fileId;
4243

44+
/**
45+
* Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be
46+
* used to download or reuse the file.
47+
*
48+
* @var string
49+
*/
50+
protected $fileUniqueId;
51+
4352
/**
4453
* Duration of the audio in seconds as defined by sender
4554
*
@@ -77,6 +86,22 @@ public function setFileId($fileId)
7786
$this->fileId = $fileId;
7887
}
7988

89+
/**
90+
* @return string
91+
*/
92+
public function getFileUniqueId()
93+
{
94+
return $this->fileUniqueId;
95+
}
96+
97+
/**
98+
* @param string $fileUniqueId
99+
*/
100+
public function setFileUniqueId($fileUniqueId)
101+
{
102+
$this->fileUniqueId = $fileUniqueId;
103+
}
104+
80105
/**
81106
* @return int
82107
*/

tests/MessageTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TelegramBot\Api\Test;
44

55
use TelegramBot\Api\Types\Chat;
6+
use TelegramBot\Api\Types\Dice;
67
use TelegramBot\Api\Types\Document;
78
use TelegramBot\Api\Types\Location;
89
use TelegramBot\Api\Types\Audio;
@@ -304,6 +305,7 @@ public function testSetVoice()
304305
$item = new Message();
305306
$voice = Voice::fromResponse(array(
306307
'file_id' => 'testFileId1',
308+
'file_unique_id' => 'testUniqueFileId',
307309
'duration' => 1,
308310
'mime_type' => 'audio/mp3',
309311
'file_size' => 3
@@ -317,6 +319,7 @@ public function testGetVoice()
317319
$item = new Message();
318320
$voice = Voice::fromResponse(array(
319321
'file_id' => 'testFileId1',
322+
'file_unique_id' => 'testUniqueFileId',
320323
'duration' => 1,
321324
'mime_type' => 'audio/mp3',
322325
'file_size' => 3
@@ -369,6 +372,29 @@ public function testGetVideo()
369372
$this->assertInstanceOf('\TelegramBot\Api\Types\Video', $item->getVideo());
370373
}
371374

375+
public function testSetDice()
376+
{
377+
$item = new Message();
378+
$dice = Dice::fromResponse(array(
379+
'emoji' => '🎲',
380+
'value' => 3
381+
));
382+
$item->setDice($dice);
383+
$this->assertAttributeEquals($dice, 'dice', $item);
384+
}
385+
386+
public function testGetDice()
387+
{
388+
$item = new Message();
389+
$dice = Dice::fromResponse(array(
390+
'emoji' => '🎲',
391+
'value' => 3
392+
));
393+
$item->setDice($dice);
394+
$this->assertEquals($dice, $item->getDice());
395+
$this->assertInstanceOf('\TelegramBot\Api\Types\Dice', $item->getDice());
396+
}
397+
372398
public function testSetSticker()
373399
{
374400
$item = new Message();

tests/VoiceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ public function testGetFileId()
1919
$this->assertEquals('testfileId', $item->getFileId());
2020
}
2121

22+
public function testSetUniqueFileId()
23+
{
24+
$item = new Voice();
25+
$item->setFileUniqueId('fileUniqueId');
26+
$this->assertAttributeEquals('fileUniqueId', 'fileUniqueId', $item);
27+
}
28+
29+
public function testGetUniqueFileId()
30+
{
31+
$item = new Voice();
32+
$item->setFileUniqueId('fileUniqueId');
33+
$this->assertEquals('fileUniqueId', $item->getFileUniqueId());
34+
}
35+
2236
public function testSetDuration()
2337
{
2438
$item = new Voice();
@@ -65,12 +79,14 @@ public function testFromResponse()
6579
{
6680
$item = Voice::fromResponse(array(
6781
'file_id' => 'testFileId1',
82+
'file_unique_id' => 'testFileUniqueId1',
6883
'duration' => 1,
6984
'mime_type' => 'audio/mp3',
7085
'file_size' => 3
7186
));
7287
$this->assertInstanceOf('\TelegramBot\Api\Types\Voice', $item);
7388
$this->assertAttributeEquals('testFileId1', 'fileId', $item);
89+
$this->assertAttributeEquals('testFileUniqueId1', 'fileUniqueId', $item);
7490
$this->assertAttributeEquals(1, 'duration', $item);
7591
$this->assertAttributeEquals('audio/mp3', 'mimeType', $item);
7692
$this->assertAttributeEquals(3, 'fileSize', $item);

0 commit comments

Comments
 (0)