[FIX] Allow e-mail channel to be used without default department. (#23945)

* [IMPROVE] Allow e-mail channel to be used without default department.

* [FIX] Trasferring to wrong department for incoming emails (#23950)

Co-authored-by: Murtaza Patrawala <34130764+murtaza98@users.noreply.github.com>
pull/23959/head
Cauê Felchar 3 years ago committed by GitHub
parent 63abc7e870
commit f8be788549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/livechat/server/lib/Livechat.js
  2. 2
      server/email/IMAPInterceptor.ts
  3. 10
      server/features/EmailInbox/EmailInbox_Incoming.ts

@ -319,6 +319,8 @@ export const Livechat = {
setDepartmentForGuest({ token, department } = {}) {
check(token, String);
check(department, String);
Livechat.logger.debug(`Switching departments for user with token ${ token } (to ${ department })`);
const updateUser = {

@ -57,7 +57,7 @@ export class IMAPInterceptor extends EventEmitter {
});
this.imap.on('error', (err: Error) => {
this.log('Error occurred ...');
this.log('Error occurred: ', err);
throw err;
});
}

@ -30,7 +30,7 @@ type FileAttachment = {
const language = settings.get<string>('Language') || 'en';
const t = (s: string): string => TAPi18n.__(s, { lng: language });
function getGuestByEmail(email: string, name: string, department?: string): any {
function getGuestByEmail(email: string, name: string, department = ''): any {
logger.debug(`Attempt to register a guest for ${ email } on department: ${ department }`);
const guest = LivechatVisitors.findOneGuestByEmailAddress(email);
@ -43,6 +43,11 @@ function getGuestByEmail(email: string, name: string, department?: string): any
previousDepartment: guest.department,
newDepartment: department,
});
if (!department) {
LivechatVisitors.removeDepartmentById(guest._id);
delete guest.department;
return guest;
}
Livechat.setDepartmentForGuest({ token: guest.token, department });
return LivechatVisitors.findOneById(guest._id, {});
}
@ -120,7 +125,7 @@ async function uploadAttachment(attachment: Attachment, rid: string, visitorToke
});
}
export async function onEmailReceived(email: ParsedMail, inbox: string, department?: string): Promise<void> {
export async function onEmailReceived(email: ParsedMail, inbox: string, department = ''): Promise<void> {
logger.debug(`New email conversation received on inbox ${ inbox }. Will be assigned to department ${ department }`);
if (!email.from?.value?.[0]?.address) {
return;
@ -134,6 +139,7 @@ export async function onEmailReceived(email: ParsedMail, inbox: string, departme
const guest = getGuestByEmail(email.from.value[0].address, email.from.value[0].name, department);
logger.debug(`Guest ${ guest._id } obtained. Attempting to find or create a room on department ${ department }`);
let room = LivechatRooms.findOneByVisitorTokenAndEmailThreadAndDepartment(guest.token, thread, department, {});
logger.debug({

Loading…
Cancel
Save