Skip to content
Merged
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: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Unreleased
# 2.3.2 (2025-09-02)

### Fixed
### Widget Works Modification

* [WIDGET-WORKS] Fix `PrismaClientValidationError` in `messages.update` (missing `Message` relation) by guarding `messageUpdate.create` calls.
* [WIDGET-WORKS] Guard `messages.update` cache cleanup with a derived key and optional `MESSAGE_UPDATE_CACHE_DELETE_DISABLED` flag to prevent cache.delete crash-loops.

# 2.3.2 (2025-09-02)

### Features

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from '@config/logger.config';
import { BaileysEventMap, MessageUpsertType, proto } from 'baileys';
import { BaileysEventMap, MessageUpsertType } from 'baileys';
import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs';

type MessageUpsertPayload = BaileysEventMap['messages.upsert'];
Expand Down
28 changes: 22 additions & 6 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ import { BaileysMessageProcessor } from './baileysMessage.processor';
import { useVoiceCallsBaileys } from './voiceCalls/useVoiceCallsBaileys';

// [WIDGET-WORKS] Local helper because isJidUser is absent from current Baileys typings.
const isJidUser = (jid?: string) => !!jid && jid.includes('@s.whatsapp.net') && !isJidGroup(jid) && !isJidBroadcast(jid);
const isJidUser = (jid?: string) =>
!!jid && jid.includes('@s.whatsapp.net') && !isJidGroup(jid) && !isJidBroadcast(jid);
// [WIDGET-WORKS] Gracefully access non-typed Baileys senderPn on keys.
const getSenderPn = (key: WAMessageKey | proto.IMessageKey) => (key as any)?.senderPn;

Expand Down Expand Up @@ -1478,9 +1479,16 @@ export class BaileysStartupService extends ChannelStartupService {
if (update.message === null && update.status === undefined) {
this.sendDataWebhook(Events.MESSAGES_DELETE, key);

if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE)
await this.prismaRepository.messageUpdate.create({ data: message });

if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
// [WIDGET-WORKS] Guard against missing parent message to prevent PrismaClientValidationError
if (message.messageId) {
await this.prismaRepository.messageUpdate.create({ data: message });
} else {
this.logger.warn(
`[WIDGET-WORKS] Skipping messageUpdate.create for key ${key.id}: Parent message not found.`,
);
}
}
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot?.enabled) {
this.chatwootService.eventWhatsapp(
Events.MESSAGES_DELETE,
Expand Down Expand Up @@ -1524,8 +1532,16 @@ export class BaileysStartupService extends ChannelStartupService {

this.sendDataWebhook(Events.MESSAGES_UPDATE, message);

if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE)
await this.prismaRepository.messageUpdate.create({ data: message });
if (this.configService.get<Database>('DATABASE').SAVE_DATA.MESSAGE_UPDATE) {
// [WIDGET-WORKS] Guard against missing parent message to prevent PrismaClientValidationError
if (message.messageId) {
await this.prismaRepository.messageUpdate.create({ data: message });
} else {
this.logger.warn(
`[WIDGET-WORKS] Skipping messageUpdate.create for key ${key.id}: Parent message not found.`,
);
}
}

if (!skipMessageUpdateCacheDelete) {
const cacheDeleteKey = `${this.instanceId}:${message.remoteJid}:${message.keyId}`;
Expand Down