Chatwoot/app/javascript/dashboard/api/inbox/message.js
Nithin David Thomas 3d2db95417
feat: Add preview for attachment messages (#1562)
Add preview for pending messages and attachments

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-01-06 17:56:29 +05:30

40 lines
994 B
JavaScript

/* eslint no-console: 0 */
/* global axios */
import ApiClient from '../ApiClient';
class MessageApi extends ApiClient {
constructor() {
super('conversations', { accountScoped: true });
}
create({
conversationId,
message,
private: isPrivate,
contentAttributes,
echo_id: echoId,
file,
}) {
const formData = new FormData();
if (file) formData.append('attachments[]', file, file.name);
if (message) formData.append('content', message);
if (contentAttributes)
formData.append('content_attributes', JSON.stringify(contentAttributes));
formData.append('private', isPrivate);
formData.append('echo_id', echoId);
return axios({
method: 'post',
url: `${this.url}/${conversationId}/messages`,
data: formData,
});
}
getPreviousMessages({ conversationId, before }) {
return axios.get(`${this.url}/${conversationId}/messages`, {
params: { before },
});
}
}
export default new MessageApi();