Closed kolko123 closed 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(); });
} }); }
`
how should i get the code?
`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
Do you have node 12version?
Do you have node 12version?
node v12.16.2
npm 6.14.4
code is working for me
code is working for me
I should specify only api_id and api_hash and phone number?
yes
yes
а что-то еще должно быть установлено?
are you recieving otp?
are you recieving otp?
what is it?
are you recieving the otp on telegram number
i don't get anything
are you recieving the otp on telegram number
type your mobile number in international format
type your mobile number in international format
it is introduced in an international format
https://github.com/somgupta13/Telegram-API/blob/master/som.js try this i have updated else show your code
https://github.com/somgupta13/Telegram-API/blob/master/som.js try this i have updated else show your code
same problem
@kolko123
@kolko123 if you don't send an info by may 11 I'll close the issue
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.
This error is probably fixed in version 3.1.1. View more: https://t.me/mtproto_core/17
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