Add UploadStickerFile method
This commit is contained in:
parent
58a04ba94c
commit
36bc36e208
2 changed files with 56 additions and 0 deletions
|
@ -106,6 +106,7 @@
|
|||
use TgBotLib\Methods\UnpinAllForumTopicMessages;
|
||||
use TgBotLib\Methods\UnpinAllGeneralForumTopicMessages;
|
||||
use TgBotLib\Methods\UnpinChatMessage;
|
||||
use TgBotLib\Methods\UploadStickerFile;
|
||||
|
||||
enum Methods : string
|
||||
{
|
||||
|
@ -210,6 +211,7 @@
|
|||
case SEND_STICKER = 'sendSticker';
|
||||
case GET_STICKER_SET = 'getStickerSet';
|
||||
case GET_CUSTOM_EMOJI_STICKERS = 'getCustomEmojiStickers';
|
||||
case UPLOAD_STICKER_FILE = 'uploadStickerFile';
|
||||
|
||||
/**
|
||||
* Executes a command on the provided bot with the given parameters.
|
||||
|
@ -324,6 +326,7 @@
|
|||
self::SEND_STICKER => SendSticker::execute($bot, $parameters),
|
||||
self::GET_STICKER_SET => GetStickerSet::execute($bot, $parameters),
|
||||
self::GET_CUSTOM_EMOJI_STICKERS => GetCustomEmojiStickers::execute($bot, $parameters),
|
||||
self::UPLOAD_STICKER_FILE => UploadStickerFile::execute($bot, $parameters),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
53
src/TgBotLib/Methods/UploadStickerFile.php
Normal file
53
src/TgBotLib/Methods/UploadStickerFile.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Methods;
|
||||
|
||||
use TgBotLib\Abstracts\Method;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Enums\Methods;
|
||||
use TgBotLib\Objects\File;
|
||||
use TgBotLib\Objects\Message;
|
||||
|
||||
class UploadStickerFile extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(Bot $bot, array $parameters = []): File
|
||||
{
|
||||
if (isset($parameters['sticker']))
|
||||
{
|
||||
$sticker = $parameters['sticker'];
|
||||
|
||||
// If media is a file path and exists locally
|
||||
if (is_string($sticker) && file_exists($sticker) && is_file($sticker))
|
||||
{
|
||||
$curl = self::buildUpload($bot, Methods::UPLOAD_STICKER_FILE->value, 'sticker', $sticker, array_diff_key($parameters, ['sticker' => null]));
|
||||
return File::fromArray(self::executeCurl($curl));
|
||||
}
|
||||
}
|
||||
|
||||
return File::fromArray(self::executeCurl(self::buildPost($bot, Methods::UPLOAD_STICKER_FILE->value, $parameters)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getRequiredParameters(): ?array
|
||||
{
|
||||
return [
|
||||
'user_id',
|
||||
'sticker',
|
||||
'sticker_format'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getOptionalParameters(): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue