Closed hit6 closed 3 years ago
I think phone code is 6 numbers not 5
Nah, I'm pretty sure it's 5. But anyway I've tried with multiple phoneCode lengths ranging from 1 to 10 and it's all the same. I get that error every single time.
well anyway, the issue in your case is that the code should be an integer, not a string so. const phoneCode = 22222;
Typescript will only accept an string there. Furthermore, if I force it to be an integer, it'll crash immediately:
...
...
const args = { phoneNumber, phoneCode: 22222, phoneCodeHash };
const result = await client.invoke(new (Api as any).auth.SignIn(args));
...
...
will result in:
/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/tl/generationHelpers.js:239
throw Error(`Bytes or str expected, not ${data.constructor.name}`);
^
Error: Bytes or str expected, not Number
at serializeBytes (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/tl/generationHelpers.js:239:19)
at argToBytes (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/tl/api.js:110:20)
at VirtualClass.getBytes (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/tl/api.js:294:42)
at new RequestState (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/network/RequestState.js:9:29)
at MTProtoSender.send (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/network/MTProtoSender.js:203:23)
at Object.<anonymous> (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/client/users.js:41:48)
at Generator.next (<anonymous>)
at fulfilled (/home/hit/Jobs/telegramApp/tgApp/node_modules/telegram/client/users.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
well just found the issue. it appears that you have the wrong IP somehow. this code worked and logged me in.
const phoneCode = "222222";
// yes it's 6 numbers
const createClient = async (stringSession?: string) => {
const session = new StringSession(stringSession);
const options = { connectionRetries: 5, baseLogger: new Logger("debug") };
const client = new TelegramClient(session, apiId, apiHash, options);
client.session.setDC(2, "149.154.167.40", 443); // notice how it's 40 not 50
await client.connect();
return client;
};
Yep, you are totally right I was using the production IP 🤦.
Also the 6 digit code works, the telegram documentation is wrong where they say:
https://core.telegram.org/api/auth#test-phone-numbers
A user like this would always get XXXXX as the login confirmation code (the DC number, repeated five times)
Thank you very much for your help :)
I'm trying to login using the test DC, as stated in telegram documentation: https://core.telegram.org/api/auth#test-phone-numbers
This is my code:
But I keep receiving RPCError: PHONE_CODE_INVALID again and again. Any ideas on why it's not woring?
Thanks.