Skip to content

Commit 6e9c77d

Browse files
committed
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.
1 parent fc521b8 commit 6e9c77d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCollectionsDto } from '@api/dto/business.dto';
1+
import { getCollectionsDto } from '@api/dto/business.dto';
22
import { OfferCallDto } from '@api/dto/call.dto';
33
import {
44
ArchiveChatDto,
@@ -4255,6 +4255,20 @@ export class BaileysStartupService extends ChannelStartupService {
42554255
}));
42564256
}
42574257

4258+
public async syncLabels(): Promise<LabelDto[]> {
4259+
// Force Baileys to re-download label app state from WhatsApp (incremental)
4260+
// Using true for isLatest = incremental sync (safe, no disconnect)
4261+
// Using false would download full snapshot and may cause disconnection
4262+
await this.client.resyncAppState(['regular'], true);
4263+
4264+
// Wait for LABELS_EDIT and LABELS_ASSOCIATION events to be processed
4265+
await new Promise((resolve) => setTimeout(resolve, 3000));
4266+
4267+
// Return the now-updated labels from database
4268+
return this.fetchLabels();
4269+
}
4270+
4271+
42584272
public async handleLabel(data: HandleLabelDto) {
42594273
const whatsappContact = await this.whatsappNumber({ numbers: [data.number] });
42604274
if (whatsappContact.length === 0) {

0 commit comments

Comments
 (0)