-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow admins to decide if email transcript should be sent always (
#32820) Co-authored-by: Marcos Spessatto Defendi <marcos.defendi@rocket.chat> Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
- Loading branch information
1 parent
f5ea2ff
commit 393e613
Showing
15 changed files
with
273 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
--- | ||
|
||
Added a new setting `Livechat_transcript_send_always` that allows admins to decide if email transcript should be sent all the times when a conversation is closed. This setting bypasses agent's preferences. For this setting to work, `Livechat_enable_transcript` should be off, meaning that visitors will no longer receive the option to decide if they want a transcript or not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { IOmnichannelRoom, IUser, ILivechatVisitor } from '@rocket.chat/core-typings'; | ||
|
||
export type GenericCloseRoomParams = { | ||
room: IOmnichannelRoom; | ||
comment?: string; | ||
options?: { | ||
clientAction?: boolean; | ||
tags?: string[]; | ||
emailTranscript?: | ||
| { | ||
sendToVisitor: false; | ||
} | ||
| { | ||
sendToVisitor: true; | ||
requestData: NonNullable<IOmnichannelRoom['transcriptRequest']>; | ||
}; | ||
pdfTranscript?: { | ||
requestedBy: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export type CloseRoomParamsByUser = { | ||
user: IUser | null; | ||
} & GenericCloseRoomParams; | ||
|
||
export type CloseRoomParamsByVisitor = { | ||
visitor: ILivechatVisitor; | ||
} & GenericCloseRoomParams; | ||
|
||
export type CloseRoomParams = CloseRoomParamsByUser | CloseRoomParamsByVisitor; |
61 changes: 61 additions & 0 deletions
61
apps/meteor/app/livechat/server/lib/parseTranscriptRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import type { ILivechatVisitor, IOmnichannelRoom, IUser } from '@rocket.chat/core-typings'; | ||
import { LivechatVisitors, Users } from '@rocket.chat/models'; | ||
|
||
import { settings } from '../../../settings/server'; | ||
import type { CloseRoomParams } from './localTypes'; | ||
|
||
export const parseTranscriptRequest = async ( | ||
room: IOmnichannelRoom, | ||
options: CloseRoomParams['options'], | ||
visitor?: ILivechatVisitor, | ||
user?: IUser, | ||
): Promise<CloseRoomParams['options']> => { | ||
const visitorDecideTranscript = settings.get<boolean>('Livechat_enable_transcript'); | ||
// visitor decides, no changes | ||
if (visitorDecideTranscript) { | ||
return options; | ||
} | ||
|
||
// send always is disabled, no changes | ||
const sendAlways = settings.get<boolean>('Livechat_transcript_send_always'); | ||
if (!sendAlways) { | ||
return options; | ||
} | ||
|
||
const visitorData = | ||
visitor || | ||
(await LivechatVisitors.findOneById<Pick<ILivechatVisitor, 'visitorEmails'>>(room.v._id, { projection: { visitorEmails: 1 } })); | ||
// no visitor, no changes | ||
if (!visitorData) { | ||
return options; | ||
} | ||
const visitorEmail = visitorData?.visitorEmails?.[0]?.address; | ||
// visitor doesnt have email, no changes | ||
if (!visitorEmail) { | ||
return options; | ||
} | ||
|
||
const defOptions = { projection: { _id: 1, username: 1, name: 1 } }; | ||
const requestedBy = | ||
user || | ||
(room.servedBy && (await Users.findOneById(room.servedBy._id, defOptions))) || | ||
(await Users.findOneById('rocket.cat', defOptions)); | ||
|
||
// no user available for backing request, no changes | ||
if (!requestedBy) { | ||
return options; | ||
} | ||
|
||
return { | ||
...options, | ||
emailTranscript: { | ||
sendToVisitor: true, | ||
requestData: { | ||
email: visitorEmail, | ||
requestedAt: new Date(), | ||
subject: '', | ||
requestedBy, | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.