Skip to content

Commit

Permalink
Remove deprecated "input" with "readline" from README.md (#658)
Browse files Browse the repository at this point in the history
input library is deprecated and doesn't work for input anymore.
#657
  • Loading branch information
cxinu authored Apr 12, 2024
1 parent 4690d50 commit a969d6c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ Install GramJS:
$ 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:

1. Login into your [telegram account](https://my.telegram.org/)
Expand All @@ -36,22 +30,35 @@ Then run this code to send a message to yourself.
```javascript
import { TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
import input from "input";
import readline from "readline";

const apiId = 123456;
const apiHash = "123456abcdfg";
const stringSession = new StringSession(""); // fill this later with the value from session.save()

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

(async () => {
console.log("Loading interactive example...");
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.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 () =>
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),
});
console.log("You should now be connected.");
Expand Down

0 comments on commit a969d6c

Please sign in to comment.