Chatwoot/app/javascript/dashboard/api/inbox/message.js
Nithin David Thomas 68e697c379
feat: Support cc and bcc in email replies (#3098)
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-10-11 13:00:48 +05:30

79 lines
1.6 KiB
JavaScript

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