1

I'm trying to show alert like this https://i.stack.imgur.com/0lSAk.png

My test code looks 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");

$response was { "ok": true, "result": true }, so I think parameter $callback_query_id is correct.

But alert didn't appear. That is the problem.

A tried other bots (not mine) and other devices, and they showed alerts properly. So, I'm pretty sure problem is not with my device or telegram application.

I also have tried CURL and some Telegram Bot libraries. But it could not help me.

maximw
  • 21
  • 5

1 Answers1

1

The problem was in the library I use and the way I use it. I use https://github.com/php-telegram-bot/core, and get updates from Telegram using handleGetUpdates() method. This library automatically sends empty response to answerCallbackQuery endpoint. So, I tried to respond to CallbackQuery one more time, after library had already responded. Telegram says OK to such API calls, but really handle only the first one.

maximw
  • 21
  • 5
  • And how did you solve it then with the API? Like getting a new callback ID or something? – hakre Jul 09 '21 at 22:27
  • I decided to use other library. Library https://github.com/php-telegram-bot/core uses classes with static properties. I.e. Longman\TelegramBot\Request class stores telegram client in static property. It makes using of 2 bots simultaneously pretty difficult. – maximw Jul 10 '21 at 08:05
  • ah, I see, yes I can imagine that. So there can be only one bot. – hakre Jul 10 '21 at 08:20