Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically check if a cell phone number is registered in the Telegram?

I was wondering about what is the best way to know if a cell phone number has registered to the Telegram messenger or not?

Thanks.

like image 537
Adel Avatar asked Nov 15 '15 10:11

Adel


1 Answers

I'm not familiar with python. but there is a way to do this:

As you know you can send a contact in telegram bot using its phoneNumber and a firsName (Doesn't need to be the real first name of the contact who owns that number).

After sending the contact to a chatID(no matter what chatID you choose, can be your own personal chat ID), you can look for its UserID.

Now if the person exists in Telegram you will get a long number that stands for his/her UserID or chatID but if not the long will be 0.

In C# I used this piece of code to see whether a phone number exists in telegram or not and it worked very well.

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());
}
like image 151
Naser.Sadeghi Avatar answered Nov 06 '22 14:11

Naser.Sadeghi