feat(client): run method that wraps start()
This commit is contained in:
parent
c863e7a854
commit
48d328f486
2 changed files with 41 additions and 0 deletions
|
@ -7,6 +7,7 @@ import { getPasswordHint } from './methods/auth/get-password-hint'
|
||||||
import { logOut } from './methods/auth/log-out'
|
import { logOut } from './methods/auth/log-out'
|
||||||
import { recoverPassword } from './methods/auth/recover-password'
|
import { recoverPassword } from './methods/auth/recover-password'
|
||||||
import { resendCode } from './methods/auth/resend-code'
|
import { resendCode } from './methods/auth/resend-code'
|
||||||
|
import { run } from './methods/auth/run'
|
||||||
import { sendCode } from './methods/auth/send-code'
|
import { sendCode } from './methods/auth/send-code'
|
||||||
import { sendRecoveryCode } from './methods/auth/send-recovery-code'
|
import { sendRecoveryCode } from './methods/auth/send-recovery-code'
|
||||||
import { signInBot } from './methods/auth/sign-in-bot'
|
import { signInBot } from './methods/auth/sign-in-bot'
|
||||||
|
@ -158,6 +159,21 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* @param phoneCodeHash Confirmation code identifier from {@link SentCode}
|
* @param phoneCodeHash Confirmation code identifier from {@link SentCode}
|
||||||
*/
|
*/
|
||||||
resendCode(phone: string, phoneCodeHash: string): Promise<SentCode>
|
resendCode(phone: string, phoneCodeHash: string): Promise<SentCode>
|
||||||
|
/**
|
||||||
|
* Simple wrapper that calls {@link start} and then
|
||||||
|
* provided callback function (if any) without the
|
||||||
|
* need to introduce a `main()` function manually.
|
||||||
|
*
|
||||||
|
* Errors that were encountered while calling {@link start}
|
||||||
|
* and `then` will be emitted as usual, and can be caught with {@link onError}
|
||||||
|
*
|
||||||
|
* @param params Parameters to be passed to {@link params}
|
||||||
|
* @param then Function to be called after {@link start} returns
|
||||||
|
*/
|
||||||
|
run(
|
||||||
|
params: Parameters<TelegramClient['start']>[0],
|
||||||
|
then?: (user: User) => void | Promise<void>
|
||||||
|
): void
|
||||||
/**
|
/**
|
||||||
* Send the confirmation code to the given phone number
|
* Send the confirmation code to the given phone number
|
||||||
*
|
*
|
||||||
|
@ -1640,6 +1656,7 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
logOut = logOut as TelegramClient['logOut']
|
logOut = logOut as TelegramClient['logOut']
|
||||||
recoverPassword = recoverPassword as TelegramClient['recoverPassword']
|
recoverPassword = recoverPassword as TelegramClient['recoverPassword']
|
||||||
resendCode = resendCode as TelegramClient['resendCode']
|
resendCode = resendCode as TelegramClient['resendCode']
|
||||||
|
run = run as TelegramClient['run']
|
||||||
sendCode = sendCode as TelegramClient['sendCode']
|
sendCode = sendCode as TelegramClient['sendCode']
|
||||||
sendRecoveryCode = sendRecoveryCode as TelegramClient['sendRecoveryCode']
|
sendRecoveryCode = sendRecoveryCode as TelegramClient['sendRecoveryCode']
|
||||||
signInBot = signInBot as TelegramClient['signInBot']
|
signInBot = signInBot as TelegramClient['signInBot']
|
||||||
|
|
24
packages/client/src/methods/auth/run.ts
Normal file
24
packages/client/src/methods/auth/run.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { User } from '../../types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple wrapper that calls {@link start} and then
|
||||||
|
* provided callback function (if any) without the
|
||||||
|
* need to introduce a `main()` function manually.
|
||||||
|
*
|
||||||
|
* Errors that were encountered while calling {@link start}
|
||||||
|
* and `then` will be emitted as usual, and can be caught with {@link onError}
|
||||||
|
*
|
||||||
|
* @param params Parameters to be passed to {@link params}
|
||||||
|
* @param then Function to be called after {@link start} returns
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export function run(
|
||||||
|
this: TelegramClient,
|
||||||
|
params: Parameters<TelegramClient['start']>[0],
|
||||||
|
then?: (user: User) => void | Promise<void>
|
||||||
|
): void {
|
||||||
|
this.start(params)
|
||||||
|
.then(then)
|
||||||
|
.catch((err) => this._emitError(err))
|
||||||
|
}
|
Loading…
Reference in a new issue