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

31 lines
872 B
TypeScript
Raw Normal View History

2021-04-08 12:19:38 +03:00
import { TelegramClient } from '../../client'
import { SentCode } from '../../types'
2021-04-08 12:19:38 +03:00
import { normalizePhoneNumber } from '../../utils/misc-utils'
2023-07-20 19:01:34 +03:00
import { assertTypeIs } from '../../utils/type-assertion'
2021-04-08 12:19:38 +03:00
/**
* 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,
2021-04-08 12:19:38 +03:00
): Promise<SentCode> {
phone = normalizePhoneNumber(phone)
const res = await this.call({
_: 'auth.sendCode',
phoneNumber: phone,
2023-06-10 00:37:26 +03:00
apiId: this.network._initConnectionParams.apiId,
2021-04-08 12:19:38 +03:00
apiHash: this._apiHash,
settings: { _: 'codeSettings' },
})
2023-07-20 19:01:34 +03:00
assertTypeIs('sendCode', res, 'auth.sentCode')
2021-04-08 12:19:38 +03:00
return new SentCode(res)
}