diff --git a/packages/node/index.ts b/packages/node/index.ts index 75886b52..c4ab6821 100644 --- a/packages/node/index.ts +++ b/packages/node/index.ts @@ -89,10 +89,10 @@ export class NodeTelegramClient extends TelegramClient { return new Promise((res) => this._rl!.question(text, res)) } - async run( + run( params: Parameters[0], then?: (user: User) => void | Promise - ): Promise { + ): void { if (!params.botToken) { if (!params.phone) params.phone = () => this.input('Phone > ') if (!params.code) params.code = () => this.input('Code > ') @@ -100,12 +100,14 @@ export class NodeTelegramClient extends TelegramClient { params.password = () => this.input('2FA password > ') } - await super.run(params, then) + super.run(params, (user) => { + if (this._rl) { + this._rl.close() + delete this._rl + } - if (this._rl) { - this._rl.close() - delete this._rl - } + return then?.(user) + }) } close(): Promise {