Merge branch 'main' of github.com:hainatravel/global-sales

dev/mobile
Jimmy Liow 2 years ago
commit a6e036ed38

@ -1,4 +1,4 @@
import { cloneDeep, isEmpty } from "@/utils/utils"; import { cloneDeep, isEmpty, olog } from "@/utils/utils";
import { v4 as uuid } from "uuid"; import { v4 as uuid } from "uuid";
export const replaceTemplateString = (str, replacements) => { export const replaceTemplateString = (str, replacements) => {
@ -169,21 +169,27 @@ export const whatsappMsgTypeMapped = {
image: { image: {
type: 'photo', type: 'photo',
data: (msg) => ({ data: (msg) => ({
id: msg.wamid,
data: { id: msg.wamid, uri: msg.image.link, width: 200, height: 200, alt: '' }, data: { id: msg.wamid, uri: msg.image.link, width: 200, height: 200, alt: '' },
onOpen: () => { onOpen: () => {
console.log('Open image', msg.image.link); console.log('Open image', msg.image.link);
}, },
}), }),
renderForReply: (msg) => ({
id: msg.wamid, photoURL: msg.image.link, width: 200, height: 200, alt: '',
}),
}, },
sticker: { sticker: {
type: 'photo', type: 'photo',
data: (msg) => ({ data: (msg) => ({
id: msg.wamid,
data: { id: msg.wamid, uri: msg.sticker.link, width: 150, height: 120, alt: '' }, data: { id: msg.wamid, uri: msg.sticker.link, width: 150, height: 120, alt: '' },
}), }),
}, },
video: { video: {
type: 'video', type: 'video',
data: (msg) => ({ data: (msg) => ({
id: msg.wamid,
data: { data: {
id: msg.wamid, id: msg.wamid,
videoURL: msg.video.link, 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: { audio: {
type: '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; 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 } 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: { reply: {
message: `${msg.context.id}`, // todo: msg.context.text?.body || msg.context.text, message: `${msg.context.id}`, // todo: msg.context.text?.body || msg.context.text,
title: msg?.customerProfile?.name || msg.from, title: msg?.customerProfile?.name || msg.from,
titleColor: "#128c7e", titleColor: "#53bdeb", // "#128c7e",
}, },
origin: msg.context, origin: msg.context,
}), }),
@ -280,13 +293,16 @@ export const parseRenderMessageList = (messages, conversationid = null) => {
dateString: msgStatusRenderMapped[msgContent?.status || 'failed'] === 'failed' ? '发送失败 ❌' : '', dateString: msgStatusRenderMapped[msgContent?.status || 'failed'] === 'failed' ? '发送失败 ❌' : '',
} }
: {}), : {}),
...(isEmpty(msg.messageorigin_AsJOSN) ...(isEmpty(msg.messageorigin_AsJOSN) && isEmpty(msgContent.context)
? {} ? {}
: { : {
reply: { reply: {
message: msg.messageorigin_AsJOSN.text?.body || msg.messageorigin_AsJOSN.text, message: msg.messageorigin_AsJOSN.text?.body || msg.messageorigin_AsJOSN.text,
title: msg.messageorigin_AsJOSN.senderName || '@', // msg.messageorigin_AsJOSN.from 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, origin: msg.messageorigin_AsJOSN,
}), }),

Loading…
Cancel
Save