Added method \TgBotLib\Bot > uploadStickerFile()
to upload a sticker file with a sticker for later use in createNewStickerSet
and addStickerToSet
methods (can be used multiple times). See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information.
https://git.n64.cc/nosial/libs/tgbot/-/issues/2
This commit is contained in:
parent
4dc5e9e20d
commit
595872c997
2 changed files with 49 additions and 0 deletions
|
@ -25,6 +25,8 @@ This update accompanies the release of the [Telegram Bot API 6.6](https://core.t
|
|||
* Added method `\TgBotLib\Bot > addStickerToSet()` to add a new sticker to a set created by the bot.
|
||||
See [addStickerToSet](https://core.telegram.org/bots/api#addstickertoset) for more information.
|
||||
* Added abstract class `\TgBotLib\Abstracts > StickerFormat` to represent a sticker format ("`static`", "`animated`" or "`video`")
|
||||
* Added method `\TgBotLib\Bot > uploadStickerFile()` to upload a sticker file with a sticker for later use in `createNewStickerSet` and `addStickerToSet` methods (can be used multiple times).
|
||||
See [uploadStickerFile](https://core.telegram.org/bots/api#uploadstickerfile) for more information.
|
||||
|
||||
### Changed
|
||||
* Removed unused `__destruct()` method from `\TgBotLib\Bot`
|
||||
|
|
|
@ -2526,4 +2526,51 @@
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to upload a file with a sticker for later use in the createNewStickerSet and addStickerToSet
|
||||
* methods (the file can be used multiple times). Returns the uploaded File on success.
|
||||
*
|
||||
* @param int $user_id User identifier of sticker file owner
|
||||
* @param string $sticker A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements.
|
||||
* @param string $sticker_format Format of the sticker, must be one of “static”, “animated”, “video”
|
||||
* @return File
|
||||
* @throws TelegramException
|
||||
* @see https://core.telegram.org/bots/api#sending-files
|
||||
* @link https://core.telegram.org/bots/api#uploadstickerfile
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
public function uploadStickerFile(int $user_id, string $sticker, string $sticker_format): File
|
||||
{
|
||||
if(file_exists($sticker))
|
||||
{
|
||||
return File::fromArray(
|
||||
$this->sendFileUpload('uploadStickerFile', 'sticker', $sticker, [
|
||||
'user_id' => $user_id,
|
||||
'sticker_format' => $sticker_format
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$tmp_file = new TempFile();
|
||||
file_put_contents($tmp_file, $sticker);
|
||||
|
||||
try
|
||||
{
|
||||
$response = File::fromArray(
|
||||
$this->sendFileUpload('uploadStickerFile', 'sticker', $tmp_file, [
|
||||
'user_id' => $user_id,
|
||||
'sticker_format' => $sticker_format
|
||||
])
|
||||
);
|
||||
}
|
||||
catch(TelegramException $e)
|
||||
{
|
||||
unset($tmp_file);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
unset($tmp_file);
|
||||
return $response;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue