|
@@ -15,12 +15,6 @@ Install GramJS:
|
|
$ npm i telegram
|
|
$ npm i telegram
|
|
```
|
|
```
|
|
|
|
|
|
-Install [input package](https://www.npmjs.com/package/input), we'll use it to prompt ourselves inside terminal for login information:
|
|
|
|
-
|
|
|
|
-```bash
|
|
|
|
-$ npm i input
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
After installation, you'll need to obtain an API ID and hash:
|
|
After installation, you'll need to obtain an API ID and hash:
|
|
|
|
|
|
1. Login into your [telegram account](https://my.telegram.org/)
|
|
1. Login into your [telegram account](https://my.telegram.org/)
|
|
@@ -36,22 +30,35 @@ Then run this code to send a message to yourself.
|
|
```javascript
|
|
```javascript
|
|
import { TelegramClient } from "telegram";
|
|
import { TelegramClient } from "telegram";
|
|
import { StringSession } from "telegram/sessions";
|
|
import { StringSession } from "telegram/sessions";
|
|
-import input from "input";
|
|
|
|
|
|
+import readline from "readline";
|
|
|
|
|
|
const apiId = 123456;
|
|
const apiId = 123456;
|
|
const apiHash = "123456abcdfg";
|
|
const apiHash = "123456abcdfg";
|
|
const stringSession = new StringSession(""); // fill this later with the value from session.save()
|
|
const stringSession = new StringSession(""); // fill this later with the value from session.save()
|
|
|
|
|
|
|
|
+const rl = readline.createInterface({
|
|
|
|
+ input: process.stdin,
|
|
|
|
+ output: process.stdout,
|
|
|
|
+});
|
|
|
|
+
|
|
(async () => {
|
|
(async () => {
|
|
console.log("Loading interactive example...");
|
|
console.log("Loading interactive example...");
|
|
const client = new TelegramClient(stringSession, apiId, apiHash, {
|
|
const client = new TelegramClient(stringSession, apiId, apiHash, {
|
|
connectionRetries: 5,
|
|
connectionRetries: 5,
|
|
});
|
|
});
|
|
await client.start({
|
|
await client.start({
|
|
- phoneNumber: async () => await input.text("Please enter your number: "),
|
|
|
|
- password: async () => await input.text("Please enter your password: "),
|
|
|
|
|
|
+ phoneNumber: async () =>
|
|
|
|
+ new Promise((resolve) =>
|
|
|
|
+ rl.question("Please enter your number: ", resolve)
|
|
|
|
+ ),
|
|
|
|
+ password: async () =>
|
|
|
|
+ new Promise((resolve) =>
|
|
|
|
+ rl.question("Please enter your password: ", resolve)
|
|
|
|
+ ),
|
|
phoneCode: async () =>
|
|
phoneCode: async () =>
|
|
- await input.text("Please enter the code you received: "),
|
|
|
|
|
|
+ new Promise((resolve) =>
|
|
|
|
+ rl.question("Please enter the code you received: ", resolve)
|
|
|
|
+ ),
|
|
onError: (err) => console.log(err),
|
|
onError: (err) => console.log(err),
|
|
});
|
|
});
|
|
console.log("You should now be connected.");
|
|
console.log("You should now be connected.");
|