feat: Refactors API for conversation and messages to support multiple conversations
This commit is contained in:
parent
0c9b682329
commit
c42fc65a2d
2 changed files with 91 additions and 0 deletions
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…
Add table
Add a link
Reference in a new issue