2020-06-12 18:49:43 +00:00
|
|
|
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
2020-05-17 10:45:53 +00:00
|
|
|
|
2021-02-15 18:44:13 +00:00
|
|
|
const createConversation = params => {
|
|
|
|
const referrerURL = window.referrerURL || '';
|
|
|
|
const search = buildSearchParamsWithLocale(window.location.search);
|
|
|
|
return {
|
|
|
|
url: `/api/v1/widget/conversations${search}`,
|
|
|
|
params: {
|
|
|
|
contact: {
|
|
|
|
name: params.fullName,
|
|
|
|
email: params.emailAddress,
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
content: params.message,
|
|
|
|
timestamp: new Date().toString(),
|
|
|
|
referer_url: referrerURL,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-05-17 10:45:53 +00:00
|
|
|
const sendMessage = content => {
|
2020-10-14 18:41:47 +00:00
|
|
|
const referrerURL = window.referrerURL || '';
|
2020-06-12 18:49:43 +00:00
|
|
|
const search = buildSearchParamsWithLocale(window.location.search);
|
2020-05-17 10:45:53 +00:00
|
|
|
return {
|
|
|
|
url: `/api/v1/widget/messages${search}`,
|
|
|
|
params: {
|
|
|
|
message: {
|
|
|
|
content,
|
|
|
|
timestamp: new Date().toString(),
|
2020-10-14 18:41:47 +00:00
|
|
|
referer_url: referrerURL,
|
2020-05-17 10:45:53 +00:00
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2020-05-17 10:45:53 +00:00
|
|
|
};
|
|
|
|
};
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2020-04-17 15:45:20 +00:00
|
|
|
const sendAttachment = ({ attachment }) => {
|
2020-10-14 18:41:47 +00:00
|
|
|
const { referrerURL = '' } = window;
|
2020-03-30 06:45:06 +00:00
|
|
|
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-10-14 18:41:47 +00:00
|
|
|
formData.append('message[referer_url]', referrerURL);
|
2020-03-30 06:45:06 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
2021-05-10 07:31:00 +00:00
|
|
|
const getCampaigns = token => ({
|
|
|
|
url: '/api/v1/widget/campaigns',
|
|
|
|
params: {
|
|
|
|
website_token: token,
|
|
|
|
},
|
|
|
|
});
|
2021-05-17 16:08:35 +00:00
|
|
|
const triggerCampaign = ({ websiteToken, campaignId }) => ({
|
2021-05-10 07:31:00 +00:00
|
|
|
url: '/api/v1/widget/events',
|
|
|
|
data: {
|
|
|
|
name: 'campaign.triggered',
|
|
|
|
event_info: {
|
|
|
|
campaign_id: campaignId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
params: {
|
2021-05-17 16:08:35 +00:00
|
|
|
website_token: websiteToken,
|
2021-05-10 07:31:00 +00:00
|
|
|
},
|
|
|
|
});
|
2020-02-05 05:57:22 +00:00
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
export default {
|
2021-02-15 18:44:13 +00:00
|
|
|
createConversation,
|
2019-10-29 07:20:54 +00:00
|
|
|
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,
|
2021-05-10 07:31:00 +00:00
|
|
|
getCampaigns,
|
|
|
|
triggerCampaign,
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|