我的机器人反复回复一条消息我怎么能阻止它?它正在从/ 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>
答案 0 :(得分:4)
您可以在PHP中使用memcache或只使用数据库。
将最后update_id
存储在memcache或您的数据库中。这样你就知道已经回答了什么信息。下次你可以获得最后一个update_id
,增加它,然后获得新的响应消息。
根据Telegram api文档,您可以将update_id
+ 1作为offset
param传递给getUpdates
。