Closed sajadghobadi closed 5 years ago
You should check every constants to make sure they are valid first.
always surround all your codes with three `
@sajadghobadi How did you receive a phone code hash from a file? Looks like it does not exist at all
Hash is what you must inquire from the server
@zerobias Probably he split the login process into two parts: getCode and signIn.
@zerobias and @wfjsw thanks lot for response this error occurre for cheep!(sorry) mistake. i must pass phone_code_hash to signIn method but in truly i send undefined!!!
change and correct phone hash code to
const res = await telegram('auth.signIn', { phone_number: phone, phone_code_hash:phone_code_hash, phone_code: code })
please help me if you can. thnaks. sorry for my bad en
@zerobias you can't help?
@sajadghobadi Have you used the code as string or number type? Phone, code and hash fields must be string, not number.
I think this code should fails
const code = 12345
telegram('auth.signIn', { phone_number, phone_code_hash, phone_code: code })
So better to try this
const code = "12345"
telegram('auth.signIn', { phone_number, phone_code_hash, phone_code: code })
@sajadghobadi Hmm...Expired? You should try to understand it. The main problem is that you are too slow to get you authenticated. Try to be quick next time.
However, depend on what you are doing, there is a rare case. According to https://t.me/MadelineProto/23
#UndocumentedAPIChangeOfTheDay
Telegram automatically invalidates your login code if it is sent to any chat on telegram before the login, this problem can be avoided simply by appending or pretending some chars to the code.
Thanks to @usage_tg for finding that out.
Time to debug on your own.
@sajadghobadi I also had such a error until I request code and sent the result within one connection
(also make sure that you are using the same auth keypair for auth)
@FragsterAt how did you grab the code from telegram chat to the code automatically? , i am getting response only for phone_code_hash and phone_code sent from telegram official to my telegram chat.
I copied the login_code from app, try pasted in
client("auth.signIn", {
phone_number: number,
phone_code_hash: result.phone_code_hash,
phone_code: "39480",
}).then((result) => {
console.log("User:", result);
});
But always getting PHONE_CODE_EXPIRED
.
@wfjsw tried this but no luck appending or pretending return PHONE_CODE_INVALID Some one please help.
#UndocumentedAPIChangeOfTheDay
Telegram automatically invalidates your login code if it is sent to any chat on telegram before the login, this problem can be avoided simply by appending or pretending some chars to the code.
Thanks to @usage_tg for finding that out.
@javeedrahman please use three backticks for code blocks
@goodmind okay sure got it.
Here is the Sample code trying::
const phone = {
num : '+9199999999999',
code: '22222'
}
const config = {
// NOTE: if you FORK the project you MUST use your APP ID.
// Otherwise YOUR APPLICATION WILL BE BLOCKED BY TELEGRAM
// You can obtain your own APP ID for your application here: https://my.telegram.org
id : 49631,
hash: 'fb050b8f6771e15bfda5df2409931569'
}
var telegram = MTProto({
layer: 57,
api_id: config.id,
});
const run = async () => {
try {
const { phone_code_hash } = await telegram('auth.sendCode', {
phone_number : phone.num,
current_number: false,
api_id : config.id,
api_hash : config.hash
})
console.log('phone_code_hash', phone_code_hash)
res = await telegram('auth.signIn', {
phone_number: phone.num,
phone_code_hash,
phone_code : "83118"
})
console.log('signIn', res)
console.log('\n Logined as user')
console.dir(res.user, { colors: true })
} catch (err) {
console.log('err', err)
}
}
run()
@javeedrahman @sajadghobadi Were you able to figure this out?
here is sample when i receive activation code and use it to sign in telegram by below sample code get this error. RangeError: Wrong length! use babel for transcompile to es5. code :
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Wrong length!