[core] Add chat.archive event

closes #434
This commit is contained in:
devlikepro committed 2024-08-04 10:06:42 +07:00
1 parent b89f9d6b35
commit cd4e1f179d
4 files changed
+32 -2

No files matched your search

+10 -1
View File
@@ -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;
}
+9 -1
View File
@@ -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;
}
+1
View File
@@ -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 {
+12
View File
@@ -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 };