zerobias / telegram-mtproto

Telegram client api (MTProto) library
MIT License
617 stars 136 forks source link

401 AUTH_KEY_EMPTY on sendCode #203

Closed ArielS1 closed 6 years ago

ArielS1 commented 6 years ago

When i'm trying to run this code:

function signIn(phone_number, phone_code, api_id, api_hash, dev) {
  const MTProto = require('telegram-mtproto').MTProto;
  return new Promise((resolve, reject) => {
    const client = MTProto({ dev }, { // dev = true
      api_id,
      layer: 57,
      initConnection: 0x69796de9
    });

    client('auth.sendCode', {
      phone_number,
      api_id,
      api_hash,
      current_number: false,
      phone_code,
    })
    .then(({ phone_code_hash }) => {
      client('auth.signIn', {
        phone_code_hash,
        phone_number,
        phone_code
      })
      .then(signInRes => {
        resolve(signInRes);
      })
      .catch(signInErr => {
        reject(signInErr);
      });
    })
    .catch(err => {
      reject(err);
    });
  });
}

and i get error in signIn: { "code": 401, "type": "AUTH_KEY_EMPTY" }

I'm not sure what is layer 57 and initConnection, and i'm not sure what to do with the public keys i got in my telegram app configuration page.

Does any of them has to do with this error?

Thanks

ArielS1 commented 6 years ago

My problem was that i have sent the object on the client initialization parameter on a malformed way