[core] Add replyTo.media if possible - all engines
This commit is contained in:
1 parent
f70bcd0b53
commit
798d782869
5 files changed
+67
-5
No files matched your search
@@ -2196,6 +2196,16 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
const media = await this.downloadMediaSafe(message);
|
||||
wamessage.media = media;
|
||||
}
|
||||
if (downloadMedia && wamessage.replyTo?.hasMedia) {
|
||||
const msg = {
|
||||
Message: wamessage.replyTo._data,
|
||||
Info: {
|
||||
Chat: message.Info.Chat,
|
||||
ID: wamessage.replyTo.id || '',
|
||||
},
|
||||
};
|
||||
wamessage.replyTo.media = await this.downloadMediaSafe(msg);
|
||||
}
|
||||
return wamessage;
|
||||
}
|
||||
|
||||
@@ -2405,10 +2415,13 @@ export class WhatsappSessionGoWSCore extends WhatsappSession {
|
||||
return null;
|
||||
}
|
||||
const body = extractBody(quotedMessage);
|
||||
const mediaContent = extractMediaContent(quotedMessage);
|
||||
return {
|
||||
id: contextInfo.stanzaID,
|
||||
participant: toCusFormat(contextInfo.participant),
|
||||
body: body,
|
||||
hasMedia: Boolean(mediaContent),
|
||||
media: null,
|
||||
_data: quotedMessage,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Browsers, WABrowserDescription } from '@adiwajshing/baileys';
|
||||
import makeWASocket, {
|
||||
Browsers,
|
||||
Chat,
|
||||
Contact,
|
||||
decryptPollVote,
|
||||
@@ -19,6 +19,7 @@ import makeWASocket, {
|
||||
PresenceData,
|
||||
proto,
|
||||
SocketConfig,
|
||||
WABrowserDescription,
|
||||
WAMessageContent,
|
||||
WAMessageKey,
|
||||
WAMessageUpdate,
|
||||
@@ -183,13 +184,13 @@ import * as NodeCache from 'node-cache';
|
||||
import {
|
||||
filter,
|
||||
fromEvent,
|
||||
groupBy,
|
||||
identity,
|
||||
merge,
|
||||
mergeAll,
|
||||
mergeMap,
|
||||
Observable,
|
||||
partition,
|
||||
groupBy,
|
||||
share,
|
||||
tap,
|
||||
} from 'rxjs';
|
||||
@@ -2482,9 +2483,24 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
|
||||
return null;
|
||||
}
|
||||
// Media
|
||||
if (downloadMedia) {
|
||||
const media = await this.downloadMediaSafe(message);
|
||||
wamessage.media = media;
|
||||
if (downloadMedia && wamessage.hasMedia) {
|
||||
wamessage.media = await this.downloadMediaSafe(message);
|
||||
}
|
||||
|
||||
if (downloadMedia && wamessage.replyTo?.hasMedia) {
|
||||
const mediaContent = extractMediaContent(wamessage.replyTo._data);
|
||||
const m = {
|
||||
message: wamessage.replyTo._data,
|
||||
key: {
|
||||
id:
|
||||
wamessage.replyTo.id ||
|
||||
mediaContent.fileSha256 ||
|
||||
mediaContent.fileEncSha256 ||
|
||||
mediaContent.mediaKeyTimestamp,
|
||||
remoteJid: message.key.remoteJid,
|
||||
},
|
||||
};
|
||||
wamessage.replyTo.media = await this.downloadMediaSafe(m);
|
||||
}
|
||||
return wamessage;
|
||||
}
|
||||
@@ -2544,10 +2560,15 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
|
||||
return null;
|
||||
}
|
||||
const body = extractBody(quotedMessage);
|
||||
const mediaContent = extractMediaContent(quotedMessage);
|
||||
return {
|
||||
id: contextInfo.stanzaId,
|
||||
participant: toCusFormat(contextInfo.participant),
|
||||
body: body,
|
||||
// Media
|
||||
hasMedia: Boolean(mediaContent),
|
||||
media: null,
|
||||
// Data
|
||||
_data: quotedMessage,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1991,6 +1991,12 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
const media = await this.downloadMediaSafe(message);
|
||||
wamessage.media = media;
|
||||
}
|
||||
if (downloadMedia && wamessage.replyTo?.hasMedia) {
|
||||
const quotedMessage = await message.getQuotedMessage().catch(() => null);
|
||||
if (quotedMessage) {
|
||||
wamessage.replyTo.media = await this.downloadMediaSafe(quotedMessage);
|
||||
}
|
||||
}
|
||||
return wamessage;
|
||||
}
|
||||
|
||||
@@ -2158,6 +2164,8 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
id: quotedStanzaId || quotedMsg?.id?.id,
|
||||
participant: quotedParticipant,
|
||||
body: quotedMsg?.caption || quotedMsg?.body,
|
||||
hasMedia: Boolean(quotedMsg?.directPath),
|
||||
media: null,
|
||||
_data: quotedMsg,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2089,12 +2089,15 @@ export class WhatsappSessionWPPCore extends WhatsappSession {
|
||||
quotedMessage?.author ||
|
||||
quotedMessage?.from ||
|
||||
null;
|
||||
const hasMedia = getHasMedia(quotedMessage);
|
||||
return {
|
||||
id: quotedMessageId,
|
||||
participant: toCusFormat(
|
||||
Deserialized(quotedParticipant) || quotedParticipant,
|
||||
),
|
||||
body: getMessageBody(quotedMessage),
|
||||
hasMedia: hasMedia,
|
||||
media: null,
|
||||
_data: quotedMessage,
|
||||
};
|
||||
}
|
||||
@@ -2105,6 +2108,12 @@ export class WhatsappSessionWPPCore extends WhatsappSession {
|
||||
const media = await this.downloadMediaSafe(message);
|
||||
wamessage.media = media;
|
||||
}
|
||||
if (downloadMedia && wamessage.replyTo?.hasMedia) {
|
||||
const quotedMessage = message?.quotedMsg || message?._data?.quotedMsg;
|
||||
if (quotedMessage) {
|
||||
wamessage.replyTo.media = await this.downloadMediaSafe(quotedMessage);
|
||||
}
|
||||
}
|
||||
return wamessage;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
ChatIdProperty,
|
||||
MessageIdOnlyProperty,
|
||||
} from '@waha/structures/properties.dto';
|
||||
import { WAMedia } from '@waha/structures/media.dto';
|
||||
|
||||
export class ReplyToMessage {
|
||||
@MessageIdOnlyProperty()
|
||||
@@ -16,6 +17,16 @@ export class ReplyToMessage {
|
||||
})
|
||||
body?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Indicates if the message has media available for download',
|
||||
})
|
||||
hasMedia: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Media object for the message if any and downloaded',
|
||||
})
|
||||
media?: WAMedia;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Raw data from reply's message",
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user