[英]PHP - self destruct message telegram bot
I am building a telegram bot to send ads to my channels and I want them to be deleted after a certain period of time 我正在建立一个电报自动程序,将广告发送到我的频道,我希望在一段时间后将其删除
But I need to get message id to delete it, when I run code like this 但是当我运行这样的代码时,我需要获取消息ID才能将其删除
$update = json_decode(file_get_contents("php://input"));
$command = $update->message->text;
function message($mchat_id, $mtext)
{
global $token;
$ret=json_decode(file_get_contents('https://api.telegram.org/bot' .$token.'/sendMessage?chat_id='.$mchat_id.'&text='.$mtext.'&parse_mode=HTML'));
return $ret;
}
function delete($dchat_id, $dmsgid)
{
global $token;
file_get_contents('https://api.telegram.org/bot'.$token.'/deleteMessage?chat_id='.$dchat_id.'&message_id='.$dmsgid);
}
if($command == "/start")
{
$ret = message("$chat_id" , "$text");
$msgid = $ret->result->message_id;
$chatid = $ret->result->chat->id;
sleep(3600);
delete($chaid , $msgid);
}
It sends the text again and again every ~2 minutes forever and deletes each sent message after an hour. 它会每隔约2分钟一次又一次发送文本,并在一小时后删除每条发送的消息。
您使用了名为delete()的现有函数,只需对其进行重命名即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.