-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Newly added agent not following business hours (#29529)
Co-authored-by: Kevin Aleman <11577696+KevLehman@users.noreply.github.com>
- Loading branch information
Showing
24 changed files
with
301 additions
and
172 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,6 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
"@rocket.chat/model-typings": patch | ||
--- | ||
|
||
fix: newly added agent not following business hours |
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
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
50 changes: 39 additions & 11 deletions
50
apps/meteor/app/livechat/server/hooks/afterUserActions.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 |
---|---|---|
@@ -1,23 +1,51 @@ | ||
import type { IUser } from '@rocket.chat/core-typings'; | ||
import { Users } from '@rocket.chat/models'; | ||
import type { UsersUpdateParamsPOST } from '@rocket.chat/rest-typings'; | ||
|
||
import { callbacks } from '../../../../lib/callbacks'; | ||
import { Livechat } from '../lib/Livechat'; | ||
import { callbackLogger } from '../lib/logger'; | ||
|
||
type UserData = UsersUpdateParamsPOST['data'] & { _id: string }; | ||
type IAfterSaveUserProps = { | ||
user: IUser; | ||
oldUser: IUser | null; | ||
}; | ||
|
||
const wasAgent = (user: Pick<IUser, 'roles'> | null) => user?.roles?.includes('livechat-agent'); | ||
const isAgent = (user: Pick<IUser, 'roles'> | null) => user?.roles?.includes('livechat-agent'); | ||
|
||
const handleAgentUpdated = async (userData: IAfterSaveUserProps) => { | ||
const { | ||
user: { _id: userId, username }, | ||
user: newUser, | ||
oldUser, | ||
} = userData; | ||
|
||
if (wasAgent(oldUser) && !isAgent(newUser)) { | ||
callbackLogger.debug('Removing agent', userId); | ||
await Livechat.removeAgent(username); | ||
} | ||
|
||
const handleAgentUpdated = async (userData: UserData) => { | ||
if (!userData?.roles?.includes('livechat-agent')) { | ||
await Users.unsetExtension(userData._id); | ||
if (!wasAgent(oldUser) && isAgent(newUser)) { | ||
callbackLogger.debug('Adding agent', userId); | ||
await Livechat.addAgent(username); | ||
} | ||
}; | ||
|
||
const handleDeactivateUser = async (userData: IUser) => { | ||
if (userData?.roles?.includes('livechat-agent')) { | ||
await Users.unsetExtension(userData._id); | ||
const handleDeactivateUser = async (user: IUser) => { | ||
if (wasAgent(user)) { | ||
callbackLogger.debug('Removing agent', user._id); | ||
await Livechat.removeAgent(user.username); | ||
} | ||
}; | ||
|
||
callbacks.add('afterSaveUser', handleAgentUpdated, callbacks.priority.LOW, 'livechat-after-save-user-remove-extension'); | ||
const handleActivateUser = async (user: IUser) => { | ||
if (isAgent(user)) { | ||
callbackLogger.debug('Adding agent', user._id); | ||
await Livechat.addAgent(user.username); | ||
} | ||
}; | ||
|
||
callbacks.add('afterSaveUser', handleAgentUpdated, callbacks.priority.LOW, 'livechat-after-save-user-update-agent'); | ||
|
||
callbacks.add('afterDeactivateUser', handleDeactivateUser, callbacks.priority.LOW, 'livechat-after-deactivate-user-remove-agent'); | ||
|
||
callbacks.add('afterDeactivateUser', handleDeactivateUser, callbacks.priority.LOW, 'livechat-after-deactivate-user-remove-extension'); | ||
callbacks.add('afterActivateUser', handleActivateUser, callbacks.priority.LOW, 'livechat-after-activate-user-add-agent'); |
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
1 change: 1 addition & 0 deletions
1
...app/livechat/server/lib/callbackLogger.ts → .../meteor/app/livechat/server/lib/logger.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { Logger } from '../../../../server/lib/logger/Logger'; | ||
|
||
export const callbackLogger = new Logger('[Omnichannel] Callback'); | ||
export const businessHourLogger = new Logger('Business Hour'); |
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.