Skip to content

Commit 9992cf8

Browse files
committed
fix(baileys): preserve protobuf Long prototypes in patchMessageBeforeSending
JSON.parse(JSON.stringify(message)) was stripping prototypes from protobuf Long objects, causing 'TypeError: this.isZero is not a function' when sendList encoded outbound messages and silent delivery failures on sendButtons. Replace the round-trip with an in-place normalizeListType helper. Cherry-picked from upstream PR EvolutionAPI#2461.
1 parent cd800f2 commit 9992cf8

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ async function getVideoDuration(input: Buffer | string | Readable): Promise<numb
224224
return Math.round(parseFloat(duration));
225225
}
226226

227+
function normalizeListType(listMessage?: proto.Message.IListMessage | null): void {
228+
if (listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST) {
229+
listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
230+
}
231+
}
232+
227233
export class BaileysStartupService extends ChannelStartupService {
228234
private messageProcessor = new BaileysMessageProcessor();
229235

@@ -675,20 +681,8 @@ export class BaileysStartupService extends ChannelStartupService {
675681
userDevicesCache: this.userDevicesCache,
676682
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
677683
patchMessageBeforeSending(message) {
678-
if (
679-
message.deviceSentMessage?.message?.listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST
680-
) {
681-
message = JSON.parse(JSON.stringify(message));
682-
683-
message.deviceSentMessage.message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
684-
}
685-
686-
if (message.listMessage?.listType == proto.Message.ListMessage.ListType.PRODUCT_LIST) {
687-
message = JSON.parse(JSON.stringify(message));
688-
689-
message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
690-
}
691-
684+
normalizeListType(message.deviceSentMessage?.message?.listMessage);
685+
normalizeListType(message.listMessage);
692686
return message;
693687
},
694688
};

0 commit comments

Comments
 (0)