Mohammad
Mohammad

Reputation: 327

Telegram: add callback data to reply_markup

I am trying to add callback data to reply_markup.

This is my code:

$option[] = array("test");
$replyMarkup = array('keyboard'=>$option,'one_time_keyboard'=>false,'resize_keyboard'=>true,'selective'=>true);
$encodedMarkup = json_encode($replyMarkup,true); 

This code sends TEST to button and a call back to server TEST string for case

But I want use TEST string to show user and call back to server by KEY

This code does not work for me:

$option[] = array("text"=>"test","call_back"=>"key");

Upvotes: 0

Views: 4035

Answers (1)

mymedia
mymedia

Reputation: 617

It looks you try to use ReplyKeyboardMarkup. It defines a keyboard with templates of messages which an user can send by tapping on a button.

But you want to get specific key so take a look at InlineKeyboardMarkup for this.

$options[][] = array('text' => 'Your text', 'callback_data' => 'test-data');
$replyMarkup = array('inline_keyboard' => $options);
$encodedMarkup = json_encode($replyMarkup, true);

When an user presses the button, your bot will receive a special update, CallbackQuery.

Upvotes: 1

Related Questions