From aa9f394f6bc5ebe4c136c5780ab1b1fda87d90b1 Mon Sep 17 00:00:00 2001 From: Josue Cascante COCO Date: Sun, 8 Feb 2026 15:22:14 -0600 Subject: [PATCH 1/5] feat(label): add syncLabels controller method Delegates to service.syncLabels() via waMonitor, following the same pattern as fetchLabels and handleLabel. --- src/api/controllers/label.controller.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/controllers/label.controller.ts b/src/api/controllers/label.controller.ts index 2df112f70..953f55adb 100644 --- a/src/api/controllers/label.controller.ts +++ b/src/api/controllers/label.controller.ts @@ -12,4 +12,8 @@ export class LabelController { public async handleLabel({ instanceName }: InstanceDto, data: HandleLabelDto) { return await this.waMonitor.waInstances[instanceName].handleLabel(data); } -} + + public async syncLabels({ instanceName }: InstanceDto) { + return await this.waMonitor.waInstances[instanceName].syncLabels(); + } +} \ No newline at end of file From fc521b8ca0b44afbb1f3bc9802057ad05d858fb9 Mon Sep 17 00:00:00 2001 From: Josue Cascante COCO Date: Sun, 8 Feb 2026 15:22:39 -0600 Subject: [PATCH 2/5] feat(label): add GET /label/syncLabels/:instanceName route New endpoint that forces WhatsApp to re-download labels via Baileys resyncAppState(['regular'], true) before returning updated labels from DB. Uses same dataValidate pattern as findLabels. --- src/api/routes/label.router.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api/routes/label.router.ts b/src/api/routes/label.router.ts index bfb4a0859..4983def81 100644 --- a/src/api/routes/label.router.ts +++ b/src/api/routes/label.router.ts @@ -20,6 +20,16 @@ export class LabelRouter extends RouterBroker { return res.status(HttpStatus.OK).json(response); }) + .get(this.routerPath('syncLabels'), ...guards, async (req, res) => { + const response = await this.dataValidate({ + request: req, + schema: null, + ClassRef: LabelDto, + execute: (instance) => labelController.syncLabels(instance), + }); + + return res.status(HttpStatus.OK).json(response); + }) .post(this.routerPath('handleLabel'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, @@ -33,4 +43,4 @@ export class LabelRouter extends RouterBroker { } public readonly router: Router = Router(); -} +} \ No newline at end of file From 6e9c77d27734bcc9d1dbdcb18df3199c1929e0f4 Mon Sep 17 00:00:00 2001 From: Josue Cascante COCO Date: Sun, 8 Feb 2026 15:25:58 -0600 Subject: [PATCH 3/5] feat(label): add syncLabels method to BaileysStartupService Uses Baileys client.resyncAppState(['regular'], true) to force an incremental re-download of WhatsApp app state (labels). Waits 3s for LABELS_EDIT/LABELS_ASSOCIATION event handlers to process, then returns updated labels from DB via fetchLabels(). Key: isLatest=true means incremental (safe, no disconnect). isLatest=false would download full snapshot and cause disconnection. --- .../channel/whatsapp/whatsapp.baileys.service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 60e857fcc..ff6e8c8ce 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -1,4 +1,4 @@ -import { getCollectionsDto } from '@api/dto/business.dto'; +import { getCollectionsDto } from '@api/dto/business.dto'; import { OfferCallDto } from '@api/dto/call.dto'; import { ArchiveChatDto, @@ -4255,6 +4255,20 @@ export class BaileysStartupService extends ChannelStartupService { })); } + public async syncLabels(): Promise { + // Force Baileys to re-download label app state from WhatsApp (incremental) + // Using true for isLatest = incremental sync (safe, no disconnect) + // Using false would download full snapshot and may cause disconnection + await this.client.resyncAppState(['regular'], true); + + // Wait for LABELS_EDIT and LABELS_ASSOCIATION events to be processed + await new Promise((resolve) => setTimeout(resolve, 3000)); + + // Return the now-updated labels from database + return this.fetchLabels(); + } + + public async handleLabel(data: HandleLabelDto) { const whatsappContact = await this.whatsappNumber({ numbers: [data.number] }); if (whatsappContact.length === 0) { From 8fc778bc272dda8592eb660358cfe532569cd77a Mon Sep 17 00:00:00 2001 From: Josue Cascante COCO Date: Sun, 8 Feb 2026 15:28:49 -0600 Subject: [PATCH 4/5] feat(label): add syncLabels stub to Evolution Channel Throws BadRequestException as syncLabels is only available for Baileys (WhatsApp Web) connections. --- .../channel/evolution/evolution.channel.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/integrations/channel/evolution/evolution.channel.service.ts b/src/api/integrations/channel/evolution/evolution.channel.service.ts index 87bea08e6..1be3a5a62 100644 --- a/src/api/integrations/channel/evolution/evolution.channel.service.ts +++ b/src/api/integrations/channel/evolution/evolution.channel.service.ts @@ -876,6 +876,9 @@ export class EvolutionStartupService extends ChannelStartupService { public async fetchLabels() { throw new BadRequestException('Method not available on Evolution Channel'); } + public async syncLabels() { + throw new BadRequestException('Method not available on Evolution Channel'); + } public async handleLabel() { throw new BadRequestException('Method not available on Evolution Channel'); } From e7df2e23a18c2b66254405af493ba00e2a34a85b Mon Sep 17 00:00:00 2001 From: Josue Cascante COCO Date: Sun, 8 Feb 2026 15:28:51 -0600 Subject: [PATCH 5/5] feat(label): add syncLabels stub to WhatsApp Business API Throws BadRequestException as syncLabels is only available for Baileys (WhatsApp Web) connections. --- src/api/integrations/channel/meta/whatsapp.business.service.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api/integrations/channel/meta/whatsapp.business.service.ts b/src/api/integrations/channel/meta/whatsapp.business.service.ts index 1e4808c15..20a44c5f5 100644 --- a/src/api/integrations/channel/meta/whatsapp.business.service.ts +++ b/src/api/integrations/channel/meta/whatsapp.business.service.ts @@ -1759,6 +1759,9 @@ export class BusinessStartupService extends ChannelStartupService { public async fetchLabels() { throw new BadRequestException('Method not available on WhatsApp Business API'); } + public async syncLabels() { + throw new BadRequestException('Method not available on WhatsApp Business API'); + } public async handleLabel() { throw new BadRequestException('Method not available on WhatsApp Business API'); }