Closed somgupta13 closed 4 years ago
@somgupta13
const prompt = require('prompt');
const fs = require('fs');
var data={};
const mtproto = new MTProto({
api_id:111XXX,
api_hash:'a115cc7ccbcc6e44XXXXXX',
test: false,
});
const phone = '+917024XXXX';
const code = '2222';
function sendCode(phone) {
return mtproto.call('auth.sendCode', {
api_id:111XXXX,
api_hash: 'a115cc7ccbcc6e445XXXXX',
// current_number: false,
phone_number: phone,
settings: {
_: 'codeSettings',
},
})
}
sendCode(phone)
.catch(error => {
if (error.error_message.includes('_MIGRATE_')) {
const [type, nextDcId] = error.error_message.split('_MIGRATE_');
mtproto.setDefaultDc(+nextDcId);
return sendCode(phone)
}
})
.then( result => {
f1(result.phone_code_hash);
})
async function f1(phone_code_hash){
prompt.start();
await prompt.get(['code'], async function (err, result) {
if (err) { console.log(err); }
else{
const { user } = await mtproto.call('auth.signIn', {
phone_number : phone,
phone_code_hash: phone_code_hash,
phone_code : result.code
},{syncAuth:false}).then(result => {
console.log('Logged:', result);
mtproto.call('help.getConfig').then(result=>{console.log(result.this_dc);});
mtproto.call('auth.exportAuthorization',{dc_id: 5},)
.catch(err=>{
console.log(err);
})
return result;
}).catch(error => {
console.log(error);
process.exit();
});
}
});
}
@somgupta13
.then
blocks.catch
blocksconst { MTProto } = require('@mtproto/core');
const prompt = require('prompt');
const fs = require('fs');
var data={};
const mtproto = new MTProto({
api_id:111XXX,
api_hash:'a115cc7ccbcc6e44XXXXXX',
test: false,
});
const phone = '+917024XXXX';
const code = '2222';
function sendCode(phone) {
return mtproto.call('auth.sendCode', {
api_id:111XXXX,
api_hash: 'a115cc7ccbcc6e445XXXXX',
// current_number: false,
phone_number: phone,
settings: {
_: 'codeSettings',
},
})
}
sendCode(phone)
.catch(error => {
if (error.error_message.includes('_MIGRATE_')) {
const [type, nextDcId] = error.error_message.split('_MIGRATE_');
mtproto.setDefaultDc(+nextDcId);
return sendCode(phone)
}
})
.then( result => {
f1(result.phone_code_hash);
})
async function f1(phone_code_hash){
prompt.start();
await prompt.get(['code'], async function (err, result) {
if (err) { console.log(err); }
else{
const { user } = await mtproto.call('auth.signIn', {
phone_number : phone,
phone_code_hash: phone_code_hash,
phone_code : result.code
},{syncAuth:false}).then(result => {
console.log('Logged:', result);
mtproto.call('help.getConfig').then(result=>{console.log('result2',result.this_dc);});
mtproto.call('auth.exportAuthorization',{dc_id: 5},)
.catch(err=>{
console.log('error2',err);
})
return result;
}).catch(error => {
console.log(error);
process.exit();
});
}
});
}
results:
prompt: code: 44216
Logged: {
_: 'auth.authorization',
pFlags: {},
flags: 0,
user: {
_: 'user',
pFlags: { self: true },
flags: 1107,
id: 12331161,
access_hash: '202675752045680',
first_name: 'Sandhya',
phone: '91702464',
status: { _: 'userStatusOnline', expires: 1588600686 }
}
}
result2 5
error2 { _: 'rpc_error', error_code: 400, error_message: 'DC_ID_INVALID' }
@somgupta13
{ syncAuth: false }
auth.exportAuthorization
the dc_id
parameter must not be equal to the this_dc
. You are currently logged in to this_dc
actually if I delete the syncAuth:false it does not respond anything and the screen is holded more than 20 minutes due to copy of authorisation to all dc and i did not get any response back because it takes too long
if i want to make a call to any method it gives error migrate to 5th dc so i want the id and bytes to login to 5th dc so that i dont need to type phone code again and again
@somgupta13 you mean you need to keep your authorization?
@somgupta13 update to version 3.1.0. This may be fix you issue
can you give the example of how to get values from local storage so that we need to signIn again again via otp
You don't need to work with the storage. You log in once and that's it
@alik0211 by first time logging in it terminates the seesion and then again i need to login
@somgupta13
1."Remove folder with auth data" where is this present? 2.https://github.com/alik0211/mtproto-core/blob/master/src/__playground/node.js this code is not working for test =true it gives error that dc 5 not found and for test:false it does not give any ouput id does even executes sendcode
@somgupta13
Auth data is located in <path>
mtproto.call('messages.sendMessage',{
peer:{
_ :'inputPeerUser',
user_id:12707XXXX,
access_hash:93874605735XXX
},
message:"hiii",
random_id:6789
})
error { _: 'rpc_error', error_code: 400, error_message: 'PEER_ID_INVALID' }
sendMessages does not work with 3.1.1 but it works with 3.0.0
@somgupta13 the user_id
and access_hash
parameters are inserted in plain? You should get access_hash
value from the user constructor (it works for me) - https://core.telegram.org/constructor/inputPeerUser
yes i used that only it works in 3.0.0 but it does not work here
I don't understand you. Show the code!
if i have migrated to dcid=5 then while signing in my crendiatals are on dcid 5 so when i am using method exportAuthorization and passing dcid=5 it throws an error dcid invalid