Compare commits
2 commits
develop
...
widget/new
Author | SHA1 | Date | |
---|---|---|---|
|
b44e7e51d5 | ||
|
c42fc65a2d |
4 changed files with 91 additions and 73 deletions
|
@ -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,
|
||||
};
|
51
app/javascript/widget/api/conversationPublic.js
Normal file
51
app/javascript/widget/api/conversationPublic.js
Normal 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,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -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 },
|
||||
});
|
||||
},
|
||||
};
|
40
app/javascript/widget/api/messagePublic.js
Normal file
40
app/javascript/widget/api/messagePublic.js
Normal 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,
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue