diff --git a/src/core/engines/webjs/WebjsClient.ts b/src/core/engines/webjs/WebjsClient.ts index a75022d2..691f7c0b 100644 --- a/src/core/engines/webjs/WebjsClient.ts +++ b/src/core/engines/webjs/WebjsClient.ts @@ -1,6 +1,7 @@ import { GetChatMessagesFilter } from '@waha/structures/chats.dto'; import { Label } from '@waha/structures/labels.dto'; import { PaginationParams } from '@waha/structures/pagination.dto'; +import { TextStatus } from '@waha/structures/status.dto'; import * as lodash from 'lodash'; import { Client } from 'whatsapp-web.js'; import { Message } from 'whatsapp-web.js/src/structures'; @@ -101,6 +102,37 @@ export class WebjsClient extends Client { return chats.map((chat) => ChatFactory.create(this, chat)); } + async sendTextStatus(status: TextStatus) { + // Convert from hex to number + const waColor = 'FF' + status.backgroundColor.replace('#', ''); + const color = parseInt(waColor, 16); + + const textStatus = { + text: status.text, + color: color, + font: status.font, + }; + const sentMsg = await this.pupPage.evaluate(async (status) => { + // @ts-ignore + await window.Store.SendStatus.sendStatusTextMsgAction(status); + // @ts-ignore + const meUser = window.Store.User.getMeUser(); + // @ts-ignore + const myStatus = window.Store.Status.getModelsArray().findLast( + (x) => x.id == meUser, + ); + if (!myStatus) { + return undefined; + } + // @ts-ignore + const msg = myStatus.msgs.last(); + // @ts-ignore + return msg ? window.WWebJS.getMessageModel(msg) : undefined; + }, textStatus); + + return sentMsg ? new Message(this, sentMsg) : undefined; + } + async getMessages( chatId: string, filter: GetChatMessagesFilter, diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index eb2db980..a64fd8cc 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -1,8 +1,10 @@ +import { UnprocessableEntityException } from '@nestjs/common'; import { getChannelInviteLink, WAHAInternalEvent, WhatsappSession, } from '@waha/core/abc/session.abc'; +import { toJID } from '@waha/core/engines/noweb/session.noweb.core'; import { LocalAuth } from '@waha/core/engines/webjs/LocalAuth'; import { WebjsClient } from '@waha/core/engines/webjs/WebjsClient'; import { @@ -63,6 +65,11 @@ import { ReplyToMessage } from '@waha/structures/message.dto'; import { PaginationParams } from '@waha/structures/pagination.dto'; import { WAMessage, WAMessageReaction } from '@waha/structures/responses.dto'; import { MeInfo } from '@waha/structures/sessions.dto'; +import { + BROADCAST_ID, + StatusRequest, + TextStatus, +} from '@waha/structures/status.dto'; import { WAMessageRevokedBody } from '@waha/structures/webhooks.dto'; import { PaginatorInMemory } from '@waha/utils/Paginator'; import { sleep, waitUntil } from '@waha/utils/promiseTimeout'; @@ -968,6 +975,22 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { } } + /** + * Status methods + */ + protected checkStatusRequest(request: StatusRequest) { + if (request.contacts?.length > 0) { + const msg = + "WEBJS doesn't accept 'contacts'. Remove the field to send status to all contacts."; + throw new UnprocessableEntityException(msg); + } + } + + public sendTextStatus(status: TextStatus) { + this.checkStatusRequest(status); + return this.whatsapp.sendTextStatus(status); + } + /** * END - Methods for API */ diff --git a/src/structures/status.dto.ts b/src/structures/status.dto.ts index c787e33c..1e51578f 100644 --- a/src/structures/status.dto.ts +++ b/src/structures/status.dto.ts @@ -11,10 +11,9 @@ import { export const BROADCAST_ID = 'status@broadcast'; -class StatusRequest { +export class StatusRequest { @ApiProperty({ - description: - 'it is always necessary to inform the list of contacts that will have access to the posted status', + description: 'Contact list to send the status to.', example: ['55xxxxxxxxxxx@c.us'], }) contacts = ['55xxxxxxxxxxx@c.us']; diff --git a/yarn.lock b/yarn.lock index 2bf639f9..a8cf945b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12384,7 +12384,7 @@ __metadata: "whatsapp-web.js@github:devlikeapro/whatsapp-web.js#fork-main-channels": version: 1.26.0 - resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=76329eedc27b07c11e38bf1b60e6c2476c11dd73" + resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=aa90f7378659a237f30cda6d368359a1f81904dc" dependencies: "@pedroslopez/moduleraid": ^5.0.2 archiver: ^5.3.1 @@ -12402,7 +12402,7 @@ __metadata: optional: true unzipper: optional: true - checksum: b8d4fcb1fd1365a38f07f95dd2eb1fd743c6c406fc7ac679662ddeded80c441720bc8400222a37d61765ebcbb5c6799f169d5ac45f12f58b5421c55bb9f2ab7e + checksum: 7c914e9cdd4a25c967e057d0cb5019973f0556f6220320e4bcbc0666669801b92abf97c2cc783762ef462d0006123953e233136f457689ebac395260fe69a5fc languageName: node linkType: hard