Skip to content

Commit fa6b5c2

Browse files
author
Alexandre Martins
committed
feat(events): add isLatest and progress to messages.set event
- Add extra field to EmitData type for additional payload properties - Update EventManager and sendDataWebhook to support extra parameters - Update all event controllers (webhook, rabbitmq, sqs, websocket, pusher, kafka, nats) to include extra fields in payload - Pass isLatest and progress from Baileys messaging-history.set to messages.set webhook This allows consumers to know when the history sync is complete (isLatest=true) and track sync progress percentage.
1 parent df20c5f commit fa6b5c2

File tree

11 files changed

+23
-3
lines changed

11 files changed

+23
-3
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,10 @@ export class BaileysStartupService extends ChannelStartupService {
10221022
messagesRaw.push(this.prepareMessage(m));
10231023
}
10241024

1025-
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw]);
1025+
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw], true, undefined, {
1026+
isLatest,
1027+
progress,
1028+
});
10261029

10271030
if (this.configService.get<Database>('DATABASE').SAVE_DATA.HISTORIC) {
10281031
await this.prismaRepository.message.createMany({ data: messagesRaw, skipDuplicates: true });

src/api/integrations/event/event.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ export type EmitData = {
1414
apiKey?: string;
1515
local?: boolean;
1616
integration?: string[];
17+
extra?: Record<string, any>;
1718
};
1819

1920
export interface EventControllerInterface {
2021
set(instanceName: string, data: any): Promise<any>;
2122
get(instanceName: string): Promise<any>;
22-
emit({ instanceName, origin, event, data, serverUrl, dateTime, sender, apiKey, local }: EmitData): Promise<void>;
23+
emit({ instanceName, origin, event, data, serverUrl, dateTime, sender, apiKey, local, extra }: EmitData): Promise<void>;
2324
}
2425

2526
export class EventController {

src/api/integrations/event/event.manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export class EventManager {
123123
apiKey?: string;
124124
local?: boolean;
125125
integration?: string[];
126+
extra?: Record<string, any>;
126127
}): Promise<void> {
127128
await this.websocket.emit(eventData);
128129
await this.rabbitmq.emit(eventData);

src/api/integrations/event/kafka/kafka.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class KafkaController extends EventController implements EventControllerI
262262
sender,
263263
apiKey,
264264
integration,
265+
extra,
265266
}: EmitData): Promise<void> {
266267
if (integration && !integration.includes('kafka')) {
267268
return;
@@ -292,6 +293,7 @@ export class KafkaController extends EventController implements EventControllerI
292293
sender,
293294
apikey: apiKey,
294295
timestamp: Date.now(),
296+
...extra,
295297
};
296298

297299
const messageValue = JSON.stringify(message);

src/api/integrations/event/nats/nats.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class NatsController extends EventController implements EventControllerIn
4747
sender,
4848
apiKey,
4949
integration,
50+
extra,
5051
}: EmitData): Promise<void> {
5152
if (integration && !integration.includes('nats')) {
5253
return;
@@ -72,6 +73,7 @@ export class NatsController extends EventController implements EventControllerIn
7273
date_time: dateTime,
7374
sender,
7475
apikey: apiKey,
76+
...extra,
7577
};
7678

7779
// Instância específica

src/api/integrations/event/pusher/pusher.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class PusherController extends EventController implements EventController
121121
apiKey,
122122
local,
123123
integration,
124+
extra,
124125
}: EmitData): Promise<void> {
125126
if (integration && !integration.includes('pusher')) {
126127
return;
@@ -141,6 +142,7 @@ export class PusherController extends EventController implements EventController
141142
sender,
142143
server_url: serverUrl,
143144
apikey: apiKey,
145+
...extra,
144146
};
145147
if (event == 'qrcode.updated') {
146148
delete pusherData.data.qrcode.base64;

src/api/integrations/event/rabbitmq/rabbitmq.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export class RabbitmqController extends EventController implements EventControll
209209
sender,
210210
apiKey,
211211
integration,
212+
extra,
212213
}: EmitData): Promise<void> {
213214
if (integration && !integration.includes('rabbitmq')) {
214215
return;
@@ -240,6 +241,7 @@ export class RabbitmqController extends EventController implements EventControll
240241
date_time: dateTime,
241242
sender,
242243
apikey: apiKey,
244+
...extra,
243245
};
244246

245247
if (instanceRabbitmq?.enabled && this.amqpChannel) {

src/api/integrations/event/sqs/sqs.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class SqsController extends EventController implements EventControllerInt
9393
sender,
9494
apiKey,
9595
integration,
96+
extra,
9697
}: EmitData): Promise<void> {
9798
if (integration && !integration.includes('sqs')) {
9899
return;
@@ -137,6 +138,7 @@ export class SqsController extends EventController implements EventControllerInt
137138
date_time: dateTime,
138139
sender,
139140
apikey: apiKey,
141+
...extra,
140142
};
141143

142144
const jsonStr = JSON.stringify(message);

src/api/integrations/event/webhook/webhook.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class WebhookController extends EventController implements EventControlle
6565
apiKey,
6666
local,
6767
integration,
68+
extra,
6869
}: EmitData): Promise<void> {
6970
if (integration && !integration.includes('webhook')) {
7071
return;
@@ -98,6 +99,7 @@ export class WebhookController extends EventController implements EventControlle
9899
sender,
99100
server_url: serverUrl,
100101
apikey: apiKey,
102+
...extra,
101103
};
102104

103105
if (local && instance?.enabled) {

src/api/integrations/event/websocket/websocket.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export class WebsocketController extends EventController implements EventControl
115115
sender,
116116
apiKey,
117117
integration,
118+
extra,
118119
}: EmitData): Promise<void> {
119120
if (integration && !integration.includes('websocket')) {
120121
return;
@@ -134,6 +135,7 @@ export class WebsocketController extends EventController implements EventControl
134135
date_time: dateTime,
135136
sender,
136137
apikey: apiKey,
138+
...extra,
137139
};
138140

139141
if (configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {

0 commit comments

Comments
 (0)