Add GetUpdates method for fetching updates

This commit is contained in:
netkas 2024-11-01 12:44:54 -04:00
parent ead1347f34
commit 845a0d3b3c
2 changed files with 42 additions and 0 deletions

View file

@ -11,6 +11,7 @@
use TgBotLib\Methods\ForwardMessage;
use TgBotLib\Methods\ForwardMessages;
use TgBotLib\Methods\GetMe;
use TgBotLib\Methods\GetUpdates;
use TgBotLib\Methods\Logout;
use TgBotLib\Methods\SendAnimation;
use TgBotLib\Methods\SendAudio;
@ -31,6 +32,7 @@
enum Methods : string
{
case GET_UPDATES = 'getUpdates';
case GET_ME = 'getMe';
case LOGOUT = 'logOut';
case CLOSE = 'close';
@ -67,6 +69,7 @@
{
return match($this)
{
self::GET_UPDATES => GetUpdates::execute($bot, $parameters),
self::GET_ME => GetMe::execute($bot, $parameters),
self::LOGOUT => LogOut::execute($bot, $parameters),
self::CLOSE => Close::execute($bot, $parameters),

View file

@ -0,0 +1,39 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Objects\Update;
class GetUpdates extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): array
{
return array_map(
fn($update) => Update::fromArray($update),
self::executeCurl(self::buildPost($bot, Methods::GET_UPDATES->value, $parameters))['result']
);
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
// TODO: Implement getRequiredParameters() method.
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
// TODO: Implement getOptionalParameters() method.
}
}