Skip to content
Advertisement

inline keyboard on telegram error 400 bad request

I wanna send a json encoded keyboard as reply markup but I get error 400 bad requset!

This is how json looks like:

{"inline_keyboard":[[{"text":"Play, Guitar, Play - u003Cspan style="font-size:14px;"u003E Conway Twitty ","callback_data":"some url"}]]}

and this is how the code looks like:

 // Create keyboard
    $keyboard = json_encode([
        "inline_keyboard" => [
            $innerdata,
    ]], true);

    $url = "https://api.telegram.org/bot$token/sendMessage?chat_id=$chat_id&text=Choose&reply_markup=".$keyboard;
    $res = file_get_contents($url); 
        break;

I’ve also tried deleting one of the [ ] but it didn’t work.

Advertisement

Answer

I actually find the problem. It was a problem with data size. As Telegram says, the callback data should not be more than 64 bytes

And it can be fixed by:

if(strlen($callback_data) < 64){
//the rest of the code
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement