前端解析 `wai`

dev/supplier-email-drawer
Lei OT 9 months ago
parent 7317616cd4
commit 608d4ab774

@ -1,4 +1,4 @@
import { cloneDeep, isEmpty, olog, fixTo2Decimals, pick } from "@/utils/commons";
import { cloneDeep, isEmpty, olog, fixTo2Decimals, pick, objectMapper } from "@/utils/commons";
import dayjs from "dayjs";
import { v4 as uuid } from "uuid";
@ -322,6 +322,45 @@ const whatsappMsgMapped = {
dateString: msgcontent.status==='failed' ? `发送失败 ${whatsappError?.[msgcontent.errorCode] || msgcontent.errorMessage || ''}` : '',
}),
},
'wai.message.received': {
getMsg: (result) => {
const data1 = pick(result, ['conversationid', 'opi_sn', 'coli_sn', 'coli_id']);
return isEmpty(result?.waiMessage) ? null : { ...result.waiMessage, ...data1, messageorigin: result.messageorigin, msg_source: 'wai', ...objectMapper(result.waiMessage, { direction: 'msg_direction' }) };
},
contentToRender: (contentObj) => {
return parseRenderMessageItem(contentObj);
},
contentToUpdate: () => null,
},
'wai.message.updated': {
getMsg: (result) => {
return isEmpty(result?.waiMessage)
? null
: { ...result.waiMessage, conversationid: result.conversationid, messageorigin: result.messageorigin, msg_source: 'wai', ...objectMapper(result.waiMessage, { direction: 'msg_direction' }) }
},
contentToRender: (contentObj) => {
if (contentObj?.status === 'failed') {
contentObj = {
...contentObj,
type: 'error',
text: { body: `` }, // contentObj.errorMessage // Message failed to send.
id: contentObj.id,
wamid: contentObj.id,
};
return parseRenderMessageItem(contentObj);
}
// * 仅更新消息状态, 没有输出
return null;
},
contentToUpdate: (msgcontent) => ({
...msgcontent,
...parseRenderMessageItem(msgcontent),
id: msgcontent.wamid,
status: msgStatusRenderMapped[(msgcontent?.status || 'failed')],
sender: msgcontent.msg_direction === 'outbound' ? 'me' : (msgcontent?.customerProfile ?.name || ''),
dateString: msgcontent.status==='failed' ? `发送失败 ❌` : '',
}),
},
};
const emailMsgMapped = {
'email.inbound.received': {

@ -20,7 +20,7 @@ const ButtonStyleClsMapped =
{
'waba': 'bg-waba shadow shadow-waba-300 hover:!bg-waba-400 active:bg-waba-400 focus:bg-waba-400',
'whatsapp': 'bg-whatsapp shadow shadow-whatsapp-300 hover:!bg-whatsapp-400 active:bg-whatsapp-400 focus:bg-whatsapp-400',
'wa': 'bg-whatsapp shadow shadow-whatsapp-300 hover:!bg-whatsapp-400 active:bg-whatsapp-400 focus:bg-whatsapp-400',
'wai': 'bg-whatsapp shadow shadow-whatsapp-300 hover:!bg-whatsapp-400 active:bg-whatsapp-400 focus:bg-whatsapp-400',
};
const InputComposer = ({ channel, currentActive }) => {
@ -374,6 +374,6 @@ const InputComposer = ({ channel, currentActive }) => {
);
};
InputComposer.propTypes = { channel: PropTypes.oneOf(['waba', 'whatsapp']) };
InputComposer.propTypes = { channel: PropTypes.oneOf(['waba', 'wai']) };
export default InputComposer;

@ -84,7 +84,7 @@ const ReplyWrapper = () => {
label: mobile ? '' : 'WhatsApp',
icon: <WhatsAppOutlined className='text-whatsapp' />,
children: isPermitted(PERM_USE_WHATSAPP) ? (
<InputComposer channel={'whatsapp'} />
<InputComposer channel={'wai'} />
) : (
<div className='p-2 py-4 text-center text-whatsapp bg-gray-200 rounded rounded-b-none border-gray-300 border-solid border border-b-0 border-x-0'>正在开发敬请期待</div>
),

Loading…
Cancel
Save