Feature: Send images from widget
This commit is contained in:
parent
e56132c506
commit
6c4e1fdaac
16 changed files with 305 additions and 67 deletions
|
@ -7,10 +7,16 @@ const sendMessageAPI = async content => {
|
|||
return result;
|
||||
};
|
||||
|
||||
const sendAttachmentAPI = async attachment => {
|
||||
const urlData = endPoints.sendAttachmnet(attachment);
|
||||
const result = await API.post(urlData.url, urlData.params);
|
||||
return result;
|
||||
};
|
||||
|
||||
const getConversationAPI = async ({ before }) => {
|
||||
const urlData = endPoints.getConversation({ before });
|
||||
const result = await API.get(urlData.url, { params: urlData.params });
|
||||
return result;
|
||||
};
|
||||
|
||||
export { sendMessageAPI, getConversationAPI };
|
||||
export { sendMessageAPI, getConversationAPI, sendAttachmentAPI };
|
||||
|
|
|
@ -9,6 +9,22 @@ const sendMessage = content => ({
|
|||
},
|
||||
});
|
||||
|
||||
const sendAttachmnet = ({ attachment }) => {
|
||||
const { refererURL = '' } = window;
|
||||
const timestamp = new Date().toString();
|
||||
const { file, file_type: fileType } = attachment;
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('message[attachment][file]', file);
|
||||
formData.append('message[attachment][file_type]', fileType);
|
||||
formData.append('message[referer_url]', refererURL);
|
||||
formData.append('message[timestamp]', timestamp);
|
||||
return {
|
||||
url: `/api/v1/widget/messages${window.location.search}`,
|
||||
params: formData,
|
||||
};
|
||||
};
|
||||
|
||||
const getConversation = ({ before }) => ({
|
||||
url: `/api/v1/widget/messages${window.location.search}`,
|
||||
params: { before },
|
||||
|
@ -27,6 +43,7 @@ const getAvailableAgents = token => ({
|
|||
|
||||
export default {
|
||||
sendMessage,
|
||||
sendAttachmnet,
|
||||
getConversation,
|
||||
updateContact,
|
||||
getAvailableAgents,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue