Ade*_*del 6 telegram python-telegram-bot telegram-bot
我想知道什么是最好的方法来知道手机号码是否已经注册到Telegram信使?
谢谢.
我对python不熟悉。但有一种方法可以做到这一点:
如你所知,你可以使用它在发送电报机器人接触phoneNumber的和firsName(不必是谁拥有该号码的联系人的真实名字)。
将联系人发送到一个chatID后(无论你选择什么chatID,都可以是你自己的个人聊天ID),你可以查找它的UserID。
现在,如果此人存在于 Telegram 中,您将获得一个代表他/她的 UserID 或 chatID 的长数字,但如果不存在,则该数字将为0。
在 C# 中,我使用这段代码来查看电报中是否存在电话号码,并且效果很好。
string s = "+44...."; //the phone number
var req2 = await bot.MakeRequestAsync(new SendContact(update.Message.Chat.Id, s, "Name"));
if(req2.Contact.UserId == 0)
{
Console.WriteLine("The contact does not exist in Telegram");
}else
{
Console.WriteLine("The contact exists in telegram with UserID:{0}",req2.Contact.UserId.ToString());
}
Run Code Online (Sandbox Code Playgroud)