test: Email发送, 气泡 # 文件名调整

2.0/email-builder
Lei OT 11 months ago
parent 4668d0782c
commit fbbe573768

@ -1,7 +1,7 @@
import { groupBy, pick, sortArrayByOrder } from '@/utils/commons';
import { fetchJSON, postJSON, postForm } from '@/utils/request'
import { parseRenderMessageList } from '@/channel/whatsappUtils';
import { parseRenderMessageList } from '@/channel/bubbleMsgUtils';
import { API_HOST } from '@/config';
import { isEmpty } from '@/utils/commons';
import dayjs from 'dayjs';
@ -44,13 +44,14 @@ export const fetchOrderConversationsList = async (params) => {
export const MESSAGE_PAGE_SIZE = 50;
/**
*
* @param {object} params { opisn, whatsappid, lasttime, pagesize }
* @param {object} params { opisn, whatsappid, conversationid, lasttime, pagesize }
*/
export const fetchMessages = async (params) => {
const defaultParams = {
opisn: '',
whatsappid: '',
lasttime: '',
conversationid: '',
pagesize: MESSAGE_PAGE_SIZE,
};
const { errcode, result } = await fetchJSON(`${API_HOST}/getcusmessages`, {...defaultParams, ...params});

@ -209,6 +209,25 @@ export const sentMsgTypeMapped = {
};
},
},
email: {
type: 'email',
contentToSend: (msg) => ({
action: 'message',
actionId: msg.id,
renderId: msg.id,
to: msg.to,
msgtype: 'email',
msgcontent: { body: msg.text, preview_url: true, },
}),
contentToRender: (msg) => ({
...msg,
whatsapp_msg_type: 'email',
actionId: msg.id,
conversationid: msg.id.split('.')[0],
originText: msg.text,
text: (msg.text),
}),
},
};
const whatsappMsgMapped = {
'whatsapp.inbound_message.received': {
@ -552,7 +571,7 @@ export const parseRenderMessageList = (messages) => {
// msgContentString = msg.msgtext_AsJOSN + '"}';
// }
}
const msgContent = typeof msg.msgtext_AsJOSN === 'string' ? JSON.parse(msgContentString) : msg.msgtext_AsJOSN;
const msgContent = typeof msg.msgtext_AsJOSN === 'string' ? JSON.parse(msgContentString) : (msg.msgtext_AsJOSN || {});
msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...msg.template_AsJOSN } : {};
const msgType = Object.keys(whatsappMsgTypeMapped).includes(msgContent.type) ? msgContent.type : 'unsupported';
// const parseMethod = msgContent.bizType === 'whatsapp' ? cloneDeep(whatsappMsgTypeMapped) : {};

@ -1,7 +1,7 @@
import { create } from 'zustand';
import { RealTimeAPI } from '@/channel/realTimeAPI';
import { olog, isEmpty } from '@/utils/commons';
import { receivedMsgTypeMapped, handleNotification } from '@/channel/whatsappUtils';
import { receivedMsgTypeMapped, handleNotification } from '@/channel/bubbleMsgUtils';
import { fetchConversationsList, fetchTemplates, fetchConversationsSearch, UNREAD_MARK, fetchTags } from '@/actions/ConversationActions';
import { devtools } from 'zustand/middleware';
import { WS_URL, DATETIME_FORMAT } from '@/config';

@ -21,7 +21,7 @@ import DnDModal from '@/components/DnDModal';
import useConversationStore from '@/stores/ConversationStore';
import useStyleStore from '@/stores/StyleStore';
import useAuthStore from '@/stores/AuthStore';
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/whatsappUtils';
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/bubbleMsgUtils';
import { v4 as uuid } from 'uuid';
const BIG_PAGE_SIZE = MESSAGE_PAGE_SIZE * 10;

@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
import { Form, Input, Modal } from 'antd';
import { isEmpty, isNotEmpty, pick } from '@/utils/commons';
import useConversationStore from '@/stores/ConversationStore';
import { phoneNumberToWAID } from '@/channel/whatsappUtils';
import { phoneNumberToWAID } from '@/channel/bubbleMsgUtils';
import { useConversationNewItem } from '@/hooks/useConversation';
import useAuthStore from '@/stores/AuthStore';

@ -5,12 +5,15 @@ import Modal from '@dckj/react-better-modal';
import '@dckj/react-better-modal/dist/index.css';
import DnDModal from '@/components/DndModal';
import useStyleStore from '@/stores/StyleStore';
import useConversationStore from '@/stores/ConversationStore';
import LexicalEditor from '@/components/LexicalEditor';
import { v4 as uuid } from 'uuid';
import { isEmpty } from '@/utils/commons';
import './EmailEditor.css';
import { postSendEmail } from '@/actions/EmailActions';
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/bubbleMsgUtils';
const getAbstract = (longtext) => {
const lines = longtext.split('\n');
@ -191,6 +194,28 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, reference, quote = {}, ini
},
};
/**
* 先推到消息记录上面, 再发送
*/
const sentOrReceivedNewMessage = useConversationStore((state) => state.sentOrReceivedNewMessage);
const invokeEmailMessage = (msgObj) => {
const msgObjMerge = {
sender: 'me',
senderName: 'me',
msg_source: 'email',
// to: currentConversation.whatsapp_phone_number,
date: new Date(),
status: 'waiting',
...msgObj,
// id: `${currentConversation.sn}.${msgObj.id}`,
id: `1148.${msgObj.id}`,
};
// olog('invoke upload', msgObjMerge)
const contentToRender = sentMsgTypeMapped[msgObjMerge.type].contentToRender(msgObjMerge);
// console.log(contentToRender, 'contentToRender sendMessage------------------');
sentOrReceivedNewMessage(contentToRender.conversationid, contentToRender);
};
const onHandleSend = async () => {
console.log('onSend callback', '\nisRichText', isRichText);
// console.log(form.getFieldsValue());
@ -201,14 +226,19 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, reference, quote = {}, ini
body.opi_sn = 29; // debug:
body.mat_sn = 278;
console.log('body', body);
await form.validateFields();
await postSendEmail(body);
const values = await form.validateFields();
const msgObj = {
type: 'email',
id: uuid(),
}
invokeEmailMessage(msgObj);
const result = await postSendEmail(body);
// form.validateFields().then((values) => {
// form.resetFields();
// });
// .catch((err) => {})
// setOpen(false);
setOpen(false);
};
return (
@ -258,8 +288,8 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, reference, quote = {}, ini
// labelCol={{ span: 3 }}
>
<Form.Item label='收件人' className='w-full'>
{/* <Space.Compact className='w-full'> */}
<Flex justify='space-between'>
<Space.Compact className='w-full'>
{/* <Flex justify='space-between' className='w-full'> */}
{/* <Mentions // todo: 用客人列表
split='; '
options={[
@ -270,7 +300,7 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, reference, quote = {}, ini
placeholder='@'
/> */}
<Form.Item name={'to'} rules={[{ required: true }]} className='flex-1'>
<Input />
<Input className='w-full' />
</Form.Item>
<Flex gap={4}>
{!showCc && (
@ -284,8 +314,8 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, reference, quote = {}, ini
</Button>
)}
</Flex>
</Flex>
{/* </Space.Compact> */}
{/* </Flex> */}
</Space.Compact>
{/* <Input
addonAfter={
<Flex gap={4}>

@ -19,7 +19,7 @@ import {
} from '@ant-design/icons';
import { isEmpty, } from '@/utils/commons';
import { v4 as uuid } from 'uuid';
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/whatsappUtils';
import { sentMsgTypeMapped, whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/bubbleMsgUtils';
import InputTemplate from './Template';
import InputEmoji from './Emoji';
import InputMediaUpload from './MediaUpload';

@ -3,7 +3,7 @@ import { useState } from 'react';
import { FileAddOutlined } from '@ant-design/icons';
import { v4 as uuid } from 'uuid';
import { API_HOST, OSS_URL as aliOSSHost } from '@/config';
import { whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/whatsappUtils';
import { whatsappSupportFileTypes, uploadProgressSimulate } from '@/channel/bubbleMsgUtils';
import { isEmpty, sanitizeFilename } from '@/utils/commons';
// import useConversationStore from '@/stores/ConversationStore';

@ -4,7 +4,7 @@ import { MessageOutlined, SendOutlined } from '@ant-design/icons';
import useAuthStore from '@/stores/AuthStore';
import useConversationStore from '@/stores/ConversationStore';
import { cloneDeep, getNestedValue, objectMapper, removeFormattingChars, sortArrayByOrder } from '@/utils/commons';
import { replaceTemplateString } from '@/channel/whatsappUtils';
import { replaceTemplateString } from '@/channel/bubbleMsgUtils';
import { isEmpty } from '@/utils/commons';
import useStyleStore from '@/stores/StyleStore';

@ -58,7 +58,12 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
const getFirstPageMessages = async (item) => {
setMsgLoading(true);
const data = await fetchMessages({ opisn: forceGetMessages ? (currentConversation.opi_sn || '') : userId, whatsappid: item.whatsapp_phone_number, lasttime: '' });
const data = await fetchMessages({
conversationid: item.sn,
opisn: forceGetMessages ? currentConversation.opi_sn || '' : userId,
whatsappid: item.whatsapp_phone_number,
lasttime: '',
})
// test:
data.push(emailItem);
@ -74,7 +79,12 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
const getMoreMessages = async () => {
setShouldScrollBottom(false);
setLongListLoading(true);
const data = await fetchMessages({ opisn: currentConversation.opi_sn, whatsappid: currentConversation.whatsapp_phone_number, lasttime: currentConversation?.lasttime || '' });
const data = await fetchMessages({
conversationid: currentConversation.sn,
opisn: currentConversation.opi_sn,
whatsappid: currentConversation.whatsapp_phone_number,
lasttime: currentConversation?.lasttime || '',
})
setLongListLoading(false);
setLongList(prevValue => data.concat(prevValue));
const thisLastTime = data.length > 0 ? data[0].orgmsgtime : '';

Loading…
Cancel
Save