6

The following code works, it adds custom keyboard keys 'Button1' and 'Button2'

$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";

I need to use Inline Keyboard though for my purposes, but I haven't been able to get it to work

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

or

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

doesn't work. I would really appreciate if anyone has a working example or can point out what is wrong in my example.

Link to documentation: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating

1
  • It's unclear what you are asking here. What is your intention, what have you done, and what results do you get? "It doesn't work" is not a great place to start. Commented Jan 18, 2017 at 2:14

2 Answers 2

10

It looks like you are missing an additional array. The reply_markup should look like this:

$keyboard = array(
    "inline_keyboard" => array(array(array("text" => "My Button Text", "callback_data" => "myCallbackData")))
);
Sign up to request clarification or add additional context in comments.

Comments

-4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.