-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NEW][ENTERPRISE] Omnichannel Last-Chatted Agent Preferred option #17666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sampaiodiego
merged 18 commits into
develop
from
omnichannel/last-chatted-agent-preferred
May 21, 2020
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
66eb7a8
Add new setting to get the last agent chatted.
renatobecker a447b90
Store Visitor last agent info.
renatobecker 8b2f018
Check room object before get the servedBy property.
renatobecker 28a2172
Route the conversation to another agent when the last agent is not av…
renatobecker 14379a5
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker 197fb4e
Call checkWaitingQueue when the max. number of chats per agent is rea…
renatobecker 395bd88
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker abcfb35
Merge branch 'omnichannel/last-chatted-agent-preferred' of https://gi…
renatobecker a57f714
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker 817323f
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker 82afdb9
Unified setting name and translations.
renatobecker 4c3a1a2
Fix file imports.
renatobecker 31cc1f6
Fix review requests.
renatobecker dce6cf4
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker 03bef15
Add/Removed callback event handlers based on the setting.
renatobecker 3ada422
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker 51d0e87
Normalize agent payload before saving.
renatobecker 50f5821
Merge branch 'develop' into omnichannel/last-chatted-agent-preferred
renatobecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
ee/app/livechat-enterprise/server/hooks/handleLastChattedAgentPreferredEvents.js
This file contains hidden or 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,96 @@ | ||
| import { callbacks } from '../../../../../app/callbacks/server'; | ||
| import { RoutingManager } from '../../../../../app/livechat/server/lib/RoutingManager'; | ||
| import { settings } from '../../../../../app/settings/server'; | ||
| import { LivechatRooms, LivechatInquiry, LivechatVisitors, Users } from '../../../../../app/models/server'; | ||
| import { checkWaitingQueue } from '../lib/Helper'; | ||
|
|
||
| const normalizeDefaultAgent = (agent) => { | ||
| if (!agent) { | ||
| return; | ||
| } | ||
|
|
||
| const { _id: agentId, username } = agent; | ||
| return { agentId, username }; | ||
| }; | ||
|
|
||
| const checkDefaultAgentOnNewRoom = (defaultAgent, defaultGuest) => { | ||
| if (defaultAgent || !defaultGuest) { | ||
| return defaultAgent; | ||
| } | ||
|
|
||
| if (!RoutingManager.getConfig().autoAssignAgent) { | ||
| return defaultAgent; | ||
| } | ||
|
|
||
| const { _id: guestId } = defaultGuest; | ||
| const guest = LivechatVisitors.findOneById(guestId, { fields: { lastAgent: 1, token: 1 } }); | ||
| const { lastAgent: { username: usernameByVisitor } = {}, token } = guest; | ||
|
|
||
| const lastGuestAgent = usernameByVisitor && normalizeDefaultAgent(Users.findOneOnlineAgentByUsername(usernameByVisitor, { fields: { _id: 1, username: 1 } })); | ||
| if (lastGuestAgent) { | ||
| return lastGuestAgent; | ||
| } | ||
|
|
||
| const room = LivechatRooms.findOneLastServedAndClosedByVisitorToken(token, { fields: { servedBy: 1 } }); | ||
| if (!room || !room.servedBy) { | ||
| return defaultAgent; | ||
| } | ||
|
|
||
| const { servedBy: { username: usernameByRoom } } = room; | ||
| const lastRoomAgent = normalizeDefaultAgent(Users.findOneOnlineAgentByUsername(usernameByRoom, { fields: { _id: 1, username: 1 } })); | ||
| return lastRoomAgent || defaultAgent; | ||
| }; | ||
|
|
||
| const onMaxNumberSimultaneousChatsReached = (inquiry, agent) => { | ||
| if (!inquiry || !inquiry.defaultAgent) { | ||
| return inquiry; | ||
| } | ||
|
|
||
| if (!RoutingManager.getConfig().autoAssignAgent) { | ||
| return inquiry; | ||
| } | ||
|
|
||
| const { _id, defaultAgent, department } = inquiry; | ||
|
|
||
| LivechatInquiry.removeDefaultAgentById(_id); | ||
|
|
||
| const { _id: defaultAgentId } = defaultAgent; | ||
| const { agentId } = agent; | ||
|
|
||
| if (defaultAgentId === agentId) { | ||
| checkWaitingQueue(department); | ||
| } | ||
|
|
||
| return LivechatInquiry.findOneById(_id); | ||
| }; | ||
|
|
||
| const afterTakeInquiry = (inquiry, agent) => { | ||
| if (!inquiry || !agent) { | ||
| return inquiry; | ||
| } | ||
|
|
||
| if (!RoutingManager.getConfig().autoAssignAgent) { | ||
| return inquiry; | ||
| } | ||
|
|
||
| const { v: { token } = {} } = inquiry; | ||
| if (!token) { | ||
| return inquiry; | ||
| } | ||
|
|
||
| LivechatVisitors.updateLastAgentByToken(token, { ...agent, ts: new Date() }); | ||
|
|
||
| return inquiry; | ||
| }; | ||
| settings.get('Livechat_last_chatted_agent_routing', function(key, value) { | ||
| if (!value) { | ||
| callbacks.remove('livechat.checkDefaultAgentOnNewRoom', 'livechat-check-default-agent-new-room'); | ||
| callbacks.remove('livechat.onMaxNumberSimultaneousChatsReached', 'livechat-on-max-number-simultaneous-chats-reached'); | ||
| callbacks.remove('livechat.afterTakeInquiry', 'livechat-save-default-agent-after-take-inquiry'); | ||
| return; | ||
| } | ||
|
|
||
| callbacks.add('livechat.checkDefaultAgentOnNewRoom', checkDefaultAgentOnNewRoom, callbacks.priority.MEDIUM, 'livechat-check-default-agent-new-room'); | ||
| callbacks.add('livechat.onMaxNumberSimultaneousChatsReached', onMaxNumberSimultaneousChatsReached, callbacks.priority.MEDIUM, 'livechat-on-max-number-simultaneous-chats-reached'); | ||
| callbacks.add('livechat.afterTakeInquiry', afterTakeInquiry, callbacks.priority.MEDIUM, 'livechat-save-default-agent-after-take-inquiry'); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.