Skip to content

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" => [
    ]], true);

    $url = "$token/sendMessage?chat_id=$chat_id&text=Choose&reply_markup=".$keyboard;
    $res = file_get_contents($url); 

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



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