2019-10-29 07:20:54 +00:00
|
|
|
const sendMessage = content => ({
|
|
|
|
url: `/api/v1/widget/messages${window.location.search}`,
|
|
|
|
params: {
|
|
|
|
message: {
|
|
|
|
content,
|
2020-01-01 17:00:43 +00:00
|
|
|
timestamp: new Date().toString(),
|
|
|
|
referer_url: window.refererURL || '',
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-03-30 06:45:06 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-12-11 15:27:06 +00:00
|
|
|
const getConversation = ({ before }) => ({
|
2019-10-29 07:20:54 +00:00
|
|
|
url: `/api/v1/widget/messages${window.location.search}`,
|
2019-12-11 15:27:06 +00:00
|
|
|
params: { before },
|
2019-10-29 07:20:54 +00:00
|
|
|
});
|
|
|
|
|
2020-04-10 11:12:37 +00:00
|
|
|
const updateMessage = id => ({
|
2020-01-09 07:36:40 +00:00
|
|
|
url: `/api/v1/widget/messages/${id}${window.location.search}`,
|
|
|
|
});
|
|
|
|
|
2020-02-05 05:57:22 +00:00
|
|
|
const getAvailableAgents = token => ({
|
|
|
|
url: '/api/v1/widget/inbox_members',
|
|
|
|
params: {
|
|
|
|
website_token: token,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
export default {
|
|
|
|
sendMessage,
|
2020-03-30 06:45:06 +00:00
|
|
|
sendAttachmnet,
|
2019-10-29 07:20:54 +00:00
|
|
|
getConversation,
|
2020-04-10 11:12:37 +00:00
|
|
|
updateMessage,
|
2020-02-05 05:57:22 +00:00
|
|
|
getAvailableAgents,
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|