我想使用C#的Telegram Bot API中的键盘按钮进行联系请求。我知道我必须使用request_contact
方法来做这件事。但我在C#中找不到任何可以解释这一点的来源。(所有资源都与Python和PHP相关)请用C#语言解释。感恩
发布于 2020-08-22 12:17:57
对请求联系人的KeyboardButton
使用ReplyKeyboardMarkup
,如果按下按钮,telegam将让用户发送联系人。
要显示键盘,必须在SendTextMessageAsync
中将其用作参数,如下所示:
private static async void Bot_OnMessage(MessageEventArgs e)
{
// Defining Keyboard button that requests a contact
KeyboardButton button = KeyboardButton.WithRequestContact("Send contact"); // Right here, the string defines what text appears on the button
//Defining Keyboard that contains the button
ReplyKeyboardMarkup keyboard = new ReplyKeyboardMarkup(button);
// Send keyboard with message!
// https://github.com/TelegramBots/Telegram.Bot/blob/master/src/Telegram.Bot/TelegramBotClient.cs#L506
await Bot.SendTextMessageAsync(e.Message.Chat.Id, "Please send contact", replyMarkup: keyborad);
}
https://stackoverflow.com/questions/63415159
复制