电报机器人内联键盘回调不工作



我使用PHP的电报机器人。回复回调在回调击中回调URL时工作,但内联键盘回调不工作。当我点击内联键盘按钮时,没有反应,为什么会这样?请帮我解决这个问题。


$update = file_get_contents('php://input');
$update = json_decode($update, true);
$userChatId = $update["message"]["chat"]["id"]?$update["message"]["chat"]["id"]:null;
if($userChatId){
$userMessage = $update["message"]["text"]?$update["message"]["text"]:"Nothing";
$firstName = $update["message"]["from"]["first_name"]?$update["message"]["from"]["first_name"]:"N/A";
$lastName = $update["message"]["from"]["last_name"]?$update["message"]["from"]["last_name"]:"N/A";
$fullName = $firstName." ".$lastName;
$callback_query = $update['callback_query'];
$callback_query_data = $callback_query['data'];

$url = "https://webhook.site/f695055e-5a65-4120-9ea2-0581667bbd61?kk=";
if(isset($callback_query)){
file_get_contents($url.$callback_query_data);
}
if($userMessage == "/start"){

$replyMsg = "Welcome to Bot";

$keyboard = [
'inline_keyboard' => [
[
['text' => 'Button 1', 'callback_data' => '1'],['text' => 'Button 2', 'callback_data' => '2']
],
[
['text' => 'Button 3', 'callback_data' => '3']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters = array(
"chat_id" => $userChatId,
"text" => $replyMsg,
'reply_markup' => $encodedKeyboard
);
send("sendMessage", $parameters);
}
}
function send($method, $data){
$BOT_TOKEN = "Telegram_key";
$url = "https://api.telegram.org/bot$BOT_TOKEN/$method";
if(!$curld = curl_init()){
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $data);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close($curld);
return $output;
}
?> ```

您是否实现了响应回调查询的东西?

当您收到一个更新对象时,您可以检查callback_query字段是否有data字段包含字符串的CallbackQuery对象。像处理普通消息一样处理它:https://core.telegram.org/bots/api callbackquery

注意:用户按回拨按钮后,Telegram客户端将显示进度条,直到调用answerCallbackQuery。它是什么,因此,有必要通过调用answerCallbackQuery作出反应,即使不需要通知用户(例如,不指定任何的)(可选参数)

最新更新