diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 49b56e70..76790495 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -18,7 +18,7 @@ import { CreateChannelRequest, ListChannelsQuery, } from '@waha/structures/channels.dto'; -import { GetChatsQuery } from '@waha/structures/chats.dto'; +import { ChatArchiveEvent, GetChatsQuery } from '@waha/structures/chats.dto'; import { ChatRequest, CheckNumberStatusQuery, @@ -821,6 +821,15 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { case WAHAEvents.GROUP_LEAVE: this.whatsapp.on(Events.GROUP_LEAVE, handler); return true; + case WAHAEvents.CHAT_ARCHIVE: + this.whatsapp.on('chat_archived', (chat, archived, _) => { + const body: ChatArchiveEvent = { + id: chat.id._serialized, + archived: archived, + }; + handler(body); + }); + return true; default: return false; } diff --git a/src/structures/chats.dto.ts b/src/structures/chats.dto.ts index d176acc8..f47bcb65 100644 --- a/src/structures/chats.dto.ts +++ b/src/structures/chats.dto.ts @@ -1,4 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; +import { ChatIdProperty } from '@waha/structures/properties.dto'; import { Type } from 'class-transformer'; import { IsNumber, IsOptional } from 'class-validator'; @@ -32,5 +33,12 @@ export class GetChatsQuery { } /** - * Requests + * Events */ + +export class ChatArchiveEvent { + @ChatIdProperty() + id: string; + + archived: boolean; +} diff --git a/src/structures/enums.dto.ts b/src/structures/enums.dto.ts index 995a3e93..515d80ea 100644 --- a/src/structures/enums.dto.ts +++ b/src/structures/enums.dto.ts @@ -13,6 +13,7 @@ export enum WAHAEvents { PRESENCE_UPDATE = 'presence.update', POLL_VOTE = 'poll.vote', POLL_VOTE_FAILED = 'poll.vote.failed', + CHAT_ARCHIVE = 'chat.archive', } export enum WAHASessionStatus { diff --git a/src/structures/webhooks.dto.ts b/src/structures/webhooks.dto.ts index e04df8f4..ef2b0554 100644 --- a/src/structures/webhooks.dto.ts +++ b/src/structures/webhooks.dto.ts @@ -1,5 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; +import { ChatArchiveEvent } from './chats.dto'; import { MessageDestination } from './chatting.dto'; import { WAHAEngine, @@ -230,6 +231,16 @@ class WAHAWebhookPollVoteFailed extends WAHAWebhook { payload: PollVotePayload; } +class WAHAWebhookChatArchive extends WAHAWebhook { + @ApiProperty({ + description: + 'The event is triggered when the chat is archived or unarchived', + }) + event = WAHAEvents.CHAT_ARCHIVE; + + payload: ChatArchiveEvent; +} + const WAHA_WEBHOOKS = [ WAHAWebhookSessionStatus, WAHAWebhookMessage, @@ -243,5 +254,6 @@ const WAHA_WEBHOOKS = [ WAHAWebhookPresenceUpdate, WAHAWebhookPollVote, WAHAWebhookPollVoteFailed, + WAHAWebhookChatArchive, ]; export { WAHA_WEBHOOKS };