2019-10-29 07:20:54 +00:00
|
|
|
import endPoints from 'widget/api/endPoints';
|
|
|
|
import { API } from 'widget/helpers/axios';
|
|
|
|
|
2021-02-15 18:44:13 +00:00
|
|
|
const createConversationAPI = async content => {
|
|
|
|
const urlData = endPoints.createConversation(content);
|
|
|
|
const result = await API.post(urlData.url, urlData.params);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
const sendMessageAPI = async content => {
|
|
|
|
const urlData = endPoints.sendMessage(content);
|
|
|
|
const result = await API.post(urlData.url, urlData.params);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2020-03-30 06:45:06 +00:00
|
|
|
const sendAttachmentAPI = async attachment => {
|
2020-04-17 15:45:20 +00:00
|
|
|
const urlData = endPoints.sendAttachment(attachment);
|
2020-03-30 06:45:06 +00:00
|
|
|
const result = await API.post(urlData.url, urlData.params);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
const getMessagesAPI = async ({ before }) => {
|
2019-12-11 15:27:06 +00:00
|
|
|
const urlData = endPoints.getConversation({ before });
|
|
|
|
const result = await API.get(urlData.url, { params: urlData.params });
|
2019-10-29 07:20:54 +00:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
const getConversationAPI = async () => {
|
|
|
|
return API.get(`/api/v1/widget/conversations${window.location.search}`);
|
|
|
|
};
|
|
|
|
|
2021-08-26 14:49:52 +00:00
|
|
|
const getConversationsAPI = async () => {
|
|
|
|
return API.get(`/api/v1/widget/conversations`);
|
|
|
|
};
|
|
|
|
|
2020-05-04 17:37:56 +00:00
|
|
|
const toggleTyping = async ({ typingStatus }) => {
|
|
|
|
return API.post(
|
|
|
|
`/api/v1/widget/conversations/toggle_typing${window.location.search}`,
|
|
|
|
{ typing_status: typingStatus }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-07 18:34:44 +00:00
|
|
|
const setUserLastSeenAt = async ({ lastSeen }) => {
|
|
|
|
return API.post(
|
|
|
|
`/api/v1/widget/conversations/update_last_seen${window.location.search}`,
|
2020-09-10 13:49:15 +00:00
|
|
|
{ contact_last_seen_at: lastSeen }
|
2020-07-07 18:34:44 +00:00
|
|
|
);
|
|
|
|
};
|
2021-07-13 06:01:21 +00:00
|
|
|
const sendEmailTranscript = async ({ email }) => {
|
|
|
|
return API.post(
|
|
|
|
`/api/v1/widget/conversations/transcript${window.location.search}`,
|
|
|
|
{ email }
|
|
|
|
);
|
|
|
|
};
|
2020-07-07 18:34:44 +00:00
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
export {
|
2021-02-15 18:44:13 +00:00
|
|
|
createConversationAPI,
|
2020-05-09 16:32:43 +00:00
|
|
|
sendMessageAPI,
|
|
|
|
getConversationAPI,
|
|
|
|
getMessagesAPI,
|
|
|
|
sendAttachmentAPI,
|
|
|
|
toggleTyping,
|
2020-07-07 18:34:44 +00:00
|
|
|
setUserLastSeenAt,
|
2021-07-13 06:01:21 +00:00
|
|
|
sendEmailTranscript,
|
2021-08-26 14:49:52 +00:00
|
|
|
getConversationsAPI,
|
2020-05-09 16:32:43 +00:00
|
|
|
};
|