Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
3 changes: 2 additions & 1 deletion src/api/integrations/event/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/api/integrations/event/event.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/kafka/kafka.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class KafkaController extends EventController implements EventControllerI
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('kafka')) {
return;
Expand Down Expand Up @@ -292,6 +293,7 @@ export class KafkaController extends EventController implements EventControllerI
sender,
apikey: apiKey,
timestamp: Date.now(),
...extra,
};

const messageValue = JSON.stringify(message);
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/nats/nats.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class NatsController extends EventController implements EventControllerIn
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('nats')) {
return;
Expand All @@ -72,6 +73,7 @@ export class NatsController extends EventController implements EventControllerIn
date_time: dateTime,
sender,
apikey: apiKey,
...extra,
};

// Instância específica
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/pusher/pusher.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class PusherController extends EventController implements EventController
apiKey,
local,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('pusher')) {
return;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/rabbitmq/rabbitmq.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export class RabbitmqController extends EventController implements EventControll
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('rabbitmq')) {
return;
Expand Down Expand Up @@ -240,6 +241,7 @@ export class RabbitmqController extends EventController implements EventControll
date_time: dateTime,
sender,
apikey: apiKey,
...extra,
};

if (instanceRabbitmq?.enabled && this.amqpChannel) {
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/sqs/sqs.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class SqsController extends EventController implements EventControllerInt
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('sqs')) {
return;
Expand Down Expand Up @@ -137,6 +138,7 @@ export class SqsController extends EventController implements EventControllerInt
date_time: dateTime,
sender,
apikey: apiKey,
...extra,
};

const jsonStr = JSON.stringify(message);
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/webhook/webhook.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class WebhookController extends EventController implements EventControlle
apiKey,
local,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('webhook')) {
return;
Expand Down Expand Up @@ -98,6 +99,7 @@ export class WebhookController extends EventController implements EventControlle
sender,
server_url: serverUrl,
apikey: apiKey,
...extra,
};

if (local && instance?.enabled) {
Expand Down
2 changes: 2 additions & 0 deletions src/api/integrations/event/websocket/websocket.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class WebsocketController extends EventController implements EventControl
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('websocket')) {
return;
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/services/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -452,6 +452,7 @@ export class ChannelStartupService {
apiKey: expose && instanceApikey ? instanceApikey : null,
local,
integration,
extra,
});
}

Expand Down