gramjs
gramjs copied to clipboard
`npm i input` is deprecated, could cause a slowdown up to 100x even if nothing is polyfilled
📦 v1.0.0 via v20.12.0
❯ npm i input
npm WARN deprecated [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
added 32 packages, and audited 134 packages in 8s
13 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Use alternative package of input or in-build readline input library Input package is instructed to install in README.md
Edit: Neither importing this library works
src/main.ts:3:19 - error TS7016: Could not find a declaration file for module 'input'. '/home/cxinu/dev/bot-dev/tg-premium/node_modules/input/dist/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/input` if it exists or add a new declaration (.d.ts) file containing `declare module 'input';`
3 import input from "input";
~~~~~~~
Found 1 error in src/main.ts:3
Here's an implementation using inbuild readline
import { TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
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 new Promise<string>((resolve) =>
rl.question("Please enter your number: ", resolve)
),
password: async () =>
await new Promise<string>((resolve) =>
rl.question("Please enter your password: ", resolve)
),
phoneCode: async () =>
await new Promise<string>((resolve) =>
rl.question("Please enter the code you received: ", resolve)
),
onError: (err) => console.log(err),
});
console.log("You should now be connected.");
console.log(client.session.save()); // Save this string to avoid logging in again
await client.sendMessage("me", { message: "Hello!" });
})();