简体   繁体   中英

How to request contact in C# Telegram Bot API

I want to make a contact request using a keyboard button in Telegram Bot API for C#. I know I have to do this with the request_contact method. But I did not find any source that would explain this in C#. (All resources were related to Python and PHP) Please explain this in C# language. Thankful

Use ReplyKeyboardMarkup with KeyboardButton that requests Contact and if the button was pressed telegam will let user send a contact.

And to show the keyboard, you must use it in SendTextMessageAsync as parameter like this:

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM