feat: Add NATS integration and update Baileys service

- Create Nats table in PostgreSQL migration
- Disable message recovery logic in Baileys service
- Remove console log in instance creation route
This commit is contained in:
Davidson Gomes 2025-02-25 15:42:40 -03:00
parent b58d9e957f
commit 8a54efe11c
3 changed files with 30 additions and 14 deletions

View File

@ -0,0 +1,17 @@
-- CreateTable
CREATE TABLE "Nats" (
"id" TEXT NOT NULL,
"enabled" BOOLEAN NOT NULL DEFAULT false,
"events" JSONB NOT NULL,
"createdAt" TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP NOT NULL,
"instanceId" TEXT NOT NULL,
CONSTRAINT "Nats_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Nats_instanceId_key" ON "Nats"("instanceId");
-- AddForeignKey
ALTER TABLE "Nats" ADD CONSTRAINT "Nats_instanceId_fkey" FOREIGN KEY ("instanceId") REFERENCES "Instance"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -1148,23 +1148,23 @@ export class BaileysStartupService extends ChannelStartupService {
} }
} }
if (received.messageStubParameters && received.messageStubParameters[0] === 'Message absent from node') { // if (received.messageStubParameters && received.messageStubParameters[0] === 'Message absent from node') {
this.logger.info(`Recovering message lost messageId: ${received.key.id}`); // this.logger.info(`Recovering message lost messageId: ${received.key.id}`);
await this.baileysCache.set(received.key.id, { // await this.baileysCache.set(received.key.id, {
message: received, // message: received,
retry: 0, // retry: 0,
}); // });
continue; // continue;
} // }
const retryCache = (await this.baileysCache.get(received.key.id)) || null; // const retryCache = (await this.baileysCache.get(received.key.id)) || null;
if (retryCache) { // if (retryCache) {
this.logger.info('Recovered message lost'); // this.logger.info('Recovered message lost');
await this.baileysCache.delete(received.key.id); // await this.baileysCache.delete(received.key.id);
} // }
// Cache to avoid duplicate messages // Cache to avoid duplicate messages
const messageKey = `${this.instance.id}_${received.key.id}`; const messageKey = `${this.instance.id}_${received.key.id}`;

View File

@ -15,7 +15,6 @@ export class InstanceRouter extends RouterBroker {
super(); super();
this.router this.router
.post('/create', ...guards, async (req, res) => { .post('/create', ...guards, async (req, res) => {
console.log('create instance', req.body);
const response = await this.dataValidate<InstanceDto>({ const response = await this.dataValidate<InstanceDto>({
request: req, request: req,
schema: instanceSchema, schema: instanceSchema,