mtcute/packages/client/src/methods/auth/send-code.ts

30 lines
872 B
TypeScript

import { TelegramClient } from '../../client'
import { SentCode } from '../../types'
import { normalizePhoneNumber } from '../../utils/misc-utils'
import { assertTypeIs } from '../../utils/type-assertion'
/**
* Send the confirmation code to the given phone number
*
* @param phone Phone number in international format.
* @returns An object containing information about the sent confirmation code
* @internal
*/
export async function sendCode(
this: TelegramClient,
phone: string,
): Promise<SentCode> {
phone = normalizePhoneNumber(phone)
const res = await this.call({
_: 'auth.sendCode',
phoneNumber: phone,
apiId: this.network._initConnectionParams.apiId,
apiHash: this._apiHash,
settings: { _: 'codeSettings' },
})
assertTypeIs('sendCode', res, 'auth.sentCode')
return new SentCode(res)
}