Skip to content

Commit a15d401

Browse files
committed
fix(baileys): resolve type compatibility issues with updated library
Fixes TypeScript compilation errors caused by updated Baileys library types: - Cast IWebMessageInfo[] to WAMessage[] in message processor - Extract participant IDs from GroupParticipant[] objects in group-participants.update event - Add type cast for quoted message assignment The chatwoot-br Baileys fork updated event structures, particularly changing participants from string[] to GroupParticipant[] objects.
1 parent 93a3fb2 commit a15d401

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/api/integrations/channel/whatsapp/baileysMessage.processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Logger } from '@config/logger.config';
2-
import { BaileysEventMap, MessageUpsertType, proto } from 'baileys';
2+
import { BaileysEventMap, MessageUpsertType, proto, WAMessage } from 'baileys';
33
import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs';
44

55
type MessageUpsertPayload = BaileysEventMap['messages.upsert'];
@@ -25,7 +25,7 @@ export class BaileysMessageProcessor {
2525
this.processorLogs.log(`Processing batch of ${messages.length} messages`);
2626
}),
2727
concatMap(({ messages, type, requestId, settings }) =>
28-
from(onMessageReceive({ messages, type, requestId }, settings)).pipe(
28+
from(onMessageReceive({ messages: messages as WAMessage[], type, requestId }, settings)).pipe(
2929
retryWhen((errors) =>
3030
errors.pipe(
3131
tap((error) => this.processorLogs.warn(`Retrying message batch due to error: ${error.message}`)),

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,13 @@ export class BaileysStartupService extends ChannelStartupService {
17881788

17891789
if (events['group-participants.update']) {
17901790
const payload = events['group-participants.update'];
1791-
this.groupHandler['group-participants.update'](payload);
1791+
// Extract participant IDs from GroupParticipant[] to string[]
1792+
const normalizedPayload = {
1793+
id: payload.id,
1794+
participants: payload.participants.map((p) => p.id),
1795+
action: payload.action,
1796+
};
1797+
this.groupHandler['group-participants.update'](normalizedPayload);
17921798
}
17931799
}
17941800

@@ -2154,7 +2160,7 @@ export class BaileysStartupService extends ChannelStartupService {
21542160
const msg = m?.message ? m : ((await this.getMessage(m.key, true)) as proto.IWebMessageInfo);
21552161

21562162
if (msg) {
2157-
quoted = msg;
2163+
quoted = msg as WAMessage;
21582164
}
21592165
}
21602166

0 commit comments

Comments
 (0)