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-04-17 15:45:20 +00:00
|
|
|
const sendAttachment = ({ attachment }) => {
|
2020-03-30 06:45:06 +00:00
|
|
|
const { refererURL = '' } = window;
|
|
|
|
const timestamp = new Date().toString();
|
2020-04-17 15:45:20 +00:00
|
|
|
const { file } = attachment;
|
2020-03-30 06:45:06 +00:00
|
|
|
|
|
|
|
const formData = new FormData();
|
2020-04-17 15:45:20 +00:00
|
|
|
formData.append('message[attachments][]', file, file.name);
|
2020-03-30 06:45:06 +00:00
|
|
|
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-04-17 15:45:20 +00:00
|
|
|
sendAttachment,
|
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
|
|
|
};
|