Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How can I get data from onCbQueryData() #12

Closed
lamasfoker opened this issue Dec 5, 2020 · 2 comments
Closed

[Question] How can I get data from onCbQueryData() #12

lamasfoker opened this issue Dec 5, 2020 · 2 comments

Comments

@lamasfoker
Copy link

I wrote this code:

        $bot->onCommand('start', function (Context $ctx) {
            $kb = ['reply_markup' =>
                ['inline_keyboard' => [[
                    ['callback_data' => '1, 'text' => 'One'],
                    ['callback_data' => '2', 'text' => 'Two']
                ]], 'resize_keyboard' => true]
            ];
            $ctx->sendMessage("How many item would you to search?", $kb);
        });

        // This function is called when the returned data is '1' or '2'
        $bot->onCbQueryData(['1', '2'], function (Context $ctx) {
            $ctx->sendMessage("Ok Thanks!");
        });

How can I access the data inside onCbQueryData() function?
$ctx->getMessage() return null. I want to know if '1' or '2' is returned.
Thank you for the work.

@cheeghi
Copy link
Collaborator

cheeghi commented Dec 5, 2020

Hi, the callback query is returned in $ctx->getCallbackQuery() and not in $ctx->getMessage(). To access the data call $ctx->getCallbackQuery()->getData().

@lamasfoker
Copy link
Author

It's work, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants