Answer the question
In order to leave comments, you need to log in
Why does the Telegram bot API method answerCallbackQuery not show an alert?
I'm trying to show an alert like this in telegram.
My test code is something like this:
$url = "https://api.telegram.org/botTOKEN/answerCallbackQuery";
$response = file_get_contents($url."?callback_query_id=". $callback_query_id ."&text=SUCCESS&show_alert=true");
{ "ok": true, "result": true }
, so I think the $callback_query_id parameter is correct. Answer the question
In order to leave comments, you need to log in
The problem was in the library that I used https://github.com/php-telegram-bot/core
If you receive updates from telegram using the handleGetUpdates() method of this library, then the library itself sends empty responses to the CallbackQuery.
It turns out that I tried to answer the same CallbackQuery again, the answer from Telegram comes - OK, but in reality Telegram processed only the first answer, which was automatically sent by the library.
try this:
$tg = json_decode(file_get_contents('php://input'), true);
function tlgrm($method, $data, $client) {
$data["parse_mode"] = "html";
$ch = curl_init("https://api.telegram.org/---токен---/$method");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_close($ch);
}
$client = $tg['callback_query']['from']['id'];
$cb_id = $tg['callback_query']['id'];
tlgrm('answerCallbackQuery', ['callback_query_id'=> $cb_id, 'text' => 'СООБЩЕНИЕ', 'show_alert' => true],$client);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question