I was building a Telegram bot on Laravel using the library irazasyed/telegram-bot-sdk. I created inline buttons, but couldn't know how to handle click events.
Here is my code:
<?php
namespace App\TelegramCommands;
use Telegram\Bot\Commands\Command;
use Telegram\Bot\Keyboard\Keyboard;
class StartCommand extends Command
{
protected $name = "start";
protected $description = "Lets you get started";
public function handle()
{
$update = $this->getUpdate();
$keyboard = Keyboard::make()
->inline()
->row(
Keyboard::inlineButton(['text' => 'View User Manual', 'callback_data' => 'data1']),
Keyboard::inlineButton(['text' => 'View Demo Videos', 'callback_data' => 'data2'])
)
);
$response = $this->replyWithMessage([
'text' => 'What do you want to do?',
'reply_markup' => $keyboard
]);
}
}
How to respond when a user clicks one of the buttons?
You need to have a handler on your webhook request. Irazasyed's library implements only handlers for commands. Consider using westacks/telebot
- it has handlers classes where you can manually apply condition to handle incoming update
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.