when i put apiId , apiHash , mobile nummber through the bot then i received phone_code of my telegram app, when i enter phone_code in bot then i received
code:
const author = async () => {
console.log("Loading interactive example...");
const client = new TelegramClient(stringSession, parseInt(API_ID), API_HASH, {
connectionRetries: 5,
});
await client.start({
phoneNumber: async () => {
await bot.sendMessage(chatId, 'Please enter phoneNumber.');
return new Promise((resolve) => {
bot.onText(/^+[0-9]+$/, async (msg) => { // Modify the regex pattern to allow '+' and digits
const phoneNumbers = msg.text;
resolve(phoneNumbers);
});
});
},
password: async () => {
await bot.sendMessage(chatId, 'Please Enter Password ');
return new Promise((resolve) => {
bot.onText(/^[a-zA-Z0-9]+$/, async (msg) => { // Modify the regex pattern to allow '+' and digits
const passwords = msg.text;
resolve(passwords);
await bot.sendMessage(chatId, 'Please Enter Code ');
});
});
},
phoneCode: async () => {
await bot.sendMessage(chatId, 'Please Enter Phone Code ');
return new Promise((resolve) => {
bot.onText(/^[0-9]+$/, async (msg) => { // Modify the regex pattern to allow digits
const phoneCodes = msg.text;
resolve(phoneCodes);
});
});
},
onError: (err) => console.log(err),
});
console.log("You should now be connected.");
const sessionString = client.session.save(); // Save this string to avoid logging in again
console.log(sessionString);
await bot.sendMessage(chatId, `Here is your session string: ${sessionString}`);
};
but intresting thing is when i only some changes in phoneCode key in code :
phoneCode: async () =>
await input.text("Please enter the code you received: "),
and enter phoneCode in terminal then i received session without any error.
i try to also put phoneCode using bot not to go to terminal and paste phone_code manually and save session.
2
Answers
write confirm code with spaces like:
1 2 3 4 5
and put the code without spaces (use
.trim()
method) into resolveSo basically Telegram watches if you are trying to send your code to somebody else, even to your bot.
If you do that, it expires immediately.
You simply can hide the real code, like instead of typing the real one like:
123456
you can provide something like1a2a3a4a5a6
and remove letters on your backed resulting it into original123456
. But you didn’t type exact123456
inside telegram, so it will be working.I did my own algo that just increases every number.
So in my case I input
012345
to get123456
code.