feat: IMAP Email Channel (#3298)
This change allows the user to configure both IMAP and SMTP for an email inbox. IMAP enables the user to see emails in Chatwoot. And user can use SMTP to reply to an email conversation. Users can use the default settings to send and receive emails for email inboxes if both IMAP and SMTP are disabled. Fixes #2520
This commit is contained in:
@@ -35,6 +35,8 @@ export const state = {
|
||||
isUpdating: false,
|
||||
isUpdatingAutoAssignment: false,
|
||||
isDeleting: false,
|
||||
isUpdatingIMAP: false,
|
||||
isUpdatingSMTP: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -164,6 +166,52 @@ export const actions = {
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
updateInboxIMAP: async (
|
||||
{ commit },
|
||||
{ id, formData = true, ...inboxParams }
|
||||
) => {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingIMAP: true,
|
||||
});
|
||||
try {
|
||||
const response = await InboxesAPI.update(
|
||||
id,
|
||||
formData ? buildInboxData(inboxParams) : inboxParams
|
||||
);
|
||||
commit(types.default.EDIT_INBOXES, response.data);
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingIMAP: false,
|
||||
});
|
||||
} catch (error) {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingIMAP: false,
|
||||
});
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
updateInboxSMTP: async (
|
||||
{ commit },
|
||||
{ id, formData = true, ...inboxParams }
|
||||
) => {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingSMTP: true,
|
||||
});
|
||||
try {
|
||||
const response = await InboxesAPI.update(
|
||||
id,
|
||||
formData ? buildInboxData(inboxParams) : inboxParams
|
||||
);
|
||||
commit(types.default.EDIT_INBOXES, response.data);
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingSMTP: false,
|
||||
});
|
||||
} catch (error) {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
||||
isUpdatingSMTP: false,
|
||||
});
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
delete: async ({ commit }, inboxId) => {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, { isDeleting: true });
|
||||
try {
|
||||
|
||||
@@ -107,6 +107,66 @@ describe('#actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateInboxIMAP', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const updatedInbox = inboxList[0];
|
||||
|
||||
axios.patch.mockResolvedValue({ data: updatedInbox });
|
||||
await actions.updateInboxIMAP(
|
||||
{ commit },
|
||||
{ id: updatedInbox.id, inbox: { channel: { imap_enabled: true } } }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: true }],
|
||||
[types.default.EDIT_INBOXES, updatedInbox],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.updateInboxIMAP(
|
||||
{ commit },
|
||||
{ id: inboxList[0].id, inbox: { channel: { imap_enabled: true } } }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#updateInboxSMTP', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
const updatedInbox = inboxList[0];
|
||||
|
||||
axios.patch.mockResolvedValue({ data: updatedInbox });
|
||||
await actions.updateInboxSMTP(
|
||||
{ commit },
|
||||
{ id: updatedInbox.id, inbox: { channel: { smtp_enabled: true } } }
|
||||
);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: true }],
|
||||
[types.default.EDIT_INBOXES, updatedInbox],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.updateInboxSMTP(
|
||||
{ commit },
|
||||
{ id: inboxList[0].id, inbox: { channel: { smtp_enabled: true } } }
|
||||
)
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.delete.mockResolvedValue({ data: inboxList[0] });
|
||||
|
||||
Reference in New Issue
Block a user