-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
executable file
·56 lines (51 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
const { TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");
const input = require("input");
const { Logger } = require("telegram/extensions");
const boxen = require("boxen");
const chalk = require("chalk");
const clear = require("clear");
Logger.setLevel("none");
(async () => {
clear();
const welcome = `${chalk.bold.greenBright(
"Welcome To"
)} ${chalk.bold.greenBright("TG Session Generator")}`;
const box = boxen(welcome, { padding: 1, borderColor: "cyan" });
console.log(box);
const apiId = await input.text("API ID :");
if (!apiId) {
console.log(`${chalk.bold.redBright("Error No Id Provided")}`);
console.log(`${chalk.red("Exitting...")}`);
process.exit(0);
} else if (isNaN(apiId)) {
console.log(`${chalk.bold.redBright("API ID must be a number")}`);
console.log(`${chalk.red("Exitting...")}`);
process.exit(0);
}
const apiHash = await input.text("API HASH :");
if (!apiHash) {
console.log(`${chalk.bold.redBright("Error No Hash Provided")}`);
console.log(`${chalk.red("Exitting...")}`);
process.exit(0);
}
const stringSession = new StringSession("");
const client = new TelegramClient(stringSession, Number(apiId), apiHash, {
connectionRetries: 5,
});
await client.start({
phoneNumber: async () => await input.text("Number :"),
password: async () => await input.text("Password: "),
phoneCode: async () => await input.text("Code : "),
onError: (err) => {
console.log(err);
},
});
console.log(`${chalk.bold.greenBright("Connected to Telegram")}`);
console.log("Done! \n Now Check Your Saved Messages for Session String");
await client.sendMessage("me", {
message: `Generated Session String \n ${client.session.save()}`,
});
process.exit(0);
})();