Add SetChatPermissions method to TgBotLib

This commit is contained in:
netkas 2024-11-06 00:23:10 -05:00
parent db3500d46e
commit 307521debc
2 changed files with 54 additions and 1 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Interfaces\ObjectTypeInterface;
class SetChatPermissions extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): true
{
if($parameters['permissions'] instanceof ObjectTypeInterface)
{
$parameters['permissions'] = json_encode($parameters['permissions']->toArray());
}
else
{
$parameters['permissions'] = json_encode($parameters['permissions']);
}
return (bool)$bot->sendRequest(Methods::SET_CHAT_PERMISSIONS->value, $parameters);
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'permissions'
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'use_independent_chat_permissions'
];
}
}