最-6ren">
gpt4 book ai didi

bots - 如何阻止我的电报机器人多次回复消息

转载 作者:行者123 更新时间:2023-12-02 04:07:24 25 4
gpt4 key购买 nike

我的机器人反复回复消息,我该如何阻止它?它正在从/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>

最佳答案

您可以在 PHP 中使用 memcache 或仅使用数据库。

将最后一个 update_id 存储在内存缓存或数据库中。这样您就知道哪些消息已经得到答复。下次您可以获取最后一个 update_id,将其递增,然后获取新的响应消息。

根据 Telegram api 文档,您可以将最后一个 update_id+1 作为 offset 参数传递给 getUpdates

关于bots - 如何阻止我的电报机器人多次回复消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38792566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com