Skip to content

Commit 72b0833

Browse files
committed
fix(baileys): cast messageRaw and its properties to any for type safety
1 parent 2e3c818 commit 72b0833

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,10 +1201,10 @@ export class BaileysStartupService extends ChannelStartupService {
12011201
}
12021202
}
12031203

1204-
const messageRaw = this.prepareMessage(received);
1204+
const messageRaw = this.prepareMessage(received) as any;
12051205

12061206
if (messageRaw.messageType === 'pollUpdateMessage') {
1207-
const pollCreationKey = messageRaw.message.pollUpdateMessage.pollCreationMessageKey;
1207+
const pollCreationKey = (messageRaw.message as any).pollUpdateMessage.pollCreationMessageKey;
12081208
const pollMessage = (await this.getMessage(pollCreationKey, true)) as proto.IWebMessageInfo;
12091209
const pollMessageSecret = (await this.getMessage(pollCreationKey)) as any;
12101210

@@ -1213,7 +1213,7 @@ export class BaileysStartupService extends ChannelStartupService {
12131213
(pollMessage.message as any).pollCreationMessage?.options ||
12141214
(pollMessage.message as any).pollCreationMessageV3?.options ||
12151215
[];
1216-
const pollVote = messageRaw.message.pollUpdateMessage.vote;
1216+
const pollVote = (messageRaw.message as any).pollUpdateMessage.vote;
12171217

12181218
const voterJid = received.key.fromMe
12191219
? this.instance.wuid
@@ -1293,14 +1293,14 @@ export class BaileysStartupService extends ChannelStartupService {
12931293
})
12941294
.map((option) => option.optionName);
12951295

1296-
messageRaw.message.pollUpdateMessage.vote.selectedOptions = selectedOptionNames;
1296+
(messageRaw.message as any).pollUpdateMessage.vote.selectedOptions = selectedOptionNames;
12971297

12981298
const pollUpdates = pollOptions.map((option) => ({
12991299
name: option.optionName,
13001300
voters: selectedOptionNames.includes(option.optionName) ? [successfulVoterJid] : [],
13011301
}));
13021302

1303-
messageRaw.pollUpdates = pollUpdates;
1303+
(messageRaw as any).pollUpdates = pollUpdates;
13041304
}
13051305
}
13061306

@@ -1348,13 +1348,14 @@ export class BaileysStartupService extends ChannelStartupService {
13481348
});
13491349

13501350
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
1351-
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(received, this)}`;
1351+
(messageRaw.message as any).speechToText =
1352+
`[audio] ${await this.openaiService.speechToText(received, this)}`;
13521353
}
13531354
}
13541355

13551356
if (this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
13561357
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1357-
const { pollUpdates, ...messageData } = messageRaw;
1358+
const { pollUpdates, ...messageData } = messageRaw as any;
13581359
const msg = await this.prismaRepository.message.create({ data: messageData });
13591360

13601361
const { remoteJid } = received.key;
@@ -1430,7 +1431,7 @@ export class BaileysStartupService extends ChannelStartupService {
14301431

14311432
const mediaUrl = await s3Service.getObjectUrl(fullName);
14321433

1433-
messageRaw.message.mediaUrl = mediaUrl;
1434+
(messageRaw.message as any).mediaUrl = mediaUrl;
14341435

14351436
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
14361437
}
@@ -1452,7 +1453,7 @@ export class BaileysStartupService extends ChannelStartupService {
14521453
);
14531454

14541455
if (buffer) {
1455-
messageRaw.message.base64 = buffer.toString('base64');
1456+
(messageRaw.message as any).base64 = buffer.toString('base64');
14561457
} else {
14571458
// retry to download media
14581459
const buffer = await downloadMediaMessage(
@@ -1463,7 +1464,7 @@ export class BaileysStartupService extends ChannelStartupService {
14631464
);
14641465

14651466
if (buffer) {
1466-
messageRaw.message.base64 = buffer.toString('base64');
1467+
(messageRaw.message as any).base64 = buffer.toString('base64');
14671468
}
14681469
}
14691470
} catch (error) {
@@ -1475,16 +1476,16 @@ export class BaileysStartupService extends ChannelStartupService {
14751476
this.logger.verbose(messageRaw);
14761477

14771478
sendTelemetry(`received.message.${messageRaw.messageType ?? 'unknown'}`);
1478-
if (messageRaw.key.remoteJid?.includes('@lid') && messageRaw.key.remoteJidAlt) {
1479-
messageRaw.key.remoteJid = messageRaw.key.remoteJidAlt;
1479+
if ((messageRaw.key as any).remoteJid?.includes('@lid') && (messageRaw.key as any).remoteJidAlt) {
1480+
(messageRaw.key as any).remoteJid = (messageRaw.key as any).remoteJidAlt;
14801481
}
14811482
console.log(messageRaw);
14821483

14831484
this.sendDataWebhook(Events.MESSAGES_UPSERT, messageRaw);
14841485

14851486
await chatbotController.emit({
14861487
instance: { instanceName: this.instance.name, instanceId: this.instanceId },
1487-
remoteJid: messageRaw.key.remoteJid,
1488+
remoteJid: (messageRaw.key as any).remoteJid,
14881489
msg: messageRaw,
14891490
pushName: messageRaw.pushName,
14901491
});
@@ -1513,9 +1514,11 @@ export class BaileysStartupService extends ChannelStartupService {
15131514
await saveOnWhatsappCache([
15141515
{
15151516
remoteJid:
1516-
messageRaw.key.addressingMode === 'lid' ? messageRaw.key.remoteJidAlt : messageRaw.key.remoteJid,
1517-
remoteJidAlt: messageRaw.key.remoteJidAlt,
1518-
lid: messageRaw.key.addressingMode === 'lid' ? 'lid' : null,
1517+
(messageRaw.key as any).addressingMode === 'lid'
1518+
? (messageRaw.key as any).remoteJidAlt
1519+
: (messageRaw.key as any).remoteJid,
1520+
remoteJidAlt: (messageRaw.key as any).remoteJidAlt,
1521+
lid: (messageRaw.key as any).addressingMode === 'lid' ? 'lid' : null,
15191522
},
15201523
]);
15211524
}
@@ -2427,7 +2430,7 @@ export class BaileysStartupService extends ChannelStartupService {
24272430
messageSent.messageTimestamp = messageSent.messageTimestamp?.toNumber();
24282431
}
24292432

2430-
const messageRaw = this.prepareMessage(messageSent);
2433+
const messageRaw = this.prepareMessage(messageSent) as any;
24312434

24322435
const isMedia =
24332436
messageSent?.message?.imageMessage ||
@@ -2449,14 +2452,15 @@ export class BaileysStartupService extends ChannelStartupService {
24492452
);
24502453
}
24512454

2452-
if (this.configService.get<Openai>('OPENAI').ENABLED && messageRaw?.message?.audioMessage) {
2455+
if (this.configService.get<Openai>('OPENAI').ENABLED && (messageRaw as any)?.message?.audioMessage) {
24532456
const openAiDefaultSettings = await this.prismaRepository.openaiSetting.findFirst({
24542457
where: { instanceId: this.instanceId },
24552458
include: { OpenaiCreds: true },
24562459
});
24572460

24582461
if (openAiDefaultSettings && openAiDefaultSettings.openaiCredsId && openAiDefaultSettings.speechToText) {
2459-
messageRaw.message.speechToText = `[audio] ${await this.openaiService.speechToText(messageRaw, this)}`;
2462+
(messageRaw.message as any).speechToText =
2463+
`[audio] ${await this.openaiService.speechToText(messageRaw, this)}`;
24602464
}
24612465
}
24622466

0 commit comments

Comments
 (0)