Closed temirovgroup closed 3 years ago
@temirovgroup Have you tried on different devices and Telegram apps? Various Telegram apps display the alerts differently.
Also, be sure to return the answer using return Request::answerCallbackQuery...
!
I tried it on different devices. Returns this:
{ "ok": true, "result": true, "raw_data": { "ok": true, "result": true }, "bot_username": "@chickenstore_bot" }
P.S. return Request::answerCallbackQuery...! - It's done. Not working
Please try this instead, inside your CallbackqueryCommand::execute
command, and let me know if that works.
Maybe the callback query ID you're passing is invalid?
public function execute(): ServerResponse
{
$callback_query = $this->getCallbackQuery();
// your code...
return $callback_query->answer([
'text' => 'OK',
'show_alert' => true,
]);
}
Excuse please. The problem was this:
$telegram = new Telegram(Yii::$app->params['telegram']['api_key'], Yii::$app->params['telegram']['bot_username']); $telegram->handle();
($telegram->handle();)
I don't know why I called him at all.. :))
Thank you for your answers. And a special thank you for your work!
Excuse please. The problem was this:
$telegram = new Telegram(Yii::$app->params['telegram']['api_key'], Yii::$app->params['telegram']['bot_username']); $telegram->handle();
($telegram->handle();)I don't know why I called him at all.. :))
This problem has plagued me 10H.. Thank you Soooooomuch
I encountered the same issue where I'd send an answerCallbackQuery
and Telegram responded with 200 OK
, but no notification appeared for the user.
I found this answer on StackOverflow mentioning:
The problem was with the library I was using and how I used it. Using the https://github.com/php-telegram-bot/core and the handleGetUpdates() method, the library automatically sends an empty response to answerCallbackQuery. I attempted to answer the CallbackQuery again after the library already did. Even though Telegram says OK, it only handles the first call.
So, I solved it by not using $telegram->handleGetUpdates()
.
Instead, I'm now using the \Longman\TelegramBot\Request::getUpdates($data)
method.
To use it directly, you still need to set up and create a Telegram
instance and then pass it to Request::initialize()
.
Like this:
use \Longman\TelegramBot\Request;
use \Longman\TelegramBot\Telegram;
$apiKey = "place_your_api_key_here";
$botUsername = "place_your_bot_username_here";
$telegram = new Telegram($apiKey, $botUsername);
Request::initialize($telegram);
$updates = Request::getUpdates([
// here is a place for your long polling request params
]);
I hope this helps!
@underwear How curious, I don't understand why it's not working for you, as the $telegram->handleGetUpdates()
"should" be doing the same thing.
Clearly the few extras it does, seem to be breaking something, but I've not encountered that yet.
FYI, no need to do Request::initialize
as the Telegram
constructor does that already for you.
What version of PHP are you on, and which version of the bot are you using?
PHP 7.4 (Shared hosting beget.com) Other commands are working successfully.
answerCallbackQuery not working. Everything is done correctly, returns a successful result. But there is no window in the chat (alert)
My code:
Request::answerCallbackQuery([ 'callback_query_id' => $callback_query_id, 'text' => 'OK', 'show_alert' => true, ]);
Please, help me :)