[英]How can I save user's phone number after he shared his contact
this is my telegram bot keyboardbuttons: 这是我的电报漫游器键盘按钮:
var keyboard = new ReplyKeyboardMarkup(new[]
{
new [] // first row
{
**new KeyboardButton("ارسال شماره تماس")
{
RequestContact = true
}**
},
new [] // last row
{
new KeyboardButton("درباره ما"),
new KeyboardButton("ارتباط با ما"),
}
});
How can I save user's phone number after he shared his contact? 共享联系人后如何保存用户的电话号码? (I want to get his phone number and check it with phone numbers in my database)
(我想获取他的电话号码,并与数据库中的电话号码进行比较)
I try this, but it doesn't work (The condition is not true): 我尝试了这个,但是不起作用(条件不正确):
if (message.Type == MessageType.ContactMessage)
{
Console.WriteLine("aaaa");
string ph = message.Contact.PhoneNumber;
await Bot.SendTextMessageAsync(message.Chat.Id, ph, replyMarkup: keyboard);
}
MrRoundRobin says: If the user presses the custom keyboard button with RequestContact = true you will receive an update with Update.Type == MessageUpdate and the contact information in Update.Message.Contact. MrRoundRobin说:如果用户使用RequestContact = true按下自定义键盘按钮,您将收到Update.Type == MessageUpdate的更新以及Update.Message.Contact中的联系信息。
https://github.com/MrRoundRobin/telegram.bot/issues/198 https://github.com/MrRoundRobin/telegram.bot/issues/198
I fix this problem by this part of code: 我通过这部分代码解决了这个问题:
static async Task GetContactPhoneNumber()
{
while (true)
{
var Updates = await Bot.GetUpdates();
foreach (var update in Updates)
{
Console.WriteLine("aaaa");
if (update.Type == UpdateType.MessageUpdate)
{
Console.WriteLine("bbb");
var cc = update.Message.Contact.PhoneNumber;
//string ph = message.Contact.PhoneNumber;
await Bot.SendTextMessageAsync(update.Message.Chat.Id, cc);
}
}
}
}
You can't access to phone number! 您无法访问电话号码! telegram bot doesn't return phone number of user.
电报漫游器不会返回用户的电话号码。 for sent message to all of your users you most using chat-id.
发送给您最常使用chat-id的所有用户的消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.