skip to Main Content

I have gone through many forums and API of telegram also.
But could not get the proper answer.

Well here is my main question.
I have list of users with their mobile numbers in my database and from all those, I want to send them messages on their telegram. So for that I will need their chat ID. How can I retrieve that by their MobileNumber? If I will have chat id, I am able to send message to them by using the following reference.

Telegram php example send message

I have visited the following link to get the chat id by manually from BOT by user itself. But I want automatic from script.

How to obtain Telegram chat_id for a specific user?

Thanks.

3

Answers


  1. You can’t use bots to find a user on Telegram using their phone number.

    Login or Signup to reply.
  2. I’m not familiar with PHP. 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());
    }
    

    I believe this can be done in PHP too.

    Login or Signup to reply.
  3. By Telegram bot you can send messages only to users that started chat with your bot. you can obtain their chat_id (not phone number) from received query.

    So you can not send message to another people even if you have their phone numbers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search