Merge pull request #2260 from alexandrereyes/feat/add-islatest-progress-to-messages-set

feat(events): add isLatest and progress to messages.set event
This commit is contained in:
Davidson Gomes 2025-12-05 11:01:21 -03:00 committed by GitHub
commit 86b194af5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 40 additions and 3 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -1044,7 +1044,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 });

View File

@ -14,12 +14,24 @@ 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 {

View File

@ -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);

View File

@ -262,6 +262,7 @@ export class KafkaController extends EventController implements EventControllerI
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('kafka')) {
return;
@ -284,6 +285,7 @@ export class KafkaController extends EventController implements EventControllerI
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
const message = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -47,6 +47,7 @@ export class NatsController extends EventController implements EventControllerIn
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('nats')) {
return;
@ -65,6 +66,7 @@ export class NatsController extends EventController implements EventControllerIn
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
const message = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -121,6 +121,7 @@ export class PusherController extends EventController implements EventController
apiKey,
local,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('pusher')) {
return;
@ -133,6 +134,7 @@ export class PusherController extends EventController implements EventController
const enabledLog = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
const eventName = event.replace(/_/g, '.').toLowerCase();
const pusherData = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -209,6 +209,7 @@ export class RabbitmqController extends EventController implements EventControll
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('rabbitmq')) {
return;
@ -233,6 +234,7 @@ export class RabbitmqController extends EventController implements EventControll
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBHOOKS');
const message = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -93,6 +93,7 @@ export class SqsController extends EventController implements EventControllerInt
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('sqs')) {
return;
@ -128,6 +129,7 @@ export class SqsController extends EventController implements EventControllerInt
const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
const message = {
...(extra ?? {}),
event,
instance: instanceName,
dataType: 'json',

View File

@ -65,6 +65,7 @@ export class WebhookController extends EventController implements EventControlle
apiKey,
local,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('webhook')) {
return;
@ -90,6 +91,7 @@ export class WebhookController extends EventController implements EventControlle
const regex = /^(https?:\/\/)/;
const webhookData = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -116,6 +116,7 @@ export class WebsocketController extends EventController implements EventControl
sender,
apiKey,
integration,
extra,
}: EmitData): Promise<void> {
if (integration && !integration.includes('websocket')) {
return;
@ -128,6 +129,7 @@ export class WebsocketController extends EventController implements EventControl
const configEv = event.replace(/[.-]/gm, '_').toUpperCase();
const logEnabled = configService.get<Log>('LOG').LEVEL.includes('WEBSOCKET');
const message = {
...(extra ?? {}),
event,
instance: instanceName,
data,

View File

@ -432,7 +432,13 @@ 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();
@ -453,6 +459,7 @@ export class ChannelStartupService {
apiKey: expose && instanceApikey ? instanceApikey : null,
local,
integration,
extra,
});
}