public getUpdates ( $offset, $limit = 100, $timeout, $update = true ) |
public function getUpdates($offset = 0, $limit = 100, $timeout = 0, $update = true)
{
$content = array('offset' => $offset, 'limit' => $limit, 'timeout' => $timeout);
$this->updates = $this->endpoint("getUpdates", $content);
if ($update) {
if (count($this->updates["result"]) >= 1) {
//for CLI working.
$last_element_id = $this->updates["result"][count($this->updates["result"]) - 1]["update_id"] + 1;
$content = array('offset' => $last_element_id, 'limit' => "1", 'timeout' => $timeout);
$this->endpoint("getUpdates", $content);
}
}
return $this->updates;
}
<?php /** * Telegram Bot Example whitout WebHook. * It uses getUpdates Telegram's API. * @author Gabriele Grillo <*****@*****.**> */ include "Telegram.php"; $bot_id = "bot_token"; $telegram = new Telegram($bot_id); // Get all the new updates and set the new correct update_id $req = $telegram->getUpdates(); for ($i = 0; $i < $telegram->UpdateCount(); $i++) { // You NEED to call serveUpdate before accessing the values of message in Telegram Class $telegram->serveUpdate($i); $text = $telegram->Text(); $chat_id = $telegram->ChatID(); if ($text == "/start") { $reply = "Working"; $content = array('chat_id' => $chat_id, 'text' => $reply); $telegram->sendMessage($content); } if ($text == "/test") { if ($telegram->messageFromGroup()) { $reply = "Chat Group"; } else { $reply = "Private Chat"; } // Create option for the custom keyboard. Array of array string $option = array(array("A", "B"), array("C", "D")); // Get the keyboard