Chatwoot/app/javascript/widget/api/messagePublic.js
2021-09-29 14:28:32 +05:30

39 lines
1.1 KiB
JavaScript

import { API } from 'widget/helpers/axios';
const buildUrl = endPoint =>
`/public/api/v1/${endPoint}${window.location.search}`;
/*
* Refer: https://www.chatwoot.com/developers/api#tag/Messages-API
*/
export default {
create(inboxIdentifier, contactIdentifier, conversationId, content, echoId) {
return API.post(
buildUrl(
`inboxes/${inboxIdentifier}/contacts/${contactIdentifier}/conversations/${conversationId}/messages`
),
{ content, echo_id: echoId }
);
},
get(inboxIdentifier, contactIdentifier, conversationId) {
return API.get(
buildUrl(
`inboxes/${inboxIdentifier}/contacts/${contactIdentifier}/conversations/${conversationId}/messages`
)
);
},
update(inboxIdentifier, contactIdentifier, conversationId, messageObject) {
const { id: messageId } = messageObject;
return API.patch(
buildUrl(
`inboxes/${inboxIdentifier}/contacts/${contactIdentifier}/conversations/${conversationId}/messages/${messageId}`
),
{
...messageObject,
}
);
},
};