Chatwoot/app/javascript/widget/api/endPoints.js
Sojan Jose f9e8bb8e10
Chore: Send browser language in webwidget events (#952)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
2020-06-13 00:19:43 +05:30

55 lines
1.3 KiB
JavaScript
Executable file

import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
const sendMessage = content => {
const refererURL = window.refererURL || '';
const search = buildSearchParamsWithLocale(window.location.search);
return {
url: `/api/v1/widget/messages${search}`,
params: {
message: {
content,
timestamp: new Date().toString(),
referer_url: refererURL,
},
},
};
};
const sendAttachment = ({ attachment }) => {
const { refererURL = '' } = window;
const timestamp = new Date().toString();
const { file } = attachment;
const formData = new FormData();
formData.append('message[attachments][]', file, file.name);
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,
};