Skip to content

Commit

Permalink
Add sendVideoNote method
Browse files Browse the repository at this point in the history
  • Loading branch information
punyflash committed Sep 12, 2020
1 parent d6e4260 commit d036f31
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use WeStacks\TeleBot\Methods\SendAudioMethod;
use WeStacks\TeleBot\Methods\SendDocumentMethod;
use WeStacks\TeleBot\Methods\SendVideoMethod;
use WeStacks\TeleBot\Methods\SendVideoNoteMethod;
use WeStacks\TeleBot\Methods\SendVoiceMethod;
use WeStacks\TeleBot\Methods\SetWebhookMethod;
use WeStacks\TeleBot\Objects\Update;
Expand All @@ -39,6 +40,7 @@
* @method Message|PromiseInterface|False sendMessage(array $parameters = []) Use this method to send text messages. On success, the sent Message is returned.
* @method Message|PromiseInterface|False sendPhoto(array $parameters = []) Use this method to send photos. On success, the sent Message is returned.
* @method Message|PromiseInterface|False sendVideo(array $parameters = []) Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
* @method Message|PromiseInterface|False sendVideoNote(array $parameters = []) As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.
* @method Message|PromiseInterface|False sendVoice(array $parameters = []) Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
* @method True|PromiseInterface|False setWebhook(array $parameters = []) Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
*
Expand Down Expand Up @@ -198,6 +200,7 @@ protected function methods()
'sendMessage' => SendMessageMethod::class,
'sendPhoto' => SendPhotoMethod::class,
'sendVideo' => SendVideoMethod::class,
'sendVideoNote' => SendVideoNoteMethod::class,
'sendVoice' => SendVoiceMethod::class,
'setWebhook' => SetWebhookMethod::class,
];
Expand Down
39 changes: 39 additions & 0 deletions src/Methods/SendVideoNoteMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace WeStacks\TeleBot\Methods;

use WeStacks\TeleBot\Helpers\TypeCaster;
use WeStacks\TeleBot\Interfaces\TelegramMethod;
use WeStacks\TeleBot\Objects\InputFile;
use WeStacks\TeleBot\Objects\Keyboard;
use WeStacks\TeleBot\Objects\Message;

class SendVideoNoteMethod extends TelegramMethod
{
protected function request()
{
return [
'type' => 'POST',
'url' => "https://api.telegram.org/bot{$this->token}/sendVideoNote",
'send' => $this->send(),
'expect' => Message::class
];
}

private function send()
{
$parameters = [
'chat_id' => 'string',
'video_note' => InputFile::class,
'duration' => 'integer',
'length' => 'integer',
'thumb' => InputFile::class,
'disable_notification' => 'boolean',
'reply_to_message_id' => 'integer',
'reply_markup' => Keyboard::class
];

$object = TypeCaster::castValues($this->arguments[0] ?? [], $parameters);
return [ 'multipart' => TypeCaster::createMultipartArray($object) ];
}
}
12 changes: 12 additions & 0 deletions tests/Feature/SendFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,17 @@ public function testSendVoice()
'voice' => 'https://file-examples-com.github.io/uploads/2017/11/file_example_OOG_1MG.ogg'
]);
$this->assertInstanceOf(Message::class, $message);
// https://raw.githubusercontent.com/TelegramBots/book/master/src/docs/video-waves.mp4
}

public function testSendVideoNote()
{
$message = $this->bot->sendVideoNote([
'chat_id' => getenv('TELEGRAM_USER_ID'),
'video_note' => 'https://raw.githubusercontent.com/TelegramBots/book/master/src/docs/video-waves.mp4',
'length' => 360,
'duration' => 47
]);
$this->assertInstanceOf(Message::class, $message);
}
}

0 comments on commit d036f31

Please sign in to comment.