telegram-api
telegram-api copied to clipboard
BUTTON_TYPE_INVALID when inline keyboard is used as reply_markup in InlineQueryResults
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.
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!
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.
can this do the trick? https://www.php.net/manual/en/function.array-filter.php
guys, do you know Telegram is going to add this opportunity? I mean setting pyment button to inline keyboard? Thanks
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”
@MrDarkest i tried it, i set only one pay button, got after that BUTTON_TYPE_INVALID. Maybe you know how to get it through?
This error is coming when sending a webApp button as reply markup of inline query result. This button is only button in markup
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.