Telegram-bot-sdk: How to answer callback query?

Created on 3 Jan 2019  路  2Comments  路  Source: irazasyed/telegram-bot-sdk

Here is my buttons:

    $keyboard = Keyboard::make()

       ->inline()

        ->row(
            Keyboard::inlineButton([
                'text'          => '馃嚭馃嚘 褍泻褉邪褩薪褋褜泻邪',
                'callback_data' => json_encode(['a' => 'firstLang', 'lang' => 'ua']),
            ]),
            Keyboard::inlineButton([
                'text'          => '馃嚪馃嚭 褉褍褋褋泻懈泄',
                'callback_data' => json_encode(['a' => 'firstLang', 'lang' => 'ru']),
            ]),
            Keyboard::inlineButton([
                'text'          => '馃嚭馃嚫 english',
                'callback_data' => json_encode(['a' => 'firstLang', 'lang' => 'en']),
            ])
        );

I handle them this way:

    $update = Telegram::getWebhookUpdates(); // todo check why is it deprecated
    $isCallback = $update->detectType() === 'callback_query';

    if ($isCallback) {

        $chatId = $update['callback_query']['message']['chat']['id'];

But how can I answer callback query?

Most helpful comment

What version of the SDK are you currently using? Are you using it in Laravel?

Based on your code , you just need simply call answerCallbackQuery() inside your if

If you're using develop version of the SDK:

Telegram::answerCallbackQuery([
    'callback_query_id' => $update->getId(),
    'cache_time' => 1
]);

If using v2:

Telegram::answerCallbackQuery([
    'callback_query_id' => $update['callback_query']['id'],
    'cache_time' => 1
]);

All 2 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

What version of the SDK are you currently using? Are you using it in Laravel?

Based on your code , you just need simply call answerCallbackQuery() inside your if

If you're using develop version of the SDK:

Telegram::answerCallbackQuery([
    'callback_query_id' => $update->getId(),
    'cache_time' => 1
]);

If using v2:

Telegram::answerCallbackQuery([
    'callback_query_id' => $update['callback_query']['id'],
    'cache_time' => 1
]);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

iMohammadd picture iMohammadd  路  3Comments

wlinh picture wlinh  路  3Comments

dswtech picture dswtech  路  4Comments

Enelar picture Enelar  路  3Comments

danilopinotti picture danilopinotti  路  3Comments