[core] WEBJS pairing code

This commit is contained in:
devlikepro committed 2024-09-17 11:30:30 +07:00
1 parent b1a5dd3b3c
commit 2ba7d1a425
1 file changed
+16 -2
+16 -2
View File
@@ -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<PairingCodeResponse> {
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<Buffer> {
const screenshot = await this.whatsapp.pupPage.screenshot({
encoding: 'binary',