简体   繁体   English

用户共享联系人后如何保存用户的电话号码

[英]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.

相关问题 如何在ASP.NET核心确认用户email后才改变用户的Email - How to change user's Email in ASP.NET core only after he confirmed his email 怎样才能让object达到目标后变回原来的position呢? - How can I make the object move back to his original position after he reached the target? 用户已经登录后如何在其他帐户上登录? - How to login User on other account while he's already logged in on his? 如何在用户离线时发布到用户的墙上,通过我的应用更新他的令牌(如果已过期)。 C#Facebook SDK - How to post to a user's wall while he is offline,renew his token(if expired) via my app. C# Facebook SDK 用户如何在WinForm中循环期间更改其号码? - How can the user change his number during a loop in WinForm? 如何通过电话号码取得联系? - How to get contact by phone number? 如何使用GSMComm获取发件人的电话号码? - How can I get a sender's phone number using GSMComm? 如何将用户上传的图像保存到我以后可以访问的临时文件中,但之后会被删除 - How can I save a User's uploaded image to a temp file that I can access later, but gets deleted after that 如何将值添加到用户的属性,然后将其保存到数据库? - How can i add values to a user's properties and then save it to a database? 如何在Windows Phone 8.1上保存具有多个电话号码的联系人? - How to save a contact with multiple phone numbers on Windows Phone 8.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM