Add GetMyCommands method to TgBotLib

This commit is contained in:
netkas 2024-11-13 15:18:58 -05:00
parent c48dbda47b
commit c1d515de0c
2 changed files with 52 additions and 0 deletions

View file

@ -38,6 +38,7 @@
use TgBotLib\Methods\GetFile;
use TgBotLib\Methods\GetForumTopicIconStickers;
use TgBotLib\Methods\GetMe;
use TgBotLib\Methods\GetMyCommands;
use TgBotLib\Methods\GetUpdates;
use TgBotLib\Methods\GetUserChatBoosts;
use TgBotLib\Methods\GetUserProfilePhotos;
@ -164,6 +165,7 @@
case GET_BUSINESS_CONNECTION = 'getBusinessConnection';
case SET_MY_COMMANDS = 'setMyCommands';
case DELETE_MY_COMMANDS = 'deleteMyCommands';
case GET_MY_COMMANDS = 'getMyCommands';
/**
* Executes a command on the provided bot with the given parameters.
@ -255,6 +257,7 @@
self::GET_BUSINESS_CONNECTION => GetBusinessConnection::execute($bot, $parameters),
self::SET_MY_COMMANDS => SetMyCommands::execute($bot, $parameters),
self::DELETE_MY_COMMANDS => DeleteMyCommands::execute($bot, $parameters),
self::GET_MY_COMMANDS => GetMyCommands::execute($bot, $parameters),
};
}
}

View file

@ -0,0 +1,49 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\BotCommand;
use TgBotLib\Objects\ChatMember;
class GetMyCommands extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): array
{
if(isset($parameters['scope']) && $parameters['scope'] instanceof ObjectTypeInterface)
{
$parameters['scope'] = json_encode($parameters['scope']->toArray());
}
return array_map(
fn($update) => BotCommand::fromArray($update),
self::executeCurl(self::buildPost($bot, Methods::GET_MY_COMMANDS->value, $parameters))
);
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return null;
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'scope',
'language_code'
];
}
}