telegram-bot-sdk: Keyboard not work (webhook)

Hi, first of all thank you very much for your great work.

I have a problem sending a message with an options keyboard. Selecting an option displays a wait icon. The application does not receive the callback of the selected option.

My settings are as follows:

Laravel: 6.18.8 telegram-bot-skk: 3.1.0

File web.php

Route::post('/bot', function () {
    Telegram::commandsHandler(true);
    return 'ok';
});

Config file telegram.php

'bot_token' => env('TELEGRAM_BOT_TOKEN', 'YOUR-BOT-TOKEN'),
'async_requests' => env('TELEGRAM_ASYNC_REQUESTS', false),
'http_client_handler' => null,
'commands' => [
        Telegram\Bot\Commands\HelpCommand::class,
        ResumenDiarioCommand::class,
        BuscarCommand::class,

    ],

File MyCustomCommand.php

public function handle()
    {

        $update = $this->telegram->getWebhookUpdate();

        Log::info('handle');
        Log::info($update);

        if ($update->isType('callback_query')) {
            Log::info('...is callback');

        } else {

            Log::info('show keyboard...');


            $keyboard = Keyboard::make()
                ->inline()
                ->row(
                    Keyboard::inlineButton(['text' => 'DOE', 'callback_data' => 'doe']),
                    Keyboard::inlineButton(['text' => 'BOE', 'callback_data' => 'boe'])
                );

            $this->replyWithMessage([
                'chat_id'      => $this->dataRequest->chat()->id(),
                'text'         => 'Select',
                'reply_markup' => $keyboard
            ]);
        }

    }

also, I have configured a connection with Ngrok.

When the buttons are displayed, the following appears … and nothing happens. Captura de pantalla de 2020-04-20 14-46-58

I’ve reviewed a lot of documentation and issues but can’t find a solution. Thank you very much for your time.

A greeting.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19

Most upvoted comments

How i handle it:

$msg = $telegram->getWebhookUpdate()->getMessage();
if (!$message->getFrom()->isBot) {
    // do something with usual messages
} else {
   $cb = $telegram->getWebhookUpdate()->getCallbackQuery();
   $chatID = $cb->getId();
   $command = $cb->getData(); // here we receive 'callback_data' setted in created Menu
   switch ($command) {
      case .......
      default .......
   }
   $telegram->answerCallbackQuery([
        'callback_query_id' => $chatID,
        'text' => "CALLBACK RESPONSE",
        'show_alert' => true // if you need modal window, not popup info
    ]);
}

Where you have put the code? at routes/web.php ???

How i handle it:

$msg = $telegram->getWebhookUpdate()->getMessage();
if (!$message->getFrom()->isBot) {
    // do something with usual messages
} else {
   $cb = $telegram->getWebhookUpdate()->getCallbackQuery();
   $chatID = $cb->getId();
   $command = $cb->getData(); // here we receive 'callback_data' setted in created Menu
   switch ($command) {
      case .......
      default .......
   }
   $telegram->answerCallbackQuery([
        'callback_query_id' => $chatID,
        'text' => "CALLBACK RESPONSE",
        'show_alert' => true // if you need modal window, not popup info
    ]);
}

if anybody else stumbles upon the issue of non-working buttons, please check this answer https://stackoverflow.com/questions/62876048/telegram-inline-keyboard-button-not-working basically, revoke your token and try again. pavel durov says no. image

            Telegram::answerCallbackQuery([
                'callback_query_id' => $update->callbackQuery->get('id'),
                'text'  =>  __('Any text'),
            ]);

Do not forget to answer callback query

in your route web.php

Route::post('/bot', function () {
    $telegram =Telegram::commandsHandler(true);
if(!$telegram->isType('Command')){
//your new class called in here
}
    return 'ok';
});``