skip to Main Content

I’ve got telegram bot in php, and I show custom keyboard doing :

$replyMarkup = array(
      'keyboard' => array(
           array('/help')
       )
);

$keyboard = json_encode($replyMarkup)

$this->client->request('POST', 'sendmessage', ['query' => ['chat_id' => $chatId, 'text' => $text, 'reply_markup' => $keyboard]]);

All works right.
My question is : is there a way to map a keyboard command to a different message?
So in this case i want to show custom keyboard that shows “Help” and on click send /help.

Thanks.

2

Answers


  1. For now, custom keyboard’s buttons are simply templates for messages, so “No, it’s not possible”.

    Login or Signup to reply.
  2. Using InlineKeyboardMarkup can solve this issue.

    Basic usage for C#

       public static InlineKeyboardMarkup TestInlineKeyboard { get; } = new InlineKeyboardMarkup           
        {
            InlineKeyboard = new []{new[] {new InlineKeyboardButton("Text1","Data1"),    
                                           new InlineKeyboardButton("text1","data2")} }
        };    
    

    where “Text1” and “text1” is captions on inline buttons, “Data1” and “data2” is CallbackQuery text that your bot will recieve when user clicks inline button. Note that bot not send any message to user when he clicks inline button. If you need to send any message at that moment – you can do that programmatically.
    Warning: Inline keyboards are currently being tested and are not available in channels yet. For now, feel free to use them in one-on-one chats or groups. but very good to know.

    Taked from this post.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search