Skip to content
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

[FIX] Chat Transfer Failure due to Unrecognized stage name departmentId #22838

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/server/models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class Users extends Base {
// if department is provided, remove the agents that are not from the selected department
const departmentFilter = departmentId ? [{
$lookup: {
from: 'rocketchat_livechat_department_agent',
from: 'rocketchat_livechat_department_agents',
let: { departmentId: '$departmentId', agentId: '$agentId' },
pipeline: [{
$match: { $expr: { $eq: ['$$agentId', '$_id'] } },
Expand Down Expand Up @@ -273,7 +273,7 @@ export class Users extends Base {
},
},
},
...customFilter ? [customFilter] : [],
...customFilter ? [{ $match: customFilter }] : [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this was required? TBH, I don't think this is required because customFilters are getting defined by this callback and as you can see here and here both these return values apply a $match filter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I logged what we are receiving in this function, It was showing {departmentId: 'string'}.

FYI I don't have enterprise edition, so /ee/app/livechat-enterprise/server/hooks/applySimultaneousChatsRestrictions.ts hook won't be called.

Maybe the issue is only with a non-enterprise server?

Copy link
Contributor

@murtaza98 murtaza98 Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay got it. I found out that this was happening because livechat.applySimultaneousChatRestrictions callback was simply returning the first param passed to it incase the callback was not found, which happens in the community edition.

So I think the correct way to use this callback was to pass the params/constants in the second param and keep the first param empty/default.

PS: I took the liberty of raising a PR for the same #22839

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @murtaza98 🙃

{
$sort: {
'queueInfo.chats': 1,
Expand Down