/** * Handle Bot API updates * * @param array $updates Updates from Bot API * * @return void */ public function handleBotApiUpdates(array $updates) { $updateId = $this->_lastUpdate->getBotUpdateId(); foreach ($updates['result'] as $update) { $message = trim($this->_updateHelper->getMessageText($update)); $updateId = $this->_updateHelper->getIncrementedUpdateId($update); if (!$this->_isCommandExist($this->_getCommandClassName($message))) { continue; } /** @var ICommand $commandModel */ $commandModel = $this->_di->get($this->_getCommandClassName($message)); $commandModel->execute($update); } $this->_lastUpdate->setData([Model\LastUpdate::UPDATE_COLUMN_NAME => $updateId])->saveBotUpdateId(); }
/** * Check updates * * @return void */ public function checkUpdates() { $updates = json_decode($this->_botApi->getUpdates($this->_lastUpdate->getBotUpdateId()), $assoc = true); $this->_updatesHandler->handleBotApiUpdates($updates); }