From 22d232b56d2b696ff57f10859726960815d9cc79 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Tue, 20 Feb 2024 16:15:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E6=81=AF=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=9A=84id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/msgUtils.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index 8e06764..2ffb741 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -1,4 +1,4 @@ -import { cloneDeep, isEmpty } from "@/utils/utils"; +import { cloneDeep, isEmpty, olog } from "@/utils/utils"; import { v4 as uuid } from "uuid"; export const replaceTemplateString = (str, replacements) => { @@ -169,21 +169,27 @@ export const whatsappMsgTypeMapped = { image: { type: 'photo', data: (msg) => ({ + id: msg.wamid, data: { id: msg.wamid, uri: msg.image.link, width: 200, height: 200, alt: '' }, onOpen: () => { console.log('Open image', msg.image.link); }, }), + renderForReply: (msg) => ({ + id: msg.wamid, photoURL: msg.image.link, width: 200, height: 200, alt: '', + }), }, sticker: { type: 'photo', data: (msg) => ({ + id: msg.wamid, data: { id: msg.wamid, uri: msg.sticker.link, width: 150, height: 120, alt: '' }, }), }, video: { type: 'video', data: (msg) => ({ + id: msg.wamid, data: { id: msg.wamid, videoURL: msg.video.link, @@ -194,6 +200,9 @@ export const whatsappMsgTypeMapped = { }, }, }), + renderForReply: (msg) => ({ + id: msg.wamid, videoURL: msg.video.link, width: 200, height: 200, alt: '', + }), }, audio: { type: 'audio', @@ -224,6 +233,10 @@ export const whatsappMsgTypeMapped = { const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({...r, [v.type]: v}), {}) : null; return { id: msg.wamid, text: templateDataMapped?.body?.text || templateDataMapped?.body?.parameters?.[0]?.text || '', title: msg.template.name } }, + renderForReply: (msg) => { + const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({...r, [v.type]: v}), {}) : null; + return { id: msg.wamid, message: templateDataMapped?.body?.text || templateDataMapped?.body?.parameters?.[0]?.text || '', title: `${msg.template.name}` } + }, }, }; /** @@ -250,7 +263,7 @@ export const parseRenderMessageItem = (msg) => { reply: { message: `${msg.context.id}`, // todo: msg.context.text?.body || msg.context.text, title: msg?.customerProfile?.name || msg.from, - titleColor: "#128c7e", + titleColor: "#53bdeb", // "#128c7e", }, origin: msg.context, }), @@ -280,13 +293,16 @@ export const parseRenderMessageList = (messages, conversationid = null) => { dateString: msgStatusRenderMapped[msgContent?.status || 'failed'] === 'failed' ? '发送失败 ❌' : '', } : {}), - ...(isEmpty(msg.messageorigin_AsJOSN) + ...(isEmpty(msg.messageorigin_AsJOSN) && isEmpty(msgContent.context) ? {} : { reply: { message: msg.messageorigin_AsJOSN.text?.body || msg.messageorigin_AsJOSN.text, title: msg.messageorigin_AsJOSN.senderName || '@', // msg.messageorigin_AsJOSN.from - titleColor: "#128c7e", + ...(typeof whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type]?.renderForReply === 'function' + ? whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type].renderForReply(msg.messageorigin_AsJOSN) + : {}), + titleColor: '#53bdeb', // "#128c7e", // todo: 原始消息的方向 }, origin: msg.messageorigin_AsJOSN, }),