Skip to content

Commit 8e7e13d

Browse files
authored
fix(whatsapp): resolve this.isZero error in list messages by removing destructive JSON cloning (#2461)
* fix(whatsapp): resolve this.isZero error in list messages by removing destructive JSON cloning * refactor: extract listType normalization into a helper function
1 parent 6e737d4 commit 8e7e13d

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ async function getVideoDuration(input: Buffer | string | Readable): Promise<numb
228228
return Math.round(parseFloat(duration));
229229
}
230230

231+
function normalizeListType(listMessage?: proto.Message.IListMessage | null): void {
232+
if (listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST) {
233+
listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
234+
}
235+
}
236+
231237
export class BaileysStartupService extends ChannelStartupService {
232238
private messageProcessor = new BaileysMessageProcessor();
233239

@@ -756,19 +762,8 @@ export class BaileysStartupService extends ChannelStartupService {
756762
userDevicesCache: this.userDevicesCache,
757763
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
758764
patchMessageBeforeSending(message) {
759-
if (
760-
message.deviceSentMessage?.message?.listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST
761-
) {
762-
message = JSON.parse(JSON.stringify(message));
763-
764-
message.deviceSentMessage.message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
765-
}
766-
767-
if (message.listMessage?.listType == proto.Message.ListMessage.ListType.PRODUCT_LIST) {
768-
message = JSON.parse(JSON.stringify(message));
769-
770-
message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
771-
}
765+
normalizeListType(message.deviceSentMessage?.message?.listMessage);
766+
normalizeListType(message.listMessage);
772767

773768
return message;
774769
},

0 commit comments

Comments
 (0)