Skip to content

Commit 034619c

Browse files
authored
refactor: extract listType normalization into a helper function
1 parent 5cb5348 commit 034619c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

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

Lines changed: 8 additions & 9 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,15 +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.deviceSentMessage.message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
682-
}
683-
684-
if (message.listMessage?.listType === proto.Message.ListMessage.ListType.PRODUCT_LIST) {
685-
message.listMessage.listType = proto.Message.ListMessage.ListType.SINGLE_SELECT;
686-
}
684+
normalizeListType(message.deviceSentMessage?.message?.listMessage);
685+
normalizeListType(message.listMessage);
687686

688687
return message;
689688
},

0 commit comments

Comments
 (0)