|
|
|
@ -33,8 +33,8 @@ export const sentMsgTypeMapped = {
|
|
|
|
|
contentToRender: (msg) => {
|
|
|
|
|
console.log(msg);
|
|
|
|
|
const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({...r, [v.type]: v}), {}) : null;
|
|
|
|
|
const templateParam = (templateDataMapped?.body?.parameters || []).map(e => e.text);
|
|
|
|
|
const fillTemplate = templateParam.length ? replaceTemplateString(msg.template_origin.components.body?.[0]?.text || '', templateParam) : (msg.template_origin.components.body?.[0]?.text || '');
|
|
|
|
|
// const templateParam = (templateDataMapped?.body?.parameters || []).map(e => e.text);
|
|
|
|
|
// const fillTemplate = templateParam.length ? replaceTemplateString(msg.template_origin.components.body?.[0]?.text || '', templateParam) : (msg.template_origin.components.body?.[0]?.text || '');
|
|
|
|
|
// const footer = msg.template_origin.components?.footer?.[0]?.text || '';
|
|
|
|
|
return {
|
|
|
|
|
...msg,
|
|
|
|
@ -42,7 +42,7 @@ export const sentMsgTypeMapped = {
|
|
|
|
|
conversationid: msg.id.split('.')[0],
|
|
|
|
|
type: 'text',
|
|
|
|
|
title: msg.template_origin.components.header?.[0]?.text || '',
|
|
|
|
|
text: `${fillTemplate}`, // msg.template_origin.components.body?.[0]?.text || '',
|
|
|
|
|
text: templateDataMapped?.body?.text || '', // msg.template_origin.components.body?.[0]?.text || '',
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@ -171,6 +171,14 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
// 'contact-card': 'contact-card',
|
|
|
|
|
// 'contact-card-with-photo': 'contact-card-with-photo',
|
|
|
|
|
// 'contact-card-with-photo-and-label': 'contact-card-with-photo-and-label',
|
|
|
|
|
template: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
data: (msg) => {
|
|
|
|
|
const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({...r, [v.type]: v}), {}) : null;
|
|
|
|
|
console.log(msg.template.name, templateDataMapped);
|
|
|
|
|
return { id: msg.wamid, text: templateDataMapped?.body?.parameters?.[0]?.text || '', title: msg.template.name }
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* render received msg
|
|
|
|
@ -200,12 +208,18 @@ export const parseRenderMessageList = (messages, conversationid = null) => {
|
|
|
|
|
return {
|
|
|
|
|
...(whatsappMsgTypeMapped?.[msgType]?.data(msgContent) || {}),
|
|
|
|
|
type: msgContent.type,
|
|
|
|
|
sender: msg.msg_direction === 'outbound' ? 'me' : msgContent.from,
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[msgType].type === 'function' ? whatsappMsgTypeMapped[msgType].type(msg) : { type: whatsappMsgTypeMapped[msgType].type || 'text' }),
|
|
|
|
|
date: msgContent?.sendTime || msg.msgtime || '',
|
|
|
|
|
sender: msgContent.from,
|
|
|
|
|
...(msg.msg_direction === 'outbound'
|
|
|
|
|
? {
|
|
|
|
|
sender: 'me',
|
|
|
|
|
status: msgStatusRenderMapped[msgContent?.status || 'failed'],
|
|
|
|
|
dateString: msgStatusRenderMapped[msgContent?.status || 'failed'] === 'failed' ? '发送失败 ❌' : '',
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
// conversationid: conversationid,
|
|
|
|
|
status: msg.msg_direction === 'outbound' ? msgStatusRenderMapped[(msgContent?.status || 'failed')] : '',
|
|
|
|
|
dateString: msgStatusRenderMapped[(msgContent?.status || 'failed')] === 'failed' ? '发送失败 ❌' : '',
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -214,7 +228,8 @@ export const parseRenderMessageList = (messages, conversationid = null) => {
|
|
|
|
|
* WhatsApp Templates params
|
|
|
|
|
*/
|
|
|
|
|
export const whatsappTemplatesParamMapped = {
|
|
|
|
|
// 'asia_highlights_has_receive_your_inquiry': [['customer_name']],
|
|
|
|
|
/** @deprecated */
|
|
|
|
|
'asia_highlights_has_receive_your_inquiry': [['customer_name']],
|
|
|
|
|
'hello_from_asia_highlights': [['agent_name']], // todo:
|
|
|
|
|
'hello_from_china_highlights': [['agent_name']], // todo:
|
|
|
|
|
'use_new_whatsapp': [['agent_name']], // todo:
|
|
|
|
|