perf: 解析消息

2.0/email-builder
Lei OT 11 months ago
parent 7411763eab
commit 0a28fa4457

@ -361,6 +361,11 @@ export const receivedMsgTypeMapped = {
},
...cloneDeep(emailMsgMapped),
};
/**
* 消息类型处理, 合并各渠道类型
* * WABA: error, system, text, image, video, audio, sticker, contact, location, document, template, interactive, order, list, button, reaction,
* * Email: email
*/
export const whatsappMsgTypeMapped = {
error: {
type: (_m) => ({ type: 'system' }),
@ -372,8 +377,8 @@ export const whatsappMsgTypeMapped = {
},
text: {
type: 'text',
data: (msg) => ({ id: msg.wamid, text: autoLinkText(msg.text.body), originText: msg.text.body, title: msg?.customerProfile?.name || '' }),
renderForReply: (msg) => ({ id: msg.wamid, message: msg.text.body }),
data: (msg) => ({ id: msg.wamid, text: autoLinkText(msg?.text?.body), originText: msg?.text?.body, title: msg?.customerProfile?.name || '' }),
renderForReply: (msg) => ({ id: msg.wamid, message: msg?.text?.body }),
},
image: {
type: 'photo',
@ -520,7 +525,7 @@ export const whatsappMsgTypeMapped = {
type: 'location',
data: (msg) => ({
id: msg.wamid,
title: `位置信息 ${msg.location.name || ''} ↓打开高德地图`,
title: `位置信息 ${msg.location.name || ''} 已转高德地图, ↓点击打开`,
text: msg.location.address, // 地址
// src: `https://uri.amap.com/marker?position=${msg.location.longitude},${msg.location.latitude}&callnative=1`,
src: 'https://cdn.pixabay.com/photo/2016/03/22/04/23/map-1272165_1280.png',
@ -607,9 +612,9 @@ export const parseRenderMessageItem = (msg) => {
export const parseRenderMessageList = (messages) => {
return messages.map((msg, i) => {
let msgContentString = '';
const msgtext = msg?.msgtext || msg?.msgtext_AsJOSN || {};
const messageorigin = msg?.messageorigin || msg?.messageorigin_AsJOSN || {};
const template = msg?.template_AsJOSN || msg?.template_AsJOSN_AsJOSN || {};
const msgtext = msg?.msgtext ?? msg?.msgtext_AsJOSN;
const messageorigin = msg?.messageorigin ?? msg?.messageorigin_AsJOSN;
const template = msg?.template_AsJOSN ?? msg?.template_AsJOSN_AsJOSN;
if (typeof msgtext === 'string') {
// debug: json 缺少一部分
msgContentString = msgtext.charAt(msgtext.length - 1) !== '}' ? msgtext + '}}' : msgtext;
@ -620,8 +625,8 @@ export const parseRenderMessageList = (messages) => {
// }
}
const msgContent = typeof msgtext === 'string' ? JSON.parse(msgContentString) : (msgtext || {});
const msgType = isEmpty(msgContent) ? msg.msgtype : (Object.keys(whatsappMsgTypeMapped).includes(msgContent.type) ? msgContent.type : 'unsupported')
msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...template } : {};
const msgType = Object.keys(whatsappMsgTypeMapped).includes(msgContent.type) ? msgContent.type : 'unsupported';
// const parseMethod = msgContent.bizType === 'whatsapp' ? cloneDeep(whatsappMsgTypeMapped) : {};
let waCode, waError = '';
if ((msgContent?.status || 'failed') === 'failed' && msgContent.errorMessage && msg.msg_direction === 'outbound') {

Loading…
Cancel
Save