|
|
|
@ -512,6 +512,9 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
return { id: msg.wamid, message: templateDataMapped?.body?.text || templateDataMapped?.body?.parameters?.[0]?.text || '', title: `${msg.template.name}` };
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
email: {
|
|
|
|
|
data: (msg) => ({ id: msg.id, subject: msg.email.subject, originText: msg.text.body, title: msg?.customerProfile?.name || '' }),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* render received msg
|
|
|
|
@ -534,7 +537,7 @@ export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
customer_name: msg?.customerProfile?.name || '',
|
|
|
|
|
whatsapp_name: msg?.customerProfile?.name || '',
|
|
|
|
|
whatsapp_phone_number: isEmpty(msg?.customerProfile) ? msg.to : msg.from,
|
|
|
|
|
whatsapp_msg_type: msg.type,
|
|
|
|
|
whatsapp_msg_type: msg.msg_source==='WABA' ? msg.type : '',
|
|
|
|
|
statusCN: msgStatusRenderMappedCN[msg?.status || 'failed'],
|
|
|
|
|
statusTitle: msgStatusRenderMappedCN[msg?.status || 'failed'],
|
|
|
|
|
replyButton: ['text', 'document', 'image'].includes(msg.type) && (msg?.status || '') !== 'failed',
|
|
|
|
@ -562,17 +565,19 @@ export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
export const parseRenderMessageList = (messages) => {
|
|
|
|
|
return messages.map((msg, i) => {
|
|
|
|
|
let msgContentString = '';
|
|
|
|
|
if (typeof msg.msgtext_AsJOSN === 'string') {
|
|
|
|
|
const msgtext = msg?.msgtext || msg?.msgtext_AsJOSN || {};
|
|
|
|
|
const messageorigin = msg?.messageorigin || msg?.messageorigin_AsJOSN || {};
|
|
|
|
|
if (typeof msgtext === 'string') {
|
|
|
|
|
// debug: json 缺少一部分
|
|
|
|
|
msgContentString = msg.msgtext_AsJOSN.charAt(msg.msgtext_AsJOSN.length - 1) !== '}' ? msg.msgtext_AsJOSN + '}}' : msg.msgtext_AsJOSN;
|
|
|
|
|
// if (msg.msgtext_AsJOSN.charAt(msg.msgtext_AsJOSN.length - 1) === '"') {
|
|
|
|
|
// msgContentString = msg.msgtext_AsJOSN + '}}';
|
|
|
|
|
msgContentString = msgtext.charAt(msgtext.length - 1) !== '}' ? msgtext + '}}' : msgtext;
|
|
|
|
|
// if (msg.msgtext.charAt(msg.msgtext.length - 1) === '"') {
|
|
|
|
|
// msgContentString = msg.msgtext + '}}';
|
|
|
|
|
// } else {
|
|
|
|
|
// msgContentString = msg.msgtext_AsJOSN + '"}';
|
|
|
|
|
// msgContentString = msg.msgtext + '"}';
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
const msgContent = typeof msg.msgtext_AsJOSN === 'string' ? JSON.parse(msgContentString) : (msg.msgtext_AsJOSN || {});
|
|
|
|
|
msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...msg.template_AsJOSN } : {};
|
|
|
|
|
const msgContent = typeof msgtext === 'string' ? JSON.parse(msgContentString) : (msgtext || {});
|
|
|
|
|
msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...msg.template } : {};
|
|
|
|
|
const msgType = Object.keys(whatsappMsgTypeMapped).includes(msgContent.type) ? msgContent.type : 'unsupported';
|
|
|
|
|
// const parseMethod = msgContent.bizType === 'whatsapp' ? cloneDeep(whatsappMsgTypeMapped) : {};
|
|
|
|
|
let waCode, waError = '';
|
|
|
|
@ -610,26 +615,26 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
statusTitle: msgStatusRenderMappedCN[msgContent?.status || 'failed'],
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
...((isEmpty(msg.messageorigin_AsJOSN) && (isEmpty(msgContent.context) || msgContent.context?.forwarded === true))
|
|
|
|
|
// ...((isEmpty(msg.context) && isEmpty(msg.reaction)) || msg.context?.forwarded === true || isEmpty(msg.messageorigin)
|
|
|
|
|
// ...((isEmpty(msg.messageorigin_AsJOSN) || isEmpty(msgContent.context))
|
|
|
|
|
...((isEmpty(messageorigin) && (isEmpty(msgContent.context) || msgContent.context?.forwarded === true))
|
|
|
|
|
// ...((isEmpty(msg.context) && isEmpty(msg.reaction)) || msg.context?.forwarded === true || isEmpty(messageorigin)
|
|
|
|
|
// ...((isEmpty(messageorigin) || isEmpty(msgContent.context))
|
|
|
|
|
? {}
|
|
|
|
|
: {
|
|
|
|
|
reply: {
|
|
|
|
|
message: msg.messageorigin_AsJOSN?.text?.body || msg.messageorigin_AsJOSN?.text,
|
|
|
|
|
title: msg.messageorigin_AsJOSN?.customerProfile?.name || msg.messageorigin_AsJOSN?.senderName || 'me',
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[(msg.messageorigin_AsJOSN?.type || 'unsupported')]?.renderForReply === 'function'
|
|
|
|
|
? whatsappMsgTypeMapped[(msg.messageorigin_AsJOSN?.type || 'unsupported')].renderForReply(msg.messageorigin_AsJOSN)
|
|
|
|
|
message: messageorigin?.text?.body || messageorigin?.text,
|
|
|
|
|
title: messageorigin?.customerProfile?.name || messageorigin?.senderName || 'me',
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[(messageorigin?.type || 'unsupported')]?.renderForReply === 'function'
|
|
|
|
|
? whatsappMsgTypeMapped[(messageorigin?.type || 'unsupported')].renderForReply(messageorigin)
|
|
|
|
|
: {}),
|
|
|
|
|
titleColor: msg.messageorigin_AsJOSN?.customerProfile?.name ? '#a791ff' : "#128c7e",
|
|
|
|
|
titleColor: messageorigin?.customerProfile?.name ? '#a791ff' : "#128c7e",
|
|
|
|
|
// titleColor: msg.messageorigin_direction === 'inbound' ? '#a791ff' : "#128c7e",
|
|
|
|
|
id: msgContent.context?.id || msgContent.context?.message_id || msgContent.reaction?.message_id,
|
|
|
|
|
},
|
|
|
|
|
origin: msg.messageorigin_AsJOSN,
|
|
|
|
|
origin: messageorigin,
|
|
|
|
|
}),
|
|
|
|
|
// conversationid: conversationid,
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
|
whatsapp_msg_type: msgContent.type,
|
|
|
|
|
whatsapp_msg_type: msg.msg_source==='WABA' ? msgContent.type : '',
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|