C
C
CarpeDiem2016-07-26 23:04:21
Node.js
CarpeDiem, 2016-07-26 23:04:21

Sample code to check if a phone number is registered in Telegram?

There is a small task - to check if the phone number is registered in Telegram. There is no time to write your own implementation of TL and MTProto, I took the most mature NodeJs Telegram Client API library from github.
When trying to connect to the API, it gives an error: Client is not yet ready
The comment of the library developer on a similar problem is not very informative and applicable to my case - the person who created the issue did not make the code asynchronous. In my case, everything is asynchronous, but nevertheless it does not work as it should.
Dear experts, help to understand!
Issue on Github
An example of a working code on this library
PS There is an assumption that the telegram-link library I usedoes not provide for calling the auth.checkPhone method without authorization, although the Telegram API allows you to do this. I'm not very strong in NodeJS, so it's difficult to understand someone else's code, I need your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2017-02-06
@Fragster

This is how it works for me:

function checkPhone(phoneNumber) {
  return new Promise(function(resolve, reject) {
var client = telegramLink.createClient(app, datacenter, () => {
    client.createAuthKey((auth) => {
      client.auth.checkPhone(phoneNumber, (result) => {
        resolve(result);
    });
  });
  });}
        );
};

checkPhone(phone2).then(
        (result)=>{console.log('result', result);},
        (error)=>{console.log('error', error);}
        );

setTimeout(()=>{}, 20000);

without timeout terminates immediately.
Well, in general - I need help in implementing the missing API. Is there a complete implementation of the telegram API on node.js?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question