我正在尝试用 PHP 开发 Telegram Bot,但是当我按下内联按钮时,我的机器人无法回答用户。有人可以在调用方法后
帮我发送消息(方法)吗?sendMessage
answerCallback
这是我最后的试用代码:
if ($call_back_query != null) {
$response = $call_back_query;
$botUrl = "https://api.telegram.org/bot" . BOT_TOKEN . "/answerCallbackQuery";
$postFields = array('callback_query_id' => $call_back_id, 'text' => $response);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $botUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$output = curl_exec($ch);
//send Text
$response = "help me if you can, i'm feeling down";
header("Content-Type: application/json");
$parameters = array('chat_id' => $chatId, "text" => $response);
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
}