Answer the question
In order to leave comments, you need to log in
Why does an error occur when processing the keyboard in telegram?
I made the bot display a message with ReplyKeyboardMarkup when I start the command, but for some reason the same error occurs - Bad Request: can't parse reply keyboard markup JSON object
Code without json_encode:
if (strpos($message, "/start") === 0) { // Команда start, вызов кнопки под чатом
$post = [
'chat_id' => $chat_id,
'text' => 'Напиши любое сообщение или нажми на кнопку ниже, чтобы начать!',
'reply_markup' => ['keyboard' => [],
'resize_keyboard' => true,
'one_time_keyboard' => true]
];
sendRequest('sendMessage', $post);
}
{
"chat_id": ххх,
"text": "Напиши любое сообщение или нажми на кнопку ниже, чтобы начать!",
"reply_markup": {
"keyboard": [
[
{
"text": "Открыть список коктейлей"
}
]
],
"resize_keyboard": true,
"one_time_keyboard": true
}
}
Bad Request: can't parse reply keyboard markup JSON object
function reply_keyboard($array) {
return json_encode(['keyboard' => $array]);
}
if (strpos($message, "/start") === 0) { // Команда start, вызов кнопки под чатом
$post = [
'chat_id' => $chat_id,
'text' => 'Напиши любое сообщение или нажми на кнопку ниже, чтобы начать!',
$cocktails_button = [],
'reply_markup' => [reply_keyboard($cocktails_button),
'resize_keyboard' => true,
'one_time_keyboard' => true]
];
sendRequest('sendMessage', $post);
}
{
"chat_id": ххх,
"text": "Напиши любое сообщение или нажми на кнопку ниже, чтобы начать!",
"0": [
[
{
"text": "Открыть список коктейлей"
}
]
],
"reply_markup": {
"0": "{\"keyboard\":}",
"resize_keyboard": true,
"one_time_keyboard": true
}
}
Bad Request: can't parse reply keyboard markup JSON object
"resize_keyboard": true, "one_time_keyboard": true
, everything worked for me, but I needed to add them so that the button at the bottom of the chat is not huge and after pressing it is removed, what I'm doing wrong - I don't understand
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question