Feature: Send images from widget

This commit is contained in:
Nithin David Thomas 2020-03-30 12:15:06 +05:30 committed by GitHub
parent e56132c506
commit 6c4e1fdaac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 305 additions and 67 deletions

View file

@ -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 };

View file

@ -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,