alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
632 stars 116 forks source link

unable to log in #40

Closed kolko123 closed 4 years ago

kolko123 commented 4 years ago

I use this code: https://github.com/alik0211/mtproto-core/blob/master/docs/authentication.md

I enter my api_id and api_hash and number, but writes auth.authorization: undefined

somgupta13 commented 4 years ago

`const { MTProto } = require('@mtproto/core'); const prompt = require('prompt');

const mtproto = new MTProto({ api_id: 105, api_hash: '85b728',

test: false, });

const phone = '+91808'; const code = '2222'; // const password = 'hellojs';

function sendCode(phone) { console.log("hello"); return mtproto.call('auth.sendCode', { api_id: 1056, api_hash: '85b72864f343b734', // current_number: false, phonenumber: phone, settings: { : 'codeSettings', }, }) // .catch(error=>{console.log(error)}); }

sendCode(phone) .catch(error => { if (error.error_message.includes('MIGRATE')) { const [type, nextDcId] = error.error_message.split('MIGRATE');

  mtproto.setDefaultDc(+nextDcId);

  return sendCode(phone).catch(error=>{console.log(error)});;

} }) .then( result => { f1(result.phone_code_hash);

})

async function f1(phone_code_hash){ prompt.start(); await prompt.get(['username'], async function (err, result) { if (err) { console.log(err); } else{ // console.log(phone,phone_code_hash,result.username); // console.log(typeof(result.username));

    const { user } = await mtproto.call('auth.signIn', {
        phone_number   : phone,
        phone_code_hash: phone_code_hash,
        phone_code     : result.username
    }).then(result => {
        console.log("Logged:", result);
        console.log("Logged:", result.user);

return result; }).catch(error => { console.log("ff") console.log(error); process.exit(); });

} }); }

`

kolko123 commented 4 years ago

how should i get the code?

kolko123 commented 4 years ago

`const { MTProto } = require('@mtproto/core'); const prompt = require('prompt');

const mtproto = new MTProto({ api_id: 105, api_hash: '85b728',

test: false, });

const phone = '+91808'; const code = '2222'; // const password = 'hellojs';

function sendCode(phone) { console.log("hello"); return mtproto.call('auth.sendCode', { api_id: 1056, api_hash: '85b72864f343b734', // current_number: false, phonenumber: phone, settings: { : 'codeSettings', }, }) // .catch(error=>{console.log(error)}); }

sendCode(phone) .catch(error => { if (error.error_message.includes('MIGRATE')) { const [type, nextDcId] = error.error_message.split('MIGRATE');

  mtproto.setDefaultDc(+nextDcId);

  return sendCode(phone).catch(error=>{console.log(error)});;

} }) .then( result => { f1(result.phone_code_hash);

})

async function f1(phone_code_hash){ prompt.start(); await prompt.get(['username'], async function (err, result) { if (err) { console.log(err); } else{ // console.log(phone,phone_code_hash,result.username); // console.log(typeof(result.username));

  const { user } = await mtproto.call('auth.signIn', {
      phone_number   : phone,
      phone_code_hash: phone_code_hash,
      phone_code     : result.username
  }).then(result => {
      console.log("Logged:", result);
      console.log("Logged:", result.user);

return result; }).catch(error => { console.log("ff") console.log(error); process.exit(); });

} }); }

`

hello (node:17837) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'phone_code_hash' of undefined

somgupta13 commented 4 years ago

https://github.com/somgupta13/Telegram-API/blob/master/som.js

kolko123 commented 4 years ago

https://github.com/somgupta13/Telegram-API/blob/master/som.js

same problem

somgupta13 commented 4 years ago

Do you have node 12version?

kolko123 commented 4 years ago

Do you have node 12version?

node v12.16.2

npm 6.14.4

somgupta13 commented 4 years ago

code is working for me

kolko123 commented 4 years ago

code is working for me

I should specify only api_id and api_hash and phone number?

somgupta13 commented 4 years ago

yes

kolko123 commented 4 years ago

yes

а что-то еще должно быть установлено?

somgupta13 commented 4 years ago

are you recieving otp?

kolko123 commented 4 years ago

are you recieving otp?

what is it?

somgupta13 commented 4 years ago

are you recieving the otp on telegram number

kolko123 commented 4 years ago

i don't get anything

are you recieving the otp on telegram number

somgupta13 commented 4 years ago

type your mobile number in international format

kolko123 commented 4 years ago

type your mobile number in international format

it is introduced in an international format

somgupta13 commented 4 years ago

https://github.com/somgupta13/Telegram-API/blob/master/som.js try this i have updated else show your code

kolko123 commented 4 years ago

https://github.com/somgupta13/Telegram-API/blob/master/som.js try this i have updated else show your code

same problem

alik0211 commented 4 years ago

@kolko123

  1. What version of the library do you use?
  2. Show your code
  3. Is Telegram blocked in your country? VPN enabled (try open telegram.org)?
alik0211 commented 4 years ago

@kolko123 if you don't send an info by may 11 I'll close the issue

flaviolacer commented 4 years ago

Version 3.1.0 keep stuck on promise

ex:

client.call('auth.signIn', {
            phone_number: state.phone_number,
            phone_code_hash: state.phone_code_hash,
            phone_code: state.code
        }).then(message => {
            console.log("Logged:", message); // never happen
            return message;  // never happen
        }).catch(error => {
            console.log(error);
            process.exit();
        });

On telegram app says that i logged.

alik0211 commented 4 years ago

This error is probably fixed in version 3.1.1. View more: https://t.me/mtproto_core/17