Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion src/api/controllers/label.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCollectionsDto } from '@api/dto/business.dto';
ο»Ώimport { getCollectionsDto } from '@api/dto/business.dto';
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first import line contains a UTF-8 BOM/zero-width character (shown as an invisible character before import). This can cause noisy diffs and occasional tooling/lint issues. Please remove the BOM so the file starts with a plain import ....

Suggested change
ο»Ώimport { getCollectionsDto } from '@api/dto/business.dto';
import { getCollectionsDto } from '@api/dto/business.dto';

Copilot uses AI. Check for mistakes.
import { OfferCallDto } from '@api/dto/call.dto';
import {
ArchiveChatDto,
Expand Down Expand Up @@ -4255,6 +4255,20 @@ export class BaileysStartupService extends ChannelStartupService {
}));
}

public async syncLabels(): Promise<LabelDto[]> {
// 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) {
Expand Down
12 changes: 11 additions & 1 deletion src/api/routes/label.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LabelDto>({
request: req,
schema: null,
ClassRef: LabelDto,
execute: (instance) => labelController.syncLabels(instance),
});

Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET /label/syncLabels/:instanceName triggers a server-side re-sync with WhatsApp (side effects + external I/O). Using GET for a mutating/side-effecting operation breaks HTTP semantics and increases the risk of accidental invocation via caching/prefetching. Consider changing this to POST (or at least add Cache-Control: no-store / disable caching) to make the intent explicit and safer for intermediaries.

Suggested change
res.set('Cache-Control', 'no-store');

Copilot uses AI. Check for mistakes.
return res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('handleLabel'), ...guards, async (req, res) => {
const response = await this.dataValidate<HandleLabelDto>({
request: req,
Expand All @@ -33,4 +43,4 @@ export class LabelRouter extends RouterBroker {
}

public readonly router: Router = Router();
}
}
Loading