getUpdates() public static method

Get updates
public static getUpdates ( array $data ) : ServerResponse
$data array
return Longman\TelegramBot\Entities\ServerResponse
Example #1
1
 /**
  * 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;
 }
Example #2
0
 /**
  * Handle getUpdates method
  *
  *
  */
 public function handleGetUpdates($limit = null, $timeout = null)
 {
     //DB Query
     $last_update = DB::selectTelegramUpdate(1);
     if (isset($last_update[0]['id'])) {
         //As explained in the telegram bot api documentation
         $offset = $last_update[0]['id'] + 1;
     } else {
         $offset = null;
     }
     $ServerResponse = Request::getUpdates(['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout]);
     if ($ServerResponse->isOk()) {
         $results = '';
         $n_update = count($ServerResponse->getResult());
         for ($a = 0; $a < $n_update; $a++) {
             $result = $this->processUpdate($ServerResponse->getResult()[$a]);
         }
     }
     return $ServerResponse;
 }
 /**
  * Handle getUpdates method
  *
  * @return \Longman\TelegramBot\Telegram
  */
 public function handleGetUpdates($limit = null, $timeout = null)
 {
     //DB Query
     $last_message = DB::selectMessages(1);
     if (isset($last_message[0]['update_id'])) {
         //As explained in the telegram bot api documentation
         $offset = $last_message[0]['update_id'] + 1;
     } else {
         $offset = null;
     }
     //arrive a server Response object
     $ServerResponse = Request::getUpdates(['offset' => $offset, 'limit' => $limit, 'timeout' => $timeout]);
     if ($ServerResponse->isOk()) {
         $results = '';
         $n_update = count($ServerResponse->getResult());
         for ($a = 0; $a < $n_update; $a++) {
             $result = $this->processUpdate($ServerResponse->getResult()[$a]);
         }
         print date('Y-m-d H:i:s', time()) . ' - Processed ' . $a . " updates\n";
     } else {
         print date('Y-m-d H:i:s', time()) . " - Fail fetch updates\n";
         echo $ServerResponse->printError() . "\n";
     }
     //return $results
 }
Example #4
0
 /**
  * Handle getUpdates method
  *
  * @param int|null $limit
  * @param int|null $timeout
  *
  * @return \Longman\TelegramBot\Entities\ServerResponse
  */
 public function handleGetUpdates($limit = null, $timeout = null)
 {
     //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;
 }