mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
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.
This commit is contained in:
parent
df20c5fc93
commit
fa6b5c28a6
@ -1022,7 +1022,10 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
messagesRaw.push(this.prepareMessage(m));
|
||||
}
|
||||
|
||||
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw]);
|
||||
this.sendDataWebhook(Events.MESSAGES_SET, [...messagesRaw], true, undefined, {
|
||||
isLatest,
|
||||
progress,
|
||||
});
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').SAVE_DATA.HISTORIC) {
|
||||
await this.prismaRepository.message.createMany({ data: messagesRaw, skipDuplicates: true });
|
||||
|
||||
@ -14,12 +14,13 @@ export type EmitData = {
|
||||
apiKey?: string;
|
||||
local?: boolean;
|
||||
integration?: string[];
|
||||
extra?: Record<string, any>;
|
||||
};
|
||||
|
||||
export interface EventControllerInterface {
|
||||
set(instanceName: string, data: any): Promise<any>;
|
||||
get(instanceName: string): Promise<any>;
|
||||
emit({ instanceName, origin, event, data, serverUrl, dateTime, sender, apiKey, local }: EmitData): Promise<void>;
|
||||
emit({ instanceName, origin, event, data, serverUrl, dateTime, sender, apiKey, local, extra }: EmitData): Promise<void>;
|
||||
}
|
||||
|
||||
export class EventController {
|
||||
|
||||
@ -123,6 +123,7 @@ export class EventManager {
|
||||
apiKey?: string;
|
||||
local?: boolean;
|
||||
integration?: string[];
|
||||
extra?: Record<string, any>;
|
||||
}): Promise<void> {
|
||||
await this.websocket.emit(eventData);
|
||||
await this.rabbitmq.emit(eventData);
|
||||
|
||||
@ -262,6 +262,7 @@ export class KafkaController extends EventController implements EventControllerI
|
||||
sender,
|
||||
apiKey,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('kafka')) {
|
||||
return;
|
||||
@ -292,6 +293,7 @@ export class KafkaController extends EventController implements EventControllerI
|
||||
sender,
|
||||
apikey: apiKey,
|
||||
timestamp: Date.now(),
|
||||
...extra,
|
||||
};
|
||||
|
||||
const messageValue = JSON.stringify(message);
|
||||
|
||||
@ -47,6 +47,7 @@ export class NatsController extends EventController implements EventControllerIn
|
||||
sender,
|
||||
apiKey,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('nats')) {
|
||||
return;
|
||||
@ -72,6 +73,7 @@ export class NatsController extends EventController implements EventControllerIn
|
||||
date_time: dateTime,
|
||||
sender,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
|
||||
// Instância específica
|
||||
|
||||
@ -121,6 +121,7 @@ export class PusherController extends EventController implements EventController
|
||||
apiKey,
|
||||
local,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('pusher')) {
|
||||
return;
|
||||
@ -141,6 +142,7 @@ export class PusherController extends EventController implements EventController
|
||||
sender,
|
||||
server_url: serverUrl,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
if (event == 'qrcode.updated') {
|
||||
delete pusherData.data.qrcode.base64;
|
||||
|
||||
@ -209,6 +209,7 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
sender,
|
||||
apiKey,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('rabbitmq')) {
|
||||
return;
|
||||
@ -240,6 +241,7 @@ export class RabbitmqController extends EventController implements EventControll
|
||||
date_time: dateTime,
|
||||
sender,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
|
||||
if (instanceRabbitmq?.enabled && this.amqpChannel) {
|
||||
|
||||
@ -93,6 +93,7 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
sender,
|
||||
apiKey,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('sqs')) {
|
||||
return;
|
||||
@ -137,6 +138,7 @@ export class SqsController extends EventController implements EventControllerInt
|
||||
date_time: dateTime,
|
||||
sender,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
|
||||
const jsonStr = JSON.stringify(message);
|
||||
|
||||
@ -65,6 +65,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
apiKey,
|
||||
local,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('webhook')) {
|
||||
return;
|
||||
@ -98,6 +99,7 @@ export class WebhookController extends EventController implements EventControlle
|
||||
sender,
|
||||
server_url: serverUrl,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
|
||||
if (local && instance?.enabled) {
|
||||
|
||||
@ -115,6 +115,7 @@ export class WebsocketController extends EventController implements EventControl
|
||||
sender,
|
||||
apiKey,
|
||||
integration,
|
||||
extra,
|
||||
}: EmitData): Promise<void> {
|
||||
if (integration && !integration.includes('websocket')) {
|
||||
return;
|
||||
@ -134,6 +135,7 @@ export class WebsocketController extends EventController implements EventControl
|
||||
date_time: dateTime,
|
||||
sender,
|
||||
apikey: apiKey,
|
||||
...extra,
|
||||
};
|
||||
|
||||
if (configService.get<Websocket>('WEBSOCKET')?.GLOBAL_EVENTS) {
|
||||
|
||||
@ -431,7 +431,7 @@ export class ChannelStartupService {
|
||||
return data;
|
||||
}
|
||||
|
||||
public async sendDataWebhook<T extends object = any>(event: Events, data: T, local = true, integration?: string[]) {
|
||||
public async sendDataWebhook<T extends object = any>(event: Events, data: T, local = true, integration?: string[], extra?: Record<string, any>) {
|
||||
const serverUrl = this.configService.get<HttpServer>('SERVER').URL;
|
||||
const tzoffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds
|
||||
const localISOTime = new Date(Date.now() - tzoffset).toISOString();
|
||||
@ -452,6 +452,7 @@ export class ChannelStartupService {
|
||||
apiKey: expose && instanceApikey ? instanceApikey : null,
|
||||
local,
|
||||
integration,
|
||||
extra,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user