2

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?

Ayenew Yihune
  • 1,059
  • 13
  • 19

1 Answers1

0

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

PunyFlash
  • 1,030
  • 1
  • 6
  • 12