|
|
|
@ -31,7 +31,7 @@ export const sentMsgTypeMapped = {
|
|
|
|
|
renderId: msg.id,
|
|
|
|
|
to: msg.to,
|
|
|
|
|
msgtype: 'text',
|
|
|
|
|
msgcontent: { body: msg.text, ...(msg.context ? { context: msg.context, message_origin: msg.message_origin } : {}) },
|
|
|
|
|
msgcontent: { body: msg.text, ...(msg.context ? { context: msg.context, message_origin: msg.message_origin.msgOrigin } : {}) },
|
|
|
|
|
}),
|
|
|
|
|
contentToRender: (msg) => ({
|
|
|
|
|
...msg,
|
|
|
|
@ -39,7 +39,12 @@ export const sentMsgTypeMapped = {
|
|
|
|
|
conversationid: msg.id.split('.')[0],
|
|
|
|
|
...(msg.context
|
|
|
|
|
? {
|
|
|
|
|
reply: { message: msg.message_origin.text, title: msg.message_origin.senderName || 'Reference' },
|
|
|
|
|
reply: {
|
|
|
|
|
message: msg.message_origin.text,
|
|
|
|
|
title: msg.message_origin.senderName || 'Reference',
|
|
|
|
|
titleColor: msg.message_origin?.senderName !== 'me' ? '#a791ff' : "#128c7e",
|
|
|
|
|
// titleColor: "#a791ff",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
}),
|
|
|
|
@ -63,7 +68,7 @@ export const sentMsgTypeMapped = {
|
|
|
|
|
conversationid: msg.id.split('.')[0],
|
|
|
|
|
...(msg.context
|
|
|
|
|
? {
|
|
|
|
|
reply: { message: msg.message_origin.text, title: msg.message_origin.senderName || 'Reference' },
|
|
|
|
|
reply: { message: msg.message_origin.text, title: msg.message_origin.senderName || 'Reference', titleColor: "#a791ff", },
|
|
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
}),
|
|
|
|
@ -91,7 +96,7 @@ const whatsappMsgMapped = {
|
|
|
|
|
'whatsapp.inbound_message.received': {
|
|
|
|
|
getMsg: (result) => {
|
|
|
|
|
console.log('whatsapp.inbound_message.received', result);
|
|
|
|
|
return isEmpty(result?.whatsappInboundMessage) ? null : { ...result.whatsappInboundMessage, conversationid: result.conversationid };
|
|
|
|
|
return isEmpty(result?.whatsappInboundMessage) ? null : { ...result.whatsappInboundMessage, conversationid: result.conversationid, messageorigin: result.messageorigin };
|
|
|
|
|
},
|
|
|
|
|
contentToRender: (contentObj) => {
|
|
|
|
|
console.log('whatsapp.inbound_message.received to render', contentObj);
|
|
|
|
@ -165,6 +170,7 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
text: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
data: (msg) => ({ id: msg.wamid, text: msg.text.body }),
|
|
|
|
|
renderForReply: (msg) => ({ id: msg.wamid, message: msg.text.body }),
|
|
|
|
|
},
|
|
|
|
|
image: {
|
|
|
|
|
type: 'photo',
|
|
|
|
@ -216,7 +222,7 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
unsupported: { type: 'system', data: (msg) => ({ text: 'Message type is currently not supported.' }) },
|
|
|
|
|
reaction: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
data: (msg) => ({ id: msg.wamid, text: msg.reaction?.emoji || msg.reaction?.text?.body || 'Reaction', reply: { message: '{content}', title: 'React from', titleColor: '#1ba784' } }), // todo:
|
|
|
|
|
data: (msg) => ({ id: msg.wamid, text: msg.reaction?.emoji || '', }),
|
|
|
|
|
},
|
|
|
|
|
document: {
|
|
|
|
|
type: 'file',
|
|
|
|
@ -234,8 +240,8 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
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}` }
|
|
|
|
|
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}` };
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
@ -245,11 +251,13 @@ export const whatsappMsgTypeMapped = {
|
|
|
|
|
export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
console.log('parseRenderMessageItem', msg);
|
|
|
|
|
return {
|
|
|
|
|
msgOrigin: msg,
|
|
|
|
|
date: msg?.sendTime || msg?.createTime || '',
|
|
|
|
|
...(whatsappMsgTypeMapped?.[msg.type]?.data(msg) || {}),
|
|
|
|
|
conversationid: msg.conversationid,
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[msg.type].type === 'function' ? whatsappMsgTypeMapped[msg.type].type(msg) : { type: whatsappMsgTypeMapped[msg.type].type || 'text' }),
|
|
|
|
|
// type: whatsappMsgTypeMapped?.[msg.type]?.type || 'text',
|
|
|
|
|
from: msg.from,
|
|
|
|
|
sender: msg.from,
|
|
|
|
|
senderName: msg?.customerProfile?.name || msg.from,
|
|
|
|
|
// title: msg.customerProfile.name,
|
|
|
|
@ -257,13 +265,18 @@ export const parseRenderMessageItem = (msg) => {
|
|
|
|
|
whatsapp_name: msg?.customerProfile?.name || '',
|
|
|
|
|
whatsapp_phone_number: msg.from,
|
|
|
|
|
whatsapp_msg_type: msg.type,
|
|
|
|
|
...(isEmpty(msg.context)
|
|
|
|
|
...(isEmpty(msg.context) && isEmpty(msg.reaction)
|
|
|
|
|
? {}
|
|
|
|
|
: {
|
|
|
|
|
reply: {
|
|
|
|
|
message: `${msg.context.id}`, // todo: msg.context.text?.body || msg.context.text,
|
|
|
|
|
title: msg?.customerProfile?.name || msg.from,
|
|
|
|
|
titleColor: "#53bdeb", // "#128c7e",
|
|
|
|
|
/**
|
|
|
|
|
* reply: { message: msg.messageorigin, title: 'React from', titleColor: '#1ba784' }
|
|
|
|
|
*/
|
|
|
|
|
title: msg.messageorigin?.customerProfile?.name || 'me',
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[msg?.messageorigin?.type]?.renderForReply === 'function'
|
|
|
|
|
? whatsappMsgTypeMapped[msg.messageorigin.type].renderForReply(msg.messageorigin)
|
|
|
|
|
: {}),
|
|
|
|
|
titleColor: msg.messageorigin?.customerProfile?.name ? '#a791ff' : "#128c7e",
|
|
|
|
|
},
|
|
|
|
|
origin: msg.context,
|
|
|
|
|
}),
|
|
|
|
@ -279,10 +292,12 @@ export const parseRenderMessageList = (messages, conversationid = null) => {
|
|
|
|
|
const msgType = msgContent.type;
|
|
|
|
|
// const parseMethod = msgContent.bizType === 'whatsapp' ? cloneDeep(whatsappMsgTypeMapped) : {};
|
|
|
|
|
return {
|
|
|
|
|
msgOrigin: msgContent,
|
|
|
|
|
...(whatsappMsgTypeMapped?.[msgType]?.data(msgContent) || {}),
|
|
|
|
|
type: msgContent.type,
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[msgType].type === 'function' ? whatsappMsgTypeMapped[msgType].type(msg) : { type: whatsappMsgTypeMapped[msgType].type || 'text' }),
|
|
|
|
|
date: msgContent?.sendTime || msg.msgtime || '',
|
|
|
|
|
from: msgContent.from,
|
|
|
|
|
sender: msgContent.from,
|
|
|
|
|
senderName: msgContent?.customerProfile?.name || msgContent.from,
|
|
|
|
|
...(msg.msg_direction === 'outbound'
|
|
|
|
@ -298,11 +313,12 @@ export const parseRenderMessageList = (messages, conversationid = null) => {
|
|
|
|
|
: {
|
|
|
|
|
reply: {
|
|
|
|
|
message: msg.messageorigin_AsJOSN.text?.body || msg.messageorigin_AsJOSN.text,
|
|
|
|
|
title: msg.messageorigin_AsJOSN.senderName || '@', // msg.messageorigin_AsJOSN.from
|
|
|
|
|
title: msg.messageorigin_AsJOSN?.customerProfile?.name || 'me', // msg.messageorigin_AsJOSN.senderName || '@',
|
|
|
|
|
...(typeof whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type]?.renderForReply === 'function'
|
|
|
|
|
? whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type].renderForReply(msg.messageorigin_AsJOSN)
|
|
|
|
|
: {}),
|
|
|
|
|
titleColor: '#53bdeb', // "#128c7e", // todo: 原始消息的方向
|
|
|
|
|
titleColor: msg.messageorigin_AsJOSN?.customerProfile?.name ? '#a791ff' : "#128c7e",
|
|
|
|
|
// titleColor: msg.messageorigin_direction === 'inbound' ? '#a791ff' : "#128c7e",
|
|
|
|
|
},
|
|
|
|
|
origin: msg.messageorigin_AsJOSN,
|
|
|
|
|
}),
|
|
|
|
|