diff --git a/src/TgBotLib/Abstracts/EventType.php b/src/TgBotLib/Abstracts/EventType.php index bc3037b..c8c4a39 100644 --- a/src/TgBotLib/Abstracts/EventType.php +++ b/src/TgBotLib/Abstracts/EventType.php @@ -5,36 +5,22 @@ abstract class EventType { const GenericUpdate = 'generic_update'; - const Message = 'message'; - const EditedMessage = 'edited_message'; - const GenericCommandMessage = 'generic_command_message'; - const ChatMemberJoined = 'chat_member_joined'; - const ChatMemberLeft = 'chat_member_left'; - const ChatMemberKicked = 'chat_member_kicked'; - const ChatMemberBanned = 'chat_member_banned'; - const ChatMemberUnbanned = 'chat_member_unbanned'; - const ChatMemberPromoted = 'chat_member_promoted'; - const ChatMemberDemoted = 'chat_member_demoted'; - const ChatMemberRestricted = 'chat_member_restricted'; - const ChatMemberUnrestricted = 'chat_member_unrestricted'; - - const ChatMemberChanged = 'chat_member_changed'; const ChatTitleChanged = 'chat_title_changed'; const ChatPhotoChanged = 'chat_photo_changed'; + Const CallbackQuery = 'callback_query'; - const ChatDescriptionChanged = 'chat_description_changed'; } \ No newline at end of file diff --git a/src/TgBotLib/Bot.php b/src/TgBotLib/Bot.php index ad94486..2ca9859 100644 --- a/src/TgBotLib/Bot.php +++ b/src/TgBotLib/Bot.php @@ -6,6 +6,7 @@ use CURLFile; use CurlHandle; + use Exception; use InvalidArgumentException; use TgBotLib\Abstracts\ChatMemberStatus; use TgBotLib\Abstracts\EventType; @@ -129,6 +130,7 @@ * Sets whether the library will use SSL to send requests * * @param bool $ssl + * @noinspection PhpUnused */ public function setSsl(bool $ssl): void { @@ -405,6 +407,13 @@ $handler->handle($this, $update); } break; + + case EventType::CallbackQuery: + if(($update->getCallbackQuery() ?? null) !== null) + { + $handler->handle($this, $update); + } + break; } } @@ -2165,4 +2174,19 @@ ]); return true; } + + /** + * Public Destructor + */ + public function __destruct() + { + try + { + $this->close(); + } + catch(Exception $e) + { + unset($e); + } + } } \ No newline at end of file diff --git a/tests/commands/StartCommand.php b/tests/commands/StartCommand.php index c8193e6..e3ce303 100644 --- a/tests/commands/StartCommand.php +++ b/tests/commands/StartCommand.php @@ -18,6 +18,8 @@ public function handle(Bot $bot, Update $update): void { // reply to the incoming message - $bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName()); + $bot->sendMessage( + $update->getMessage()->getChat()->getId(), 'Hello, ' . $update->getMessage()->getFrom()->getFirstName() + ); } } \ No newline at end of file diff --git a/tests/get_updates.php b/tests/get_updates.php index 600b501..19db89c 100644 --- a/tests/get_updates.php +++ b/tests/get_updates.php @@ -1,13 +1,14 @@ setCommandHandler('start', new StartCommand()); + $bot = new TgBotLib\Bot('865804194:AAHTo9aIFP5X47dMYLJ6eoldHJnM6sc3LBc'); + $bot->setCommandHandler('start', new \commands\StartCommand()); - $bot->handleGetUpdates(true); \ No newline at end of file + print_r(json_encode($bot->getMe()->toArray()) . PHP_EOL); + $bot->sendMessage(570787098, 'Hello, world!'); + $bot->handleGetUpdates(); + unset($bot); \ No newline at end of file