improve normalizeMessageContent

This commit is contained in:
kaatt
2022-12-21 17:44:13 +05:30
committed by Adhiraj Singh
parent 572d0f1dd6
commit 02e05aba42

View File

@@ -569,13 +569,21 @@ export const getContentType = (content: WAProto.IMessage | undefined) => {
* @returns * @returns
*/ */
export const normalizeMessageContent = (content: WAMessageContent | null | undefined): WAMessageContent | undefined => { export const normalizeMessageContent = (content: WAMessageContent | null | undefined): WAMessageContent | undefined => {
content = content?.ephemeralMessage?.message?.viewOnceMessage?.message || if(!content) {
content?.ephemeralMessage?.message || return undefined
content?.viewOnceMessage?.message || }
content?.documentWithCaptionMessage?.message ||
content || for(;;) {
undefined const [key] = Object.keys(content!)
return content const inner = content![key].message
if(!inner) {
content = inner
} else {
break
}
}
return content!
} }
/** /**
@@ -725,6 +733,7 @@ export const downloadMediaMessage = async(
const contentType = getContentType(mContent) const contentType = getContentType(mContent)
let mediaType = contentType?.replace('Message', '') as MediaType let mediaType = contentType?.replace('Message', '') as MediaType
const media = mContent[contentType!] const media = mContent[contentType!]
console.log({ mContent, contentType, media })
if(!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) { if(!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) {
throw new Boom(`"${contentType}" message is not a media message`) throw new Boom(`"${contentType}" message is not a media message`)