Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Keyboard Button message text different from its caption in Telegram bot API using C#

I need my bot to print a different message than its caption (which shows by telegram client on keyboard button element).

My custom button has this text: "Where am I?" and when I click on it, it prints on the screen "Where am I?" also. I want the button to print "/location".(something different from its text field)

How can I achieve it? I'm using C# and Telegram Bot API

EDIT:

What I want:

  • When the user clicks this button, telegram client send a messages with /age [as his typed message] but NOT send show my age (which is that button text field )

So: I want a button with a text . when the user clicks the button I want the message sent to be different from that text.

like image 819
Pier Giorgio Misley Avatar asked Jul 22 '16 10:07

Pier Giorgio Misley


2 Answers

Have you looked at InlineKeyboardMarkup instead of ReplyKeyboardMarkup? It solves your problem.


UPD
Basic usage

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

where "Text1" and "text1" are captions of the inline buttons, "Data1" and "data2" is CallbackQuery text, which your bot will receive when user clicks inline button.

Note, that bot sends not any message to user when he clicks inline button. If you need to send any message at that moment - you can do that programmatically.

like image 140
anatol Avatar answered Oct 19 '22 15:10

anatol


There is a boolean field for location, did you set it to true? https://core.telegram.org/bots/api#keyboardbutton

Update: hen you are sending a reply to the user, you are also sending a ReplyKeyboardMarkup. ReplyKeyboardMarkup has a field called keyboard which is Array of Array of KeyboardButton. on each KeyboardButton you have a bool for location that you need to set to true if you want that button to send the location

Update 2

it is not possible to have a message different than your text. text- String->Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed

like image 1
Ashkan S Avatar answered Oct 19 '22 16:10

Ashkan S