Skip to content
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

[3.x] Update to Bot Api 6.6 #382

Merged
merged 4 commits into from
Mar 13, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/nutgram/nutgram.svg?style=flat-square)](https://packagist.org/packages/nutgram/nutgram)
[![Total Downloads](https://img.shields.io/packagist/dt/nutgram/nutgram.svg?style=flat-square)](https://packagist.org/packages/nutgram/nutgram)
![GitHub](https://img.shields.io/github/license/nutgram/nutgram)
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-6.5%09--%20February%203,%202023-blue.svg)](https://core.telegram.org/bots/api)
[![API](https://img.shields.io/badge/Telegram%20Bot%20API-6.6%09--%20March%209,%202023-blue.svg)](https://core.telegram.org/bots/api)

[![Test Suite](https://github.com/nutgram/nutgram/actions/workflows/php.yml/badge.svg)](https://github.com/nutgram/nutgram/actions/workflows/php.yml)
[![Maintainability](https://api.codeclimate.com/v1/badges/86c4ca3dae8f64db80f7/maintainability)](https://codeclimate.com/github/nutgram/nutgram/maintainability)
Expand Down
1 change: 0 additions & 1 deletion src/Conversations/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
abstract class Conversation
{

/**
* @var bool
*/
Expand Down
1 change: 0 additions & 1 deletion src/Proxies/GlobalCacheProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
trait GlobalCacheProxy
{

/**
* @param $key
* @param null $default
Expand Down
1 change: 0 additions & 1 deletion src/RunningMode/Fake.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class Fake implements RunningMode
{

/**
* Fake running mode constructor.
* @param object|array|null $update
Expand Down
1 change: 0 additions & 1 deletion src/RunningMode/Polling.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

class Polling implements RunningMode
{

/**
* @param Nutgram $bot
* @throws InvalidArgumentException
Expand Down
1 change: 0 additions & 1 deletion src/RunningMode/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class Webhook implements RunningMode
{

/**
* @var array|string[]
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Telegram/Attributes/StickerFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace SergiX44\Nutgram\Telegram\Attributes;

class StickerFormat extends BaseEnum
{
public const STATIC = 'static';
public const ANIMATED = 'animated';
public const VIDEO = 'video';
}
10 changes: 10 additions & 0 deletions src/Telegram/Attributes/StickerType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace SergiX44\Nutgram\Telegram\Attributes;

class StickerType extends BaseEnum
{
public const REGULAR = 'regular';
public const MASK = 'mask';
public const CUSTOM_EMOJI = 'custom_emoji';
}
65 changes: 65 additions & 0 deletions src/Telegram/Endpoints/AvailableMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use SergiX44\Nutgram\Telegram\Types\Chat\ChatPermissions;
use SergiX44\Nutgram\Telegram\Types\Command\BotCommand;
use SergiX44\Nutgram\Telegram\Types\Command\MenuButton;
use SergiX44\Nutgram\Telegram\Types\Description\BotDescription;
use SergiX44\Nutgram\Telegram\Types\Description\BotShortDescription;
use SergiX44\Nutgram\Telegram\Types\Forum\ForumTopic;
use SergiX44\Nutgram\Telegram\Types\Input\InputMedia;
use SergiX44\Nutgram\Telegram\Types\Input\InputMediaAudio;
Expand Down Expand Up @@ -1461,6 +1463,69 @@ public function getMyCommands(array $opt = []): ?array
return $this->requestJson(__FUNCTION__, $opt, BotCommand::class);
}

/**
* Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setmydescription
* @param array{
* description?:string,
* language_code?:string
* } $opt
* @return void
*/
public function setMyDescription(array $opt = []): bool
{
return $this->requestJson(__FUNCTION__, $opt);
}

/**
* Use this method to get the current bot description for the given user language.
* Returns {@see https://core.telegram.org/bots/api#botdescription BotDescription} on success.
* @see https://core.telegram.org/bots/api#getmydescription
* @param array{
* language_code?:string
* } $opt
* @return BotDescription
*/
public function getMyDescription(array $opt = []): BotDescription
{
return $this->requestJson(__FUNCTION__, $opt, BotDescription::class);
}

/**
* Use this method to change the bot's short description,
* which is shown on the bot's profile page and
* is sent together with the link when users share the bot.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setmyshortdescription
* @param array{
* short_description?:string,
* language_code?:string
* } $opt
* @return void
*/
public function setMyShortDescription(array $opt = []): bool
{
return $this->requestJson(__FUNCTION__, $opt);
}

//getMyShortDescription

/**
* Use this method to get the current bot short description for the given user language.
* Returns {@see https://core.telegram.org/bots/api#botshortdescription BotShortDescription} on success.
* @see https://core.telegram.org/bots/api#getmyshortdescription
* @param array{
* language_code?:string
* } $opt
* @return BotShortDescription
* }
*/
public function getMyShortDescription(array $opt = []): BotShortDescription
{
return $this->requestJson(__FUNCTION__, $opt, BotShortDescription::class);
}

/**
* Use this method to change the bot's menu button in a private chat, or the default menu button.
* Returns True on success.
Expand Down
1 change: 0 additions & 1 deletion src/Telegram/Endpoints/InlineMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
trait InlineMode
{

/**
* Use this method to send answers to an inline query. On success, True is returned.
* No more than 50 results per query are allowed.
Expand Down
121 changes: 102 additions & 19 deletions src/Telegram/Endpoints/Stickers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace SergiX44\Nutgram\Telegram\Endpoints;

use SergiX44\Nutgram\Telegram\Client;
use SergiX44\Nutgram\Telegram\Types\Input\InputSticker;
use SergiX44\Nutgram\Telegram\Types\Internal\InputFile;
use SergiX44\Nutgram\Telegram\Types\Keyboard\ForceReply;
use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup;
Expand Down Expand Up @@ -32,6 +33,8 @@ trait Stickers
* upload a new one using multipart/form-data.
* {@see https://core.telegram.org/bots/api#sending-files More info on Sending Files »}
* @param array{
* message_thread_id?:int,
* emoji?:string,
* disable_notification?:bool,
* protect_content?:bool,
* reply_to_message_id?:int,
Expand Down Expand Up @@ -63,19 +66,21 @@ public function getStickerSet(string $name): ?StickerSet
* and addStickerToSet methods (can be used multiple times).
* Returns the uploaded {@see https://core.telegram.org/bots/api#file File} on success.
* @see https://core.telegram.org/bots/api#uploadstickerfile
* @param mixed $png_sticker PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not
* exceed 512px, and either width or height must be exactly 512px.
* {@see https://core.telegram.org/bots/api#sending-files More info on Sending Files »}
* @param array $opt
* @param mixed $sticker A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format.
* See {@see https://core.telegram.org/stickers https://core.telegram.org/stickers} for technical requirements.
* {@see https://core.telegram.org/bots/api#sending-files More info on Sending Files »}
* @param array{
* sticker_format?:string,
* } $opt
* @param array $clientOpt
* @return File|null
*/
public function uploadStickerFile(mixed $png_sticker, array $opt = [], array $clientOpt = []): ?File
public function uploadStickerFile(mixed $sticker, array $opt = [], array $clientOpt = []): ?File
{
$user_id = $this->userId();
$required = compact('user_id', 'png_sticker');
$required = compact('user_id', 'sticker');

if (is_resource($png_sticker)) {
if (is_resource($sticker)) {
return $this->requestMultipart(__FUNCTION__, array_merge($required, $opt), File::class, $clientOpt);
}

Expand All @@ -85,20 +90,17 @@ public function uploadStickerFile(mixed $png_sticker, array $opt = [], array $cl
/**
* Use this method to create a new sticker set owned by a user.
* The bot will be able to edit the sticker set thus created.
* You must use exactly one of the fields png_sticker or tgs_sticker.
* Returns True on success.
* @see https://core.telegram.org/bots/api#createnewstickerset
* @param string $name User identifier of created sticker set owner
* @param string $title Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can
* contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive
* underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
* @param array{
* png_sticker?:InputFile|string,
* tgs_sticker?:InputFile,
* webm_sticker?:InputFile,
* stickers?:InputSticker[],
* sticker_format?:string,
* sticker_type?:string,
* emojis?:string,
* mask_position?:MaskPosition
* needs_repainting?:bool,
* } $opt
* @param array $clientOpt
* @return bool|null
Expand All @@ -119,11 +121,7 @@ public function createNewStickerSet(string $name, string $title, array $opt = []
* @see https://core.telegram.org/bots/api#addstickertoset
* @param string $name Sticker set name
* @param array{
* png_sticker?:InputFile|string,
* tgs_sticker?:InputFile,
* webm_sticker?:InputFile,
* emojis?:string,
* mask_position?:MaskPosition
* stickers?:InputSticker,
* } $opt
* @param array $clientOpt
* @return bool|null
Expand All @@ -147,6 +145,21 @@ public function setStickerPositionInSet(string $sticker, int $position): ?bool
return $this->requestJson(__FUNCTION__, compact('sticker', 'position'));
}

/**
* Use this method to set the thumbnail of a custom emoji sticker set.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
* @param string $name Sticker set name
* @param array{
* custom_emoji_id?:string,
* } $opt
* @return bool
*/
public function setCustomEmojiStickerSetThumbnail(string $name, array $opt = []): bool
{
return $this->requestJson(__FUNCTION__, array_merge(compact('name'), $opt));
}

/**
* Use this method to delete a sticker from a set created by the bot. Returns True on success.
* @see https://core.telegram.org/bots/api#deletestickerfromset
Expand All @@ -158,6 +171,51 @@ public function deleteStickerFromSet(string $sticker): ?bool
return $this->requestJson(__FUNCTION__, compact('sticker'));
}

/**
* Use this method to change the list of emoji assigned to a regular or custom emoji sticker.
* The sticker must belong to a sticker set created by the bot.
* Returns True on success.
* @param string $sticker File identifier of the sticker
* @param array $emoji_list A list of 1-20 emoji associated with the sticker
* @return bool
*/
public function setStickerEmojiList(string $sticker, array $emoji_list): bool
{
return $this->requestJson(__FUNCTION__, compact('sticker', 'emoji_list'));
}

/**
* Use this method to change search keywords assigned to a regular or custom emoji sticker.
* The sticker must belong to a sticker set created by the bot.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setstickerkeywords
* @param string $sticker File identifier of the sticker
* @param array{
* keywords?:string[],
* } $opt
* @return bool
*/
public function setStickerKeywords(string $sticker, array $opt = []): bool
{
return $this->requestJson(__FUNCTION__, array_merge(compact('sticker'), $opt));
}

/**
* Use this method to change the mask position of a mask sticker.
* The sticker must belong to a sticker set that was created by the bot.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setstickermaskposition
* @param string $sticker
* @param array{
* mask_position?:MaskPosition[],
* } $opt
* @return bool
*/
public function setStickerMaskPosition(string $sticker, array $opt = []): bool
{
return $this->requestJson(__FUNCTION__, array_merge(compact('sticker'), $opt));
}

/**
* Use this method to set the thumbnail of a sticker set.
* Animated thumbnails can be set for animated sticker sets only.
Expand All @@ -170,7 +228,7 @@ public function deleteStickerFromSet(string $sticker): ?bool
* @param array $clientOpt
* @return bool|null
*/
public function setStickerSetThumb(string $name, array $opt = [], array $clientOpt = []): ?bool
public function setStickerSetThumbnail(string $name, array $opt = [], array $clientOpt = []): ?bool
{
$user_id = $this->userId();
$required = compact('user_id', 'name');
Expand All @@ -188,4 +246,29 @@ public function getCustomEmojiStickers(array $emoji_ids): ?array
{
return $this->requestJson(__FUNCTION__, $emoji_ids, Sticker::class);
}

/**
* Use this method to set the title of a created sticker set.
* Returns True on success.
* @see https://core.telegram.org/bots/api#setstickersettitle
* @param string $name Sticker set name
* @param string $title Sticker set title, 1-64 characters
* @return bool
*/
public function setStickerSetTitle(string $name, string $title): bool
{
return $this->requestJson(__FUNCTION__, compact('name', 'title'));
}

/**
* Use this method to delete a sticker set that was created by the bot.
* Returns True on success.
* @see https://core.telegram.org/bots/api#deletestickerset
* @param string $name Sticker set name
* @return bool
*/
public function deleteStickerSet(string $name): bool
{
return $this->requestJson(__FUNCTION__, compact('name'));
}
}
1 change: 0 additions & 1 deletion src/Telegram/Types/Chat/ChatAdministratorRights.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
class ChatAdministratorRights extends BaseType
{

/**
* True, if the user's presence in the chat is hidden
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Telegram/Types/Description/BotDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SergiX44\Nutgram\Telegram\Types\Description;

use SergiX44\Nutgram\Telegram\Types\BaseType;

/**
* This object represents the bot's description.
* @see https://core.telegram.org/bots/api#botdescription
*/
class BotDescription extends BaseType
{
/**
* The bot's description
*/
public string $description;
}
17 changes: 17 additions & 0 deletions src/Telegram/Types/Description/BotShortDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SergiX44\Nutgram\Telegram\Types\Description;

use SergiX44\Nutgram\Telegram\Types\BaseType;

/**
* This object represents the bot's short description.
* @see https://core.telegram.org/bots/api#botshortdescription
*/
class BotShortDescription extends BaseType
{
/**
* The bot's short description
*/
public string $short_description;
}
Loading