2016-08-05 24 views
1

我的機器人不斷回覆郵件,我該如何阻止它?它正在讀取/ getupdates中的數據。我需要某種回覆發送變量,但不知道如何實現它如何阻止我的電報機器人多次回覆郵件

<?php 

$page = $_SERVER['PHP_SELF']; 
$sec = "60"; 

$bottoken = "218567218:AAGQMx6lYCOhRapUXxIG5b0EkXTQOJ5y3uw"; 
$website = "https://api.telegram.org/bot".$bottoken; 


$update = file_get_contents($website."/getupdates"); 

$updatearray = json_decode($update, TRUE); 

$length = count($updatearray["result"]); 
$chatid = $updatearray["result"][$length-1]["message"]["chat"]["id"]; 
$text = $updatearray["result"][$length-1]["message"]["text"]; 

if($text == 'hi'){ 
    file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=hello"); 

} 
elseif($text == 'bye'){ 
    file_get_contents($website."/sendmessage?chat_id=".$chatid."&text=piss off"); 
} 

?> 

<html> 
    <head> 
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'"> 
    </head> 
    <body> 
    </body> 
</html> 

回答

4

您可以在PHP中使用memcache或者簡單地使用數據庫。

將最後的update_id存儲在memcache或您的數據庫中。這樣你就知道什麼信息已經被回答了。下一次,你可以得到最後的update_id,增加它,然後得到新的消息來回復。

根據電報api文件,您可以通過最後update_id +1作爲offset param到getUpdates

+0

如何獲得停止命令以避免向未訂閱的用戶發送廣播消息? –