From 95e9118bfb5284428ffb66848c4901f9d8990c5c Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 1 Nov 2024 18:21:40 -0400 Subject: [PATCH] Enhance event handler selection in PollingBot --- src/TgBotLib/PollingBot.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/TgBotLib/PollingBot.php b/src/TgBotLib/PollingBot.php index da2534e..a3b6c42 100644 --- a/src/TgBotLib/PollingBot.php +++ b/src/TgBotLib/PollingBot.php @@ -89,10 +89,26 @@ $this->offset = $update->getUpdateId() + 1; } - /** @var UpdateEvent $eventHandler */ - foreach($this->getEventHandlersByType(Utilities::determineEventType($update)) as $eventHandler) + $updateByType = $this->getEventHandlersByType(Utilities::determineEventType($update)); + + if(count($updateByType) === 0) { - (new $eventHandler($update))->handle($this); + // If no event handlers are found appropriate for the update type, use the generic update event handler + // So that we don't miss any updates + /** @var UpdateEvent $eventHandler */ + foreach($this->getEventHandlersByType(UpdateEventType::UPDATE_EVENT) as $eventHandler) + { + (new $eventHandler($update))->handle($this); + } + } + else + { + // Otherwise, use the appropriate event handler for the update type + /** @var UpdateEvent $eventHandler */ + foreach($this->getEventHandlersByType(Utilities::determineEventType($update)) as $eventHandler) + { + (new $eventHandler($update))->handle($this); + } } } }