-2
我试图编辑电报机器人中的消息。 我正在使用下面的代码。我可以发送没有问题的消息,但编辑消息部分不起作用。它只是没有做任何事情!在电报机器人中使用编辑消息
<?php
if ($_SERVER['HTTPS'] != "on") {
$url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: $url");
exit;
}
$botToken="XXXX...";
$website="https://api.telegram.org/bot".$botToken;
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
switch($message) {
case("action"):
sendMessage($chatId, "What should I do?");
break;
case("add"):
editMessageText($chatId, "should I add?");
break;
default:
sendMessage($chatId, "default");
}
function sendMessage($chatId, $message) {
$url = $GLOBALS[website]."/sendMessage? chat_id=".$chatId."&text=".urlencode($message)."&reply_markup".$reply1;
file_get_contents($url);
}
function editMessageText($chatId, $messageId, $message) {
$url = $GLOBALS[website]."/editMessageText?chat_id=".$chatId."&message_id=".$messageId."&text=".urlencode($message);
file_get_contents($url);
}
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
任何有关它可能会出错的想法? 感谢
这个问题过于笼统,没有办法知道这个问题的原因。 检查你是否使用了所有的变量,''file_get_contents''返回什么?,检查你是否使用完整的''url'''。 你也可以检查如果你打开一个带有特殊字符(比如空格)的URI,你需要使用urlencode()来编码URI。 –
开发时应该启用'error_reporting(-1)'。 '$ GLOBALS [网站]'应该警告你一些事情。除非你在定义常量小写时违反所有标准。 – Xorifelse
感谢您的意见。我添加了完整的代码! – Sorena