telegram-bot-sdk
telegram-bot-sdk copied to clipboard
callback not working with version 3.4
I have try many day for fix callback function but still not working. It show nothing when I click on inline keyboard. I have use all this in my custom command handle.
use Telegram;
use Telegram\Bot\Commands\Command;
use Telegram\Bot\Keyboard\Keyboard;
use Telegram\Bot\Objects\Update;
this is my handle function
public function handle()
{
$update = $this->telegram->getWebhookUpdate();
if ($update->isType('callback_query')) {
$this->telegram->sendMessage([
'chat_id' => "123456",
'parse_mode' => 'HTML',
'text' => 'ddd',
]);
} else {
$keyboard = json_encode([
"inline_keyboard" => [
[
[
"text" => "english",
"callback_data" => "/english"
],
[
"text" => "russian",
"callback_data" => "/russian"
]
]
]
]);
$this->telegram->sendMessage([
'chat_id' => $update->getMessage()->chat->id,
'text' => 'Text with inline button',
'reply_markup' => $keyboard
]);
}
}
Thank for help me
Hello, friend! It is possible that you have already solved the problem, but if not, I will answer you: I see the problem in several places. If we talk about your question, you do not have a handler function for callback_query data, therefore the buttons do not work the way you want.
I think your approach for creating a keyboard is wrong within the framework (you can do it much easier).
To create a keyboard, refer to the Keyboard(::make) class. After you have already initiated the creation of the object, create an instance of the inline button via object->row(Keyboard::inline()).
After you create the buttons, you will need a handler for callback calls. Describe it, and, based on the information in callback_query, call the functionality you need.
An example of creating a keyboard is shown in the screenshot.
"After you create the buttons, you will need a handler for callback calls. Describe it, and, based on the information in callback_query, call the functionality you need."
Hello, friend!
Tell me how to write a handler for a callback. Thanks!