Chatwoot/app/javascript/widget/api/endPoints.js
2020-03-30 12:15:06 +05:30

50 lines
1.2 KiB
JavaScript
Executable file

const sendMessage = content => ({
url: `/api/v1/widget/messages${window.location.search}`,
params: {
message: {
content,
timestamp: new Date().toString(),
referer_url: window.refererURL || '',
},
},
});
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 },
});
const updateContact = 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,
sendAttachmnet,
getConversation,
updateContact,
getAvailableAgents,
};