34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
const { TelegramClient } = require("telegram");
|
|
const { StringSession } = require("telegram/sessions");
|
|
const input = require("input");
|
|
|
|
async function main () {
|
|
const apiId = +(await input.text("Enter API_ID:"));
|
|
if (Number.isNaN(apiId)) {
|
|
throw new Error("Invalid API_ID. Must be integer");
|
|
}
|
|
const apiHash = await input.text("Enter API_HASH:");
|
|
const stringSession = new StringSession("");
|
|
|
|
const client = new TelegramClient(stringSession, apiId, apiHash, {
|
|
connectionRetries: 5,
|
|
});
|
|
await client.start({
|
|
phoneNumber: async () => await input.text("Please enter your number: "),
|
|
password: async () => await input.password("Please enter your password: "),
|
|
phoneCode: async () =>
|
|
await input.text("Please enter the code you received: "),
|
|
onError: (err) => console.log(err),
|
|
});
|
|
console.log("You should now be connected.");
|
|
console.log("Your SESSION_ID:", client.session.save());
|
|
}
|
|
|
|
main().then(() => {
|
|
console.log("Program finished");
|
|
process.exit(0);
|
|
}).catch(err => {
|
|
console.error(err);
|
|
process.exit(-1);
|
|
});
|