Issues with Inline Keyboard in PHP Telegram Bot

I am attempting to set up an inline keyboard for my Telegram bot using PHP, but I’m facing some issues. My code for a standard keyboard works as expected:

$keyboard = [
    'keyboard' => [['Button1'], ['Button2']],
    'resize_keyboard' => true,
    'one_time_keyboard' => true,
    'selective' => true
];

$keyboard = json_encode($keyboard, true);

$sendto = API_URL . "sendmessage?chat_id=" . $chatID . "&text=" . $reply . "&parse_mode=HTML&reply_markup=$keyboard";

However, when I switch to using inline keyboards, I encounter problems and nothing appears. I’ve tried various methods:

$keyboard = [
    'inline_keyboard' => [['Button1' => 'test', 'callback_data' => 'test']]
];

and:

$keyboard = [
    'inline_keyboard' => [['Button1' => 'test'], ['callback_data' => 'test']]
];

Unfortunately, neither option displays any inline buttons. I am in need of the inline keyboard functionality for my specific requirements. Could someone please assist me in figuring out what might be wrong with my code or share a working example? It seems like I may have overlooked something in the formatting or the code structure.

Your button array structure is wrong. You’re using the wrong syntax for inline keyboard buttons. Each button needs both ‘text’ and ‘callback_data’ keys in the same array element.

Here’s the fix:

$keyboard = [
    'inline_keyboard' => [
        [['text' => 'Button1', 'callback_data' => 'test']]
    ]
];

I ran into this exact same issue when I started with Telegram bots. Inline keyboards are different from regular ones - each button has to be formatted as an object with specific properties. You were close, but you used ‘Button1’ as a key instead of the ‘text’ property. Once you get this working, don’t forget to add callback query handling so your bot can actually process the button clicks.

Your inline keyboard isn’t working because of the button structure. Each button needs to be an object with specific properties - you can’t use key-value pairs like you’re trying to do.

Here’s the correct format:

$keyboard = [
    'inline_keyboard' => [
        [['text' => 'Button1', 'callback_data' => 'test']],
        [['text' => 'Button2', 'callback_data' => 'test2']]
    ]
];

See how each button is an array with objects that have ‘text’ and ‘callback_data’ properties? The ‘text’ is what shows on the button, ‘callback_data’ is what gets sent back when someone clicks it. You were mixing regular keyboard format with inline keyboard format - that’s why nothing showed up. Don’t forget to handle the callback queries in your bot code too since inline keyboards work differently than regular ones.

yeah, ur button array’s messed up. try this:

$keyboard = [
    'inline_keyboard' => [
        [['text' => 'Button1', 'callback_data' => 'test']]
    ]
];

see how text and callback_data are separate properties? u mixed them. also, make sure ur bot handles callback queries or the buttons won’t work when clicked.