问题
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 sendshow my age
(which is that buttontext
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
.
回答1:
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
回答2:
Have you looked at InlineKeyboardMarkup instead of ReplyKeyboardMarkup? It can solve 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" 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.
来源:https://stackoverflow.com/questions/38524486/how-to-make-keyboard-button-message-text-different-from-its-caption-in-telegram