Core: Callbackquery and InlineKeyboard example

Created on 11 May 2020  ยท  3Comments  ยท  Source: php-telegram-bot/core

โ“ Support Question

Hello, i want a complete example of using Callbackquery and InlineKeyboard.

My CallbackqueryCommand.php file :

<?php

/**
 * This file is part of the TelegramBot package.
 *
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;

/**
 * Callback query command
 */
class CallbackqueryCommand extends SystemCommand
{
    /**
     * @var callable[]
     */
    protected static $callbacks = [];

    /**
     * @var string
     */
    protected $name = 'callbackquery';

    /**
     * @var string
     */
    protected $description = 'Reply to callback query';

    /**
     * @var string
     */
    protected $version = '1.0.0';

    /**
     * Command execute method
     *
     * @return ServerResponse
     */
    public function execute()
    {
        // $callback_query = $this->getCallbackQuery();
        // $user_id        = $callback_query->getFrom()->getId();
        // $query_id       = $callback_query->getId();
        // $query_data     = $callback_query->getData();

        $answer         = null;
        $callback_query = $this->getCallbackQuery();

        // Call all registered callbacks.
        foreach (self::$callbacks as $callback) {
            $answer = $callback($callback_query);
        }

        return ($answer instanceof ServerResponse) ? $answer : $callback_query->answer();
    }

    /**
     * Add a new callback handler for callback queries.
     *
     * @param $callback
     */
    public static function addCallbackHandler($callback)
    {
        self::$callbacks[] = $callback;
    }

}
question

Most helpful comment

Hello

Here is a Example of a InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/InlinekeyboardCommand.php

and Here is a matched Example of the CallbackQuery to reponse to the InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/CallbackqueryCommand.php

BR
Hitmare

All 3 comments

Hello

Here is a Example of a InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/InlinekeyboardCommand.php

and Here is a matched Example of the CallbackQuery to reponse to the InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/CallbackqueryCommand.php

BR
Hitmare

Hello

Here is a Example of a InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/InlinekeyboardCommand.php

and Here is a matched Example of the CallbackQuery to reponse to the InlineKeyboard
https://github.com/php-telegram-bot/example-bot/blob/master/Commands/CallbackqueryCommand.php

BR
Hitmare

Thank you .

No Problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sayjeyhi picture sayjeyhi  ยท  3Comments

Bl0ck154 picture Bl0ck154  ยท  3Comments

abbe-cipher picture abbe-cipher  ยท  4Comments

mithek picture mithek  ยท  4Comments

sineverba picture sineverba  ยท  3Comments