core: Callback not working in StartCommand

How to get data from callback_data ?

Required Information

  • Operating system: ubuntu 17.10
  • PHP version: php7.1-fpm
  • PHP Telegram Bot version: 0.52
  • Using MySQL database: yes
  • MySQL version: 5.7
  • Update Method: Webhook
  • Self-signed certificate: yes

Expected behaviour

In the logs there is an answer, but I dont see him in the bot. And me need save in cookie language code uz or ua.

Extra details


public function execute()
    {
        $lang = Lang::chooseLang();

        $inlineKeyboard = new InlineKeyboard([
            ['text' => 'Украинский', 'callback_data' => 'ua'],
            ['text' => 'Узбекский', 'callback_data' => 'uz'],
        ]);

        $data = [
            'chat_id' => $this->getMessage()->getChat()->getId(),
            'text' => $lang[ 'choose_lang' ],
            'reply_markup' => $inlineKeyboard
        ];
        Request::sendMessage($data); // its working

        $callbackAnswer = [
            'callback_query_id' => $this->getCallbackQuery()->getId(),
            'text'              => $this->getCallbackQuery()->getData(),
            'show_alert'        => true,
            'cache_time'        => 0
        ];

        return Request::answerCallbackQuery($callbackAnswer); // its not working
        // And i still tried  Request::sendMessage($callbackAnswer); // its not working too
    }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16

Most upvoted comments

They send generic text message on press. Handle with GenericmessageCommand.php & $this->getMessage()->getText(true)

The easiest way is to have something on the beggining of the callback data, examples:

lang_en
lang_ru
buy_3
buy_12

then you can explode('_', $callback_data) it. This way you can handle different callbacks.

Try putting callback query the code into CallbackqueryCommand.php system command instead.