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
Asked
Active
Viewed 2,578 times
2

M-Jamiri
- 127
- 2
- 9
-
SO is not a tutorial site. This question is far too broad. – itsme86 Aug 14 '20 at 15:00
-
@itsme86 I didn't ask to learn. I just want to see an example of this command in C # – M-Jamiri Aug 14 '20 at 15:04
-
You and I have different interpretations of the word "explain" I guess. No one wants to help someone that just wants things given to them. You *should* want to learn. – itsme86 Aug 14 '20 at 15:08
1 Answers
3
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);
}

Eyad Mohammed Osama
- 656
- 5
- 27

Muaath
- 579
- 3
- 19