Skip to content

Commit

Permalink
refactor(route/telegram): use log instead of console to resolve eslin…
Browse files Browse the repository at this point in the history
…t issue
  • Loading branch information
pseudoyu committed Nov 2, 2024
1 parent e9e0950 commit 56d4c5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions lib/routes/telegram/scripts/get-telegram-session.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { TelegramClient } from 'telegram';
import { StringSession } from 'telegram/sessions/index.js';
import readline from 'readline';
import debug from 'debug';

const log = debug('telegram:session');

function userInput(question) {
const rl = readline.createInterface({
Expand All @@ -16,7 +19,7 @@ function userInput(question) {
}

async function getSessionString() {
const apiId = parseInt(await userInput('Please enter your API ID: '));
const apiId = Number.parseInt(await userInput('Please enter your API ID: '));
const apiHash = await userInput('Please enter your API Hash: ');
const stringSession = new StringSession('');
const client = new TelegramClient(stringSession, apiId, apiHash, {
Expand All @@ -26,16 +29,16 @@ async function getSessionString() {
phoneNumber: async () => await userInput('Please enter your phone number: '),
password: async () => await userInput('Please enter your password: '),
phoneCode: async () => await userInput('Please enter the code you received: '),
onError: (err) => console.log(err),
onError: (err) => log('Error:', err),
});

console.log('You are now connected.');
log('You are now connected.');
const sessionString = client.session.save();
log('Your session string is:', sessionString);

console.log('Your session string is:', sessionString);
await client.disconnect();
return sessionString;
}

// Run the function
getSessionString().catch(console.error);
getSessionString().catch((error) => log('Error:', error));
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56d4c5e

Please sign in to comment.