todo: 引用消息

dev/chat
Lei OT 2 years ago
parent a291f57b8f
commit 34f900469c

@ -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,
}),

Loading…
Cancel
Save