diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index e3085442..b9c1d543 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -1,4 +1,3 @@ -import { UnprocessableEntityException } from '@nestjs/common/exceptions/unprocessable-entity.exception'; import { getChannelInviteLink, WAHAInternalEvent, @@ -11,7 +10,8 @@ import { } from '@waha/core/exceptions'; import { IMediaEngineProcessor } from '@waha/core/media/IMediaEngineProcessor'; import { QR } from '@waha/core/QR'; -import { parseBool } from '@waha/helpers'; +import { parseBool, splitAt } from '@waha/helpers'; +import { PairingCodeResponse } from '@waha/structures/auth.dto'; import { CallData } from '@waha/structures/calls.dto'; import { Channel, @@ -326,6 +326,20 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { return this.qr; } + public async requestCode( + phoneNumber: string, + method: string, + params?: any, + ): Promise { + const code = await this.whatsapp.requestPairingCode(phoneNumber, true); + + // show it as ABCD-ABCD + const parts = splitAt(code, 4); + const codeRepr = parts.join('-'); + this.logger.info(`Your code: ${codeRepr}`); + return { code: codeRepr }; + } + async getScreenshot(): Promise { const screenshot = await this.whatsapp.pupPage.screenshot({ encoding: 'binary',