php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.79k stars 949 forks source link

forward inline_keyboard with data to command #1443

Closed MustafaTaj closed 4 months ago

MustafaTaj commented 4 months ago

Required Information

? !
Operating system Linux
PHP Telegram Bot version 0.82.0
PHP version 8.2.0
MySQL version none
Update Method Webhook
Self-signed certificate yes
RAW update (if available) {...}

Summary

am trying to use the survey command example using the example-bot. It works fine when I input /survey in the chat

but using an inline keyboard doesn't seem to make the wizard work propely

in CallbackqueryCommand.php I tried to use:

return $this->telegram->executeCommand('survey);

and it only shows the first step of the wizard and doesn't continue.

this is my code CallbackqueryCommand.php

 public function execute(): ServerResponse
    {
        // Callback query data can be fetched and handled accordingly.
        $callback_query = $this->getCallbackQuery();
        $callback_data = $callback_query->getData();

        return $this->telegram->executeCommand($callback_data);
}

this is my /start command code

 $inline_keyboard = new InlineKeyboard([
                ['text' => 'Start surevey', 'remove_keyboard' => true, 'callback_data' => 'survey'],
            ], [
                ['text' => 'more info', 'remove_keyboard' => true, 'callback_data' => 'info'],
            ]);
            Request::sendMessage([
                'chat_id' => $callback_query->getMessage()->getChat()->getId(),
                'text' => "choose option 👇',
                'reply_markup' => $inline_keyboard,
            ]);
jacklul commented 4 months ago

Example survey command was build using regular keyboards only, it won't work properly if you try to call it from the callback query handler command.

Have you looked at the example callbackquery and inlinekeyboard commands?

MustafaTaj commented 4 months ago

I solve it by modifying the command as follows:

[-] $this->conversation = new Conversation($user_id, $chat_id, $this->getName());

[+] $this->conversation = new Conversation($chat_id, $chat_id, $this->getName());

Hitmare commented 4 months ago

I'm not sure how good that works with chatID as userID in the database since it would cause a duplicate when 2 or more uses were start the survey from a group chat

I've come across the issue myself and wrote a pastebin how i solved it, using InlineKeyboard in a conversation

https://pastebin.com/qxQAekwj