Skip to content

Commit 75a7140

Browse files
authored
Merge branch 'EvolutionAPI:develop' into develop
2 parents 4aca46a + 2198a86 commit 75a7140

17 files changed

Lines changed: 418 additions & 23 deletions

File tree

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"mime-types": "^2.1.35",
8383
"minio": "^8.0.3",
8484
"multer": "^1.4.5-lts.1",
85+
"nats": "^2.29.1",
8586
"node-cache": "^5.1.2",
8687
"node-cron": "^3.0.3",
8788
"openai": "^4.77.3",

prisma/mysql-schema.prisma

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ model Instance {
8686
Proxy Proxy?
8787
Setting Setting?
8888
Rabbitmq Rabbitmq?
89+
Nats Nats?
8990
Sqs Sqs?
9091
Websocket Websocket?
9192
Typebot Typebot[]
@@ -116,18 +117,19 @@ model Session {
116117
}
117118

118119
model Chat {
119-
id String @id @default(cuid())
120-
remoteJid String @db.VarChar(100)
121-
name String? @db.VarChar(100)
122-
labels Json? @db.Json
123-
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
124-
updatedAt DateTime? @updatedAt @db.Timestamp
125-
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
126-
instanceId String
120+
id String @id @default(cuid())
121+
remoteJid String @db.VarChar(100)
122+
name String? @db.VarChar(100)
123+
labels Json? @db.Json
124+
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
125+
updatedAt DateTime? @updatedAt @db.Timestamp
126+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
127+
instanceId String
127128
unreadMessages Int @default(0)
129+
130+
@@unique([instanceId, remoteJid])
128131
@@index([instanceId])
129132
@@index([remoteJid])
130-
@@unique([instanceId, remoteJid])
131133
}
132134

133135
model Contact {
@@ -170,6 +172,7 @@ model Message {
170172
171173
sessionId String?
172174
session IntegrationSession? @relation(fields: [sessionId], references: [id])
175+
173176
@@index([instanceId])
174177
}
175178

@@ -185,6 +188,7 @@ model MessageUpdate {
185188
messageId String
186189
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
187190
instanceId String
191+
188192
@@index([instanceId])
189193
@@index([messageId])
190194
}
@@ -201,6 +205,7 @@ model Webhook {
201205
updatedAt DateTime @updatedAt @db.Timestamp
202206
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
203207
instanceId String @unique
208+
204209
@@index([instanceId])
205210
}
206211

@@ -269,6 +274,7 @@ model Setting {
269274
updatedAt DateTime @updatedAt @db.Timestamp
270275
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
271276
instanceId String @unique
277+
272278
@@index([instanceId])
273279
}
274280

@@ -282,6 +288,16 @@ model Rabbitmq {
282288
instanceId String @unique
283289
}
284290

291+
model Nats {
292+
id String @id @default(cuid())
293+
enabled Boolean @default(false)
294+
events Json @db.Json
295+
createdAt DateTime? @default(dbgenerated("CURRENT_TIMESTAMP")) @db.Timestamp
296+
updatedAt DateTime @updatedAt @db.Timestamp
297+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
298+
instanceId String @unique
299+
}
300+
285301
model Sqs {
286302
id String @id @default(cuid())
287303
enabled Boolean @default(false)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- CreateTable
2+
CREATE TABLE "Nats" (
3+
"id" TEXT NOT NULL,
4+
"enabled" BOOLEAN NOT NULL DEFAULT false,
5+
"events" JSONB NOT NULL,
6+
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
7+
"updatedAt" TIMESTAMP NOT NULL,
8+
"instanceId" TEXT NOT NULL,
9+
10+
CONSTRAINT "Nats_pkey" PRIMARY KEY ("id")
11+
);
12+
13+
-- CreateIndex
14+
CREATE UNIQUE INDEX "Nats_instanceId_key" ON "Nats"("instanceId");
15+
16+
-- AddForeignKey
17+
ALTER TABLE "Nats" ADD CONSTRAINT "Nats_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/postgresql-schema.prisma

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ model Instance {
8686
Proxy Proxy?
8787
Setting Setting?
8888
Rabbitmq Rabbitmq?
89+
Nats Nats?
8990
Sqs Sqs?
9091
Websocket Websocket?
9192
Typebot Typebot[]
@@ -125,6 +126,7 @@ model Chat {
125126
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
126127
instanceId String
127128
unreadMessages Int @default(0)
129+
128130
@@index([instanceId])
129131
@@index([remoteJid])
130132
}
@@ -168,6 +170,7 @@ model Message {
168170
169171
sessionId String?
170172
session IntegrationSession? @relation(fields: [sessionId], references: [id])
173+
171174
@@index([instanceId])
172175
}
173176

@@ -183,6 +186,7 @@ model MessageUpdate {
183186
messageId String
184187
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
185188
instanceId String
189+
186190
@@index([instanceId])
187191
@@index([messageId])
188192
}
@@ -199,6 +203,7 @@ model Webhook {
199203
updatedAt DateTime @updatedAt @db.Timestamp
200204
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
201205
instanceId String @unique
206+
202207
@@index([instanceId])
203208
}
204209

@@ -269,6 +274,7 @@ model Setting {
269274
updatedAt DateTime @updatedAt @db.Timestamp
270275
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
271276
instanceId String @unique
277+
272278
@@index([instanceId])
273279
}
274280

@@ -282,6 +288,16 @@ model Rabbitmq {
282288
instanceId String @unique
283289
}
284290

291+
model Nats {
292+
id String @id @default(cuid())
293+
enabled Boolean @default(false) @db.Boolean
294+
events Json @db.JsonB
295+
createdAt DateTime? @default(now()) @db.Timestamp
296+
updatedAt DateTime @updatedAt @db.Timestamp
297+
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
298+
instanceId String @unique
299+
}
300+
285301
model Sqs {
286302
id String @id @default(cuid())
287303
enabled Boolean @default(false) @db.Boolean

src/api/controllers/instance.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export class InstanceController {
170170
rabbitmq: {
171171
enabled: instanceData?.rabbitmq?.enabled,
172172
},
173+
nats: {
174+
enabled: instanceData?.nats?.enabled,
175+
},
173176
sqs: {
174177
enabled: instanceData?.sqs?.enabled,
175178
},
@@ -258,6 +261,9 @@ export class InstanceController {
258261
rabbitmq: {
259262
enabled: instanceData?.rabbitmq?.enabled,
260263
},
264+
nats: {
265+
enabled: instanceData?.nats?.enabled,
266+
},
261267
sqs: {
262268
enabled: instanceData?.sqs?.enabled,
263269
},

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,23 +1169,23 @@ export class BaileysStartupService extends ChannelStartupService {
11691169
}
11701170
}
11711171

1172-
if (received.messageStubParameters && received.messageStubParameters[0] === 'Message absent from node') {
1173-
this.logger.info(`Recovering message lost messageId: ${received.key.id}`);
1172+
// if (received.messageStubParameters && received.messageStubParameters[0] === 'Message absent from node') {
1173+
// this.logger.info(`Recovering message lost messageId: ${received.key.id}`);
11741174

1175-
await this.baileysCache.set(received.key.id, {
1176-
message: received,
1177-
retry: 0,
1178-
});
1175+
// await this.baileysCache.set(received.key.id, {
1176+
// message: received,
1177+
// retry: 0,
1178+
// });
11791179

1180-
continue;
1181-
}
1180+
// continue;
1181+
// }
11821182

1183-
const retryCache = (await this.baileysCache.get(received.key.id)) || null;
1183+
// const retryCache = (await this.baileysCache.get(received.key.id)) || null;
11841184

1185-
if (retryCache) {
1186-
this.logger.info('Recovered message lost');
1187-
await this.baileysCache.delete(received.key.id);
1188-
}
1185+
// if (retryCache) {
1186+
// this.logger.info('Recovered message lost');
1187+
// await this.baileysCache.delete(received.key.id);
1188+
// }
11891189

11901190
// Cache to avoid duplicate messages
11911191
const messageKey = `${this.instance.id}_${received.key.id}`;

src/api/integrations/event/event.dto.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export class EventDto {
2626
events?: string[];
2727
};
2828

29+
nats?: {
30+
enabled?: boolean;
31+
events?: string[];
32+
};
33+
2934
pusher?: {
3035
enabled?: boolean;
3136
appId?: string;
@@ -63,6 +68,11 @@ export function EventInstanceMixin<TBase extends Constructor>(Base: TBase) {
6368
events?: string[];
6469
};
6570

71+
nats?: {
72+
enabled?: boolean;
73+
events?: string[];
74+
};
75+
6676
pusher?: {
6777
enabled?: boolean;
6878
appId?: string;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NatsController } from '@api/integrations/event/nats/nats.controller';
12
import { PusherController } from '@api/integrations/event/pusher/pusher.controller';
23
import { RabbitmqController } from '@api/integrations/event/rabbitmq/rabbitmq.controller';
34
import { SqsController } from '@api/integrations/event/sqs/sqs.controller';
@@ -13,6 +14,7 @@ export class EventManager {
1314
private websocketController: WebsocketController;
1415
private webhookController: WebhookController;
1516
private rabbitmqController: RabbitmqController;
17+
private natsController: NatsController;
1618
private sqsController: SqsController;
1719
private pusherController: PusherController;
1820

@@ -23,6 +25,7 @@ export class EventManager {
2325
this.websocket = new WebsocketController(prismaRepository, waMonitor);
2426
this.webhook = new WebhookController(prismaRepository, waMonitor);
2527
this.rabbitmq = new RabbitmqController(prismaRepository, waMonitor);
28+
this.nats = new NatsController(prismaRepository, waMonitor);
2629
this.sqs = new SqsController(prismaRepository, waMonitor);
2730
this.pusher = new PusherController(prismaRepository, waMonitor);
2831
}
@@ -67,6 +70,14 @@ export class EventManager {
6770
return this.rabbitmqController;
6871
}
6972

73+
public set nats(nats: NatsController) {
74+
this.natsController = nats;
75+
}
76+
77+
public get nats() {
78+
return this.natsController;
79+
}
80+
7081
public set sqs(sqs: SqsController) {
7182
this.sqsController = sqs;
7283
}
@@ -85,6 +96,7 @@ export class EventManager {
8596
public init(httpServer: Server): void {
8697
this.websocket.init(httpServer);
8798
this.rabbitmq.init();
99+
this.nats.init();
88100
this.sqs.init();
89101
this.pusher.init();
90102
}
@@ -103,6 +115,7 @@ export class EventManager {
103115
}): Promise<void> {
104116
await this.websocket.emit(eventData);
105117
await this.rabbitmq.emit(eventData);
118+
await this.nats.emit(eventData);
106119
await this.sqs.emit(eventData);
107120
await this.webhook.emit(eventData);
108121
await this.pusher.emit(eventData);
@@ -125,6 +138,14 @@ export class EventManager {
125138
},
126139
});
127140

141+
if (data.nats)
142+
await this.nats.set(instanceName, {
143+
nats: {
144+
enabled: true,
145+
events: data.nats?.events,
146+
},
147+
});
148+
128149
if (data.sqs)
129150
await this.sqs.set(instanceName, {
130151
sqs: {

src/api/integrations/event/event.router.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { NatsRouter } from '@api/integrations/event/nats/nats.router';
12
import { PusherRouter } from '@api/integrations/event/pusher/pusher.router';
23
import { RabbitmqRouter } from '@api/integrations/event/rabbitmq/rabbitmq.router';
34
import { SqsRouter } from '@api/integrations/event/sqs/sqs.router';
@@ -14,6 +15,7 @@ export class EventRouter {
1415
this.router.use('/webhook', new WebhookRouter(configService, ...guards).router);
1516
this.router.use('/websocket', new WebsocketRouter(...guards).router);
1617
this.router.use('/rabbitmq', new RabbitmqRouter(...guards).router);
18+
this.router.use('/nats', new NatsRouter(...guards).router);
1719
this.router.use('/pusher', new PusherRouter(...guards).router);
1820
this.router.use('/sqs', new SqsRouter(...guards).router);
1921
}

0 commit comments

Comments
 (0)