Chatwoot/app/javascript/widget/api/endPoints.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

const sendMessage = content => ({
url: `/api/v1/widget/messages${window.location.search}`,
params: {
message: {
content,
timestamp: new Date().toString(),
referer_url: window.refererURL || '',
},
},
});
const sendAttachment = ({ attachment }) => {
2020-03-30 06:45:06 +00:00
const { refererURL = '' } = window;
const timestamp = new Date().toString();
const { file } = attachment;
2020-03-30 06:45:06 +00:00
const formData = new FormData();
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,
};
};
const getConversation = ({ before }) => ({
url: `/api/v1/widget/messages${window.location.search}`,
params: { before },
});
const updateMessage = id => ({
url: `/api/v1/widget/messages/${id}${window.location.search}`,
});
const getAvailableAgents = token => ({
url: '/api/v1/widget/inbox_members',
params: {
website_token: token,
},
});
export default {
sendMessage,
sendAttachment,
getConversation,
updateMessage,
getAvailableAgents,
};