Compare commits

...

2 commits

Author SHA1 Message Date
Nithin David
b44e7e51d5 Delete unused files 2021-11-16 10:01:44 +05:30
Nithin David
c42fc65a2d feat: Refactors API for conversation and messages to support multiple conversations 2021-11-09 18:57:51 +05:30
4 changed files with 91 additions and 73 deletions

View file

@ -1,61 +0,0 @@
import endPoints from 'widget/api/endPoints';
import { API } from 'widget/helpers/axios';
const createConversationAPI = async content => {
const urlData = endPoints.createConversation(content);
const result = await API.post(urlData.url, urlData.params);
return result;
};
const sendMessageAPI = async content => {
const urlData = endPoints.sendMessage(content);
const result = await API.post(urlData.url, urlData.params);
return result;
};
const sendAttachmentAPI = async attachment => {
const urlData = endPoints.sendAttachment(attachment);
const result = await API.post(urlData.url, urlData.params);
return result;
};
const getMessagesAPI = async ({ before }) => {
const urlData = endPoints.getConversation({ before });
const result = await API.get(urlData.url, { params: urlData.params });
return result;
};
const getConversationAPI = async () => {
return API.get(`/api/v1/widget/conversations${window.location.search}`);
};
const toggleTyping = async ({ typingStatus }) => {
return API.post(
`/api/v1/widget/conversations/toggle_typing${window.location.search}`,
{ typing_status: typingStatus }
);
};
const setUserLastSeenAt = async ({ lastSeen }) => {
return API.post(
`/api/v1/widget/conversations/update_last_seen${window.location.search}`,
{ contact_last_seen_at: lastSeen }
);
};
const sendEmailTranscript = async ({ email }) => {
return API.post(
`/api/v1/widget/conversations/transcript${window.location.search}`,
{ email }
);
};
export {
createConversationAPI,
sendMessageAPI,
getConversationAPI,
getMessagesAPI,
sendAttachmentAPI,
toggleTyping,
setUserLastSeenAt,
sendEmailTranscript,
};

View file

@ -0,0 +1,51 @@
import { API } from 'widget/helpers/axios';
const buildUrl = endPoint =>
`/api/v1/widget/${endPoint}${window.location.search}`;
/*
* Refer: https://www.chatwoot.com/developers/api#tag/Conversations-API
*/
export default {
async createWithMessage(content, contact) {
const referrerURL = window.referrerURL || '';
return API.post(buildUrl('conversations'), {
contact: {
name: contact.fullName,
email: contact.emailAddress,
},
message: {
content,
timestamp: new Date().toString(),
referer_url: referrerURL,
},
});
},
async get() {
return API.get(buildUrl('conversations'));
},
async toggleTypingIn({ typingStatus, conversationId }) {
return API.post(buildUrl(`conversations/${conversationId}/toggle_typing`), {
typing_status: typingStatus,
});
},
async setUserLastSeenIn({ lastSeen, conversationId }) {
return API.post(
buildUrl(`conversations/${conversationId}/update_last_seen`),
{
contact_last_seen_at: lastSeen,
}
);
},
async sendEmailTranscriptIn({ email, conversationId }) {
return API.post(buildUrl(`conversations/${conversationId}/transcript`), {
email,
});
},
};

View file

@ -1,12 +0,0 @@
import authEndPoint from 'widget/api/endPoints';
import { API } from 'widget/helpers/axios';
export default {
update: ({ messageId, email, values }) => {
const urlData = authEndPoint.updateMessage(messageId);
return API.patch(urlData.url, {
contact: { email },
message: { submitted_values: values },
});
},
};

View file

@ -0,0 +1,40 @@
import { API } from 'widget/helpers/axios';
const buildUrl = endPoint =>
`/api/v1/widget/${endPoint}${window.location.search}`;
/*
* Refer: https://www.chatwoot.com/developers/api#tag/Messages-API
*/
export default {
create(conversationId, content, echoId) {
return API.post(buildUrl(`conversations/${conversationId}/messages`), {
content,
echo_id: echoId,
});
},
createAttachment(conversationId, attachmentParams) {
return API.post(
buildUrl(`conversations/${conversationId}/messages`),
attachmentParams
);
},
get(conversationId, beforeId) {
return API.get(buildUrl(`conversations/${conversationId}/messages`), {
params: { before: beforeId },
});
},
update(conversationId, messageObject) {
const { id: messageId } = messageObject;
return API.patch(
buildUrl(`conversations/${conversationId}/messages/${messageId}`),
{
...messageObject,
}
);
},
};