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

BUTTON_TYPE_INVALID when inline keyboard is used as reply_markup in InlineQueryResults #110

Open
MrDarkest opened this issue Oct 21, 2019 · 8 comments
Assignees
Labels

Comments

@MrDarkest
Copy link
Contributor

Which version are you using?

3.5.0

Output:

Bad Request: BUTTON_TYPE_INVALID

Description of problem

When I set up a Markup object to use it in reply_markup property of Article class I get an error from Telegram:

Bad Request: BUTTON_TYPE_INVALID

Digging in the code I've find out that the problem is the button in the Markup.
I've set the Button like this:

$inlineKeyboard = new Markup();
$inlineKeyboardButton = new Button();
$inlineKeyboardButton->text = "Button text";
$inlineKeyboardButton->switch_inline_query = "inline_query";
$inlineKeyboard->inline_keyboard[][] = $inlineKeyboardButton;

and passed it to reply_markup property:

$inlineQueryResultArticle = new Article();
$inlineQueryResultArticle->title = "Answer Title";
$inlineQueryResultArticle->description = "Answer description";
[...]
$inlineQueryResultArticle->reply_markup = $inlineKeyboard;

But apparently Telegram dislike the "pay" and the "callback_game" properties of the Button in the json body if the button is used in AnswerInlineQuery even if they are null (in "callback_game" case) or false (in "pay" case).

I fixed temporary the problem by creating a new class (I called it "ButtonInlineAnswer") coping Button class, removing "pay" and "callback_game" properties and use this class instead of Button in the code before:

$inlineKeyboard = new Markup();
$inlineKeyboardButton = new ButtonInlineAnswer();
$inlineKeyboardButton->text = "Button text";
$inlineKeyboardButton->switch_inline_query = "inline_query";
$inlineKeyboard->inline_keyboard[][] = $inlineKeyboardButton;

If this can be accepted as solution I can open a pull request with this new class but if a better one can be found I'm glad to wait the official fix using mine meanwhile.

@unreal4u
Copy link
Owner

Oh, that should not happen. Any empty set of properties should not be populated, even if it is a subobject. I'll have a look at it and come back to you about it!

@unreal4u unreal4u added the bug label Oct 21, 2019
@unreal4u unreal4u self-assigned this Oct 21, 2019
@unreal4u
Copy link
Owner

The problem lies in the fact that the reply_markup button does not get cleaned in unreal4u\TelegramAPI\Telegram\Types\Inline\Query\Result::export():

Array
(
    [0] => Array
        (
            [type] => article
            [title] => Answer Title
            [description] => Answer description
            [id] => 123123
            [reply_markup] => unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup Object
                (
                    [inline_keyboard] => Array
                        (
                            [0] => Array
                                (
                                    [0] => unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Button Object
                                        (
                                            [text] => Button text
                                            [url] =>
                                            [login_url] =>
                                            [callback_data] =>
                                            [switch_inline_query] => inline_query
                                            [switch_inline_query_current_chat] =>
                                            [callback_game] =>
                                            [pay] =>
                                            [logger:protected] => unreal4u\Dummy\Logger Object
                                                (
                                                )

                                        )

                                )

                        )

                    [logger:protected] => unreal4u\Dummy\Logger Object
                        (
                        )

                )

        )

)

Since the Button is actually a Type and not a Method, I'll have to come up with some way of cleaning it. Creating a new object isn't the way to do this, maybe a recursive call to each sub-element is the solution, but I'm not really a fan of this either. I'll play around with some ideas.

@MrDarkest
Copy link
Contributor Author

can this do the trick? https://www.php.net/manual/en/function.array-filter.php

@kovaIenko
Copy link

guys, do you know Telegram is going to add this opportunity? I mean setting pyment button to inline keyboard? Thanks

@MrDarkest
Copy link
Contributor Author

guys, do you know Telegram is going to add this opportunity? I mean setting pyment button to inline keyboard? Thanks

You can do that already. Quoting Telegram docs: “This type of button (pay button) must always be the first button in the first row”

@kovaIenko
Copy link

@MrDarkest i tried it, i set only one pay button, got after that BUTTON_TYPE_INVALID. Maybe you know how to get it through?

@zero8d
Copy link

zero8d commented Jul 23, 2023

This error is coming when sending a webApp button as reply markup of inline query result. This button is only button in markup

@zero8d
Copy link

zero8d commented Jul 23, 2023

This error is coming when sending a webApp button as reply markup of inline query result. This button is only button in markup

Found this lines in the docs. Web app button is only available in private chats
Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answerWebAppQuery. Available only in private chats between a user and the bot.

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

No branches or pull requests

4 participants