Updated Methods

This commit is contained in:
netkas 2024-09-30 12:22:12 -04:00
parent 67230e35ba
commit 1e3824a87a
2 changed files with 12 additions and 1 deletions

View file

@ -4,6 +4,7 @@ namespace TgBotLib\Abstracts;
use CURLFile;
use CurlHandle;
use InvalidArgumentException;
use TgBotLib\Bot;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Interfaces\ObjectTypeInterface;
@ -17,6 +18,7 @@ abstract class Method
* @param array $parameters The parameters required for the bot command.
* @return ObjectTypeInterface|ObjectTypeInterface[]|mixed The result of the bot command.
* @throws TelegramException if the response from the bot command is not valid.
* @throws InvalidArgumentException if the required parameters are not provided.
*/
public abstract static function execute(Bot $bot, array $parameters=[]): mixed;
@ -96,7 +98,7 @@ abstract class Method
* @throws TelegramException if the response is not a valid array,
* or if the 'ok' field is not set or is false.
*/
protected static function executeCurl(CurlHandle $curl): array
protected static function executeCurl(CurlHandle $curl): mixed
{
$response = curl_exec($curl);
curl_close($curl);

View file

@ -4,11 +4,17 @@
use TgBotLib\Bot;
use TgBotLib\Exceptions\TelegramException;
use TgBotLib\Methods\Close;
use TgBotLib\Methods\GetMe;
use TgBotLib\Methods\Logout;
use TgBotLib\Methods\SendMessage;
enum Methods : string
{
case GET_ME = 'getMe';
case LOGOUT = 'logOut';
case CLOSE = 'close';
case SEND_MESSAGE = 'sendMessage';
/**
* Executes a command on the provided bot with the given parameters.
@ -23,6 +29,9 @@
return match($this)
{
self::GET_ME => GetMe::execute($bot, $parameters),
self::LOGOUT => LogOut::execute($bot, $parameters),
self::CLOSE => Close::execute($bot, $parameters),
self::SEND_MESSAGE => SendMessage::execute($bot, $parameters),
};
}
}