|
|
|
|
@ -274,6 +274,35 @@ const whatsappMsgMapped = {
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
const emailMsgMapped = {
|
|
|
|
|
'email.inbound.received': {
|
|
|
|
|
getMsg: (result) => {
|
|
|
|
|
console.log('email.inbound.received', result);
|
|
|
|
|
return isEmpty(result?.emailMessage) ? null : { ...result.emailMessage, conversationid: result.conversationid };
|
|
|
|
|
},
|
|
|
|
|
contentToRender: (contentObj) => {
|
|
|
|
|
console.log('email.inbound.received to render', contentObj);
|
|
|
|
|
// const contentObj = result?.emailMessage || result; // debug:
|
|
|
|
|
},
|
|
|
|
|
contentToUpdate: (msgcontent) => null,
|
|
|
|
|
},
|
|
|
|
|
'email.updated': {
|
|
|
|
|
getMsg: (result) => {
|
|
|
|
|
console.log('email.updated', result);
|
|
|
|
|
const { emailMessage } = result;
|
|
|
|
|
return isEmpty(result?.emailMessage) ? null : { ...emailMessage, conversationid: result.conversationid, type: 'email', status: emailMessage.msgstatus };
|
|
|
|
|
},
|
|
|
|
|
contentToRender: (contentObj) => null,
|
|
|
|
|
contentToUpdate: (msgcontent) => ({
|
|
|
|
|
...msgcontent,
|
|
|
|
|
...parseRenderMessageItem({...msgcontent, type: 'email'}),
|
|
|
|
|
id: msgcontent.id,
|
|
|
|
|
status: msgStatusRenderMapped[(msgcontent?.msgstatus || 'failed')],
|
|
|
|
|
sender: 'me',
|
|
|
|
|
dateString: msgcontent.status==='failed' ? `发送失败 ❌` : '',
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export const msgStatusRenderMapped = {
|
|
|
|
|
'accepted': 'waiting', // 'sent', // 接口的发送请求
|
|
|
|
|
'sent': 'sent',
|
|
|
|
|
@ -330,6 +359,7 @@ export const receivedMsgTypeMapped = {
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
...cloneDeep(emailMsgMapped),
|
|
|
|
|
};
|
|
|
|
|
export const whatsappMsgTypeMapped = {
|
|
|
|
|
error: {
|
|
|
|
|
@ -519,7 +549,7 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
},
|
|
|
|
|
email: {
|
|
|
|
|
type: 'email',
|
|
|
|
|
data: (msg) => ({ id: msg.id, subject: msg.email.subject, }),
|
|
|
|
|
data: (msg) => ({ id: msg.id || msg.uid, subject: msg.email.subject, }),
|
|
|
|
|
renderForReply: (msg) => {
|
|
|
|
|
return {
|
|
|
|
|
id: msg.id,
|
|
|
|
|
@ -544,7 +574,7 @@ export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
localDate: (msg?.sendTime || msg?.createTime || '').replace('T', ' '),
|
|
|
|
|
from: msg.from,
|
|
|
|
|
sender: msg.from,
|
|
|
|
|
senderName: msg?.customerProfile?.name || 'me', // msg.from,
|
|
|
|
|
senderName: msg?.customerProfile?.name || msg?.fromName || msg?.from || 'me', // msg.from,
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
|
customer_name: msg?.customerProfile?.name || '',
|
|
|
|
|
whatsapp_name: msg?.customerProfile?.name || '',
|
|
|
|
|
@ -552,7 +582,7 @@ export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
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',
|
|
|
|
|
replyButton: ['text', 'document', 'image', 'email'].includes(msg.type) && (msg?.status || '') !== 'failed',
|
|
|
|
|
...((isEmpty(msg.context) && isEmpty(msg.reaction)) || msg.context?.forwarded === true // || isEmpty(msg.messageorigin)
|
|
|
|
|
? {}
|
|
|
|
|
: {
|
|
|
|
|
@ -579,6 +609,7 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
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 || {};
|
|
|
|
|
if (typeof msgtext === 'string') {
|
|
|
|
|
// debug: json 缺少一部分
|
|
|
|
|
msgContentString = msgtext.charAt(msgtext.length - 1) !== '}' ? msgtext + '}}' : msgtext;
|
|
|
|
|
@ -589,7 +620,7 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
const msgContent = typeof msgtext === 'string' ? JSON.parse(msgContentString) : (msgtext || {});
|
|
|
|
|
msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...msg.template } : {};
|
|
|
|
|
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 = '';
|
|
|
|
|
@ -617,6 +648,11 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
sender: msgContent.from,
|
|
|
|
|
senderName: msgContent?.customerProfile?.name || 'me', // msgContent.from,
|
|
|
|
|
replyButton: ['text', 'document', 'image', 'email'].includes(msgContent.type) && (msgContent?.status || '') !== 'failed',
|
|
|
|
|
// 用forwarded表示Resend, 与Reply互斥 // debug: email, failed
|
|
|
|
|
forwarded: msg.msg_direction === 'outbound'
|
|
|
|
|
&& msg.msg_source === 'email'
|
|
|
|
|
&& ['email'].includes(msgContent.type)
|
|
|
|
|
&& (msgContent?.status || 'failed') === 'failed',
|
|
|
|
|
...(msg.msg_direction === 'outbound'
|
|
|
|
|
? {
|
|
|
|
|
sender: 'me',
|
|
|
|
|
@ -627,18 +663,18 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
statusTitle: msgStatusRenderMappedCN[msgContent?.status || 'failed'],
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
...((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))
|
|
|
|
|
? {}
|
|
|
|
|
...(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: 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)
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[messageorigin?.type || 'unsupported']?.renderForReply === 'function'
|
|
|
|
|
? whatsappMsgTypeMapped[messageorigin?.type || 'unsupported'].renderForReply(messageorigin)
|
|
|
|
|
: {}),
|
|
|
|
|
titleColor: messageorigin?.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 || messageorigin?.wamid,
|
|
|
|
|
},
|
|
|
|
|
@ -646,8 +682,8 @@ export const parseRenderMessageList = (messages) => {
|
|
|
|
|
}),
|
|
|
|
|
// conversationid: conversationid,
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
|
whatsapp_msg_type: msg.msg_source==='WABA' ? msgContent.type : '',
|
|
|
|
|
};
|
|
|
|
|
whatsapp_msg_type: (msg.msg_source || 'WABA') === 'WABA' ? msgContent.type : '', // 1.0接口没有msg_source
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
export const whatsappError = {
|
|
|
|
|
|