/** * Handle getUpdates method * * @param int|null $limit * @param int|null $timeout * * @return \Longman\TelegramBot\Entities\ServerResponse */ public function handleGetUpdates($limit = null, $timeout = null) { if (!DB::isDbConnected()) { return new Entities\ServerResponse(['ok' => false, 'description' => 'getUpdates needs MySQL connection!'], $this->bot_name); } //DB Query $last_update = DB::selectTelegramUpdate(1); //As explained in the telegram bot api documentation $offset = isset($last_update[0]['id']) ? $last_update[0]['id'] + 1 : null; $response = Request::getUpdates(['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout]); if ($response->isOk()) { //Process all updates foreach ((array) $response->getResult() as $result) { $this->processUpdate($result); } } return $response; }
public function preExecute() { if (!$this->need_mysql | $this->need_mysql & $this->telegram->isDbEnabled() & DB::isDbConnected()) { return $this->execute(); } return $this->executeNoDB(); }
/** * Start a fake conversation for the passed command and return the randomly generated ids. * * @return array */ public static function startFakeConversation() { if (!DB::isDbConnected()) { return false; } //Just get some random values. $message_id = mt_rand(); $user_id = mt_rand(); $chat_id = mt_rand(); //Make sure we have a valid user and chat available. $message = self::getFakeMessageObject(['message_id' => $message_id], ['id' => $user_id], ['id' => $chat_id]); DB::insertMessageRequest($message); DB::insertUser($message->getFrom(), null, $message->getChat()); return compact('message_id', 'user_id', 'chat_id'); }