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

[NEW][ENTERPRISE] Auto close abandoned Omnichannel rooms #17055

Merged
merged 19 commits into from Apr 13, 2020

Conversation

MarcosSpessatto
Copy link
Contributor

@MarcosSpessatto MarcosSpessatto commented Mar 27, 2020

This new feature allows administrators to automatically close Omnichannel rooms when a chat is considered abandoned by the visitor. We already have a setting to define how long to wait before considering an abandoned chat, so now we can also close chats that have been abandoned.

@MarcosSpessatto MarcosSpessatto added this to the 3.2.0 milestone Mar 27, 2020
@renatobecker renatobecker changed the title [NEW][ENTERPRISE] Close/Freeze automatically inactive Omnichannel rooms [NEW][ENTERPRISE] Close/Freeze automatically abandoned Omnichannel rooms Mar 27, 2020
app/livechat/server/hooks/saveVisitorInactivity.js Outdated Show resolved Hide resolved
app/livechat/server/hooks/saveVisitorInactivity.js Outdated Show resolved Hide resolved
app/livechat/server/index.js Outdated Show resolved Hide resolved
app/livechat/server/lib/VisitorInactivityMonitor.js Outdated Show resolved Hide resolved
app/livechat/server/startup.js Outdated Show resolved Hide resolved
app/models/server/models/LivechatRooms.js Outdated Show resolved Hide resolved
@MarcosSpessatto MarcosSpessatto marked this pull request as ready for review March 28, 2020 15:17
Copy link
Contributor

@renatobecker renatobecker left a comment

Choose a reason for hiding this comment

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

@MarcosSpessatto I suggest renaming all of the terms inactive by abandoned.
Thanks.

app/livechat/server/index.js Show resolved Hide resolved
app/models/server/models/LivechatRooms.js Outdated Show resolved Hide resolved
ee/i18n/en.i18n.json Outdated Show resolved Hide resolved
ee/i18n/en.i18n.json Outdated Show resolved Hide resolved
ee/i18n/en.i18n.json Outdated Show resolved Hide resolved
ee/app/livechat-enterprise/server/settings.js Outdated Show resolved Hide resolved
ee/app/livechat-enterprise/server/startup.js Outdated Show resolved Hide resolved
@renatobecker
Copy link
Contributor

renatobecker commented Apr 5, 2020

@MarcosSpessatto We need to add a new setting to set a custom close message when the room is closed by visitor inactivity. The closeRoom method accepts a comment parameter, so, if there is a custom message defined, we need to pass it as the comment parameter.
The custom message can be defined by default setting or by department.

Copy link
Contributor

@renatobecker renatobecker left a comment

Choose a reason for hiding this comment

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

@MarcosSpessatto we almost done, but I left some comments to improve specific parts of the code.

Also, we need to update the predicted Visitor Abandonment value when a room is forward from a department to another, did you get it?
We can have a different department.visitorInactivityTimeoutInSeconds value between the old and the new department, so we need to check it and if the values are not equal, we need to update the room.

We already have a callback for this purpose, please take a look at here:
https://github.com/RocketChat/Rocket.Chat/blob/develop/ee/app/livechat-enterprise/server/hooks/afterForwardChatToDepartment.js#L5-L24

Thanks.

ee/i18n/en.i18n.json Outdated Show resolved Hide resolved
ee/i18n/pt-BR.i18n.json Outdated Show resolved Hide resolved
ee/i18n/pt-BR.i18n.json Outdated Show resolved Hide resolved
ee/i18n/en.i18n.json Outdated Show resolved Hide resolved
app/models/server/models/LivechatRooms.js Outdated Show resolved Hide resolved
ee/app/models/server/models/LivechatRooms.js Outdated Show resolved Hide resolved
ee/app/livechat-enterprise/server/lib/Helper.js Outdated Show resolved Hide resolved
@@ -23,4 +23,51 @@ overwriteClassOnLicense('livechat-enterprise', LivechatRooms, {
},
});


LivechatRooms.prototype.setTimeWhenRoomWillBeAbandoned = function(roomId, willBeAbandonedAt) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LivechatRooms.prototype.setTimeWhenRoomWillBeAbandoned = function(roomId, willBeAbandonedAt) {
LivechatRooms.prototype.setPredictedVisitorAbandonment = function(roomId, willBeAbandonedAt) {

ee/app/models/server/models/LivechatRooms.js Outdated Show resolved Hide resolved
ee/app/livechat-enterprise/server/lib/Helper.js Outdated Show resolved Hide resolved
@@ -58,5 +58,5 @@ callbacks.add('livechat.closeRoom', (room) => {
return;
}
const secondsSinceLastAgentResponse = getSecondsSinceLastAgentResponse(room, agentLastMessage);
LivechatRooms.setVisitorInactivityInSecondsByRoomId(room._id, secondsSinceLastAgentResponse);
LivechatRooms.setVisitorInactivityInSecondsById(room._id, secondsSinceLastAgentResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

This method needs to be renamed on the Model as well.
The old name is still there.

<div class="input-line">
<label>{{_ "Livechat_abandoned_rooms_closed_custom_message"}}</label>
<div>
<input type="text" class="rc-input__element customFormField" name="abandonedRoomsCloseCustomMessage" value="{{department.abandonedRoomsCloseCustomMessage}}" placeholder="{{_ "Livechat_abandoned_rooms_closed_custom_message"}}" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<input type="text" class="rc-input__element customFormField" name="abandonedRoomsCloseCustomMessage" value="{{department.abandonedRoomsCloseCustomMessage}}" placeholder="{{_ "Livechat_abandoned_rooms_closed_custom_message"}}" />
<input type="text" class="rc-input__element customFormField" name="abandonedRoomsCloseCustomMessage" value="{{department.abandonedRoomsCloseCustomMessage}}" placeholder="{{_ "Enter_a_custom_message"}}" />

};

export const updatePredictedVisitorAbandonment = (closeRooms) => {
if (closeRooms) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should check this setting here: settings.get('Livechat_auto_close_abandoned_rooms')
We can avoid an unnecessary loop here.

}

closeRooms(room) {
let comment = settings.get('Livechat_abandoned_rooms_closed_custom_message') || TAPi18n.__('Closed_automatically');
Copy link
Contributor

Choose a reason for hiding this comment

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

How about creating a custom message cache(array), at the beginning of the closeRooms method and store the department custom messages there?
This would avoid unnecessary searches in the DB.

const department = LivechatDepartment.findOneById(room.departmentId);
comment = department.abandonedRoomsCloseCustomMessage || comment;
}
Livechat.closeRoom({
Copy link
Contributor

Choose a reason for hiding this comment

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

The user who is closing the chats is required here. So, my suggestion is to use rocket.cat to as a user to perform this action.
Then you don't need to set system here:
https://github.com/RocketChat/Rocket.Chat/pull/17055/files#diff-3e725e94e4a647e422a10d903b96cf59R349

@renatobecker renatobecker changed the title [NEW][ENTERPRISE] Close/Freeze automatically abandoned Omnichannel rooms [NEW][ENTERPRISE] Close automatically abandoned Omnichannel rooms Apr 13, 2020
@lgtm-com
Copy link

lgtm-com bot commented Apr 13, 2020

This pull request introduces 1 alert when merging 3077a4b into 58b14d1 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

Copy link
Contributor

@renatobecker renatobecker left a comment

Choose a reason for hiding this comment

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

@MarcosSpessatto

When an agent sends a message, we set the room as responded, as you can see here:
https://github.com/RocketChat/Rocket.Chat/blob/develop/app/livechat/server/hooks/markRoomResponded.js#L20-L29

But when the visitor sends a message, and the status of the room is not waiting for response, we need to set it, otherwise the rooms will be closed by inactivity due to this test(which is correct):
https://github.com/RocketChat/Rocket.Chat/pull/17055/files#diff-a5636aa5e27e8717c18539b084e2348aR43

@RocketChat RocketChat deleted a comment from lgtm-com bot Apr 13, 2020
@renatobecker renatobecker changed the title [NEW][ENTERPRISE] Close automatically abandoned Omnichannel rooms [NEW][ENTERPRISE] Auto close abandoned Omnichannel rooms Apr 13, 2020
@renatobecker renatobecker added this to In progress in Omnichannel Roadmap via automation Apr 13, 2020
Omnichannel Roadmap automation moved this from In progress to Reviewer approved Apr 13, 2020
@lgtm-com
Copy link

lgtm-com bot commented Apr 13, 2020

This pull request introduces 1 alert when merging 1d2c721 into c180a53 - view on LGTM.com

new alerts:

  • 1 for Expression has no effect

@RocketChat RocketChat deleted a comment from lgtm-com bot Apr 13, 2020
@renatobecker renatobecker merged commit 6a94e3c into develop Apr 13, 2020
Omnichannel Roadmap automation moved this from Reviewer approved to Done Apr 13, 2020
@renatobecker renatobecker deleted the livechat-close-inactive branch April 13, 2020 21:43
gabriellsh added a commit that referenced this pull request Apr 14, 2020
…users_and_rooms

* 'develop' of github.com:RocketChat/Rocket.Chat:
  [FIX] Omnichannel SMS / WhatsApp integration errors due to missing location data (#17288)
  [FIX] User search on directory not working correctly (#17299)
  [FIX] Can not save Unread Tray Icon Alert user preference (#16288) (#16313)
  [FIX] Variable rendering problem on Import recent history page (#15997)
  [FIX] Admin panel custom sounds, multiple sound playback fix and added single play/pause button (#16215)
  [FIX] Discussions created from inside DMs were not working (#17282)
  [FIX] translation for nl (#16742)
  [FIX] No maxlength defined for custom user status (#16534)
  [FIX] Directory users email sort button (#16606)
  [FIX] In Create a New Channel, input should be focused on channel name instead of invite users (#16405)
  [FIX] Email not verified message (#16236)
  [FIX] Directory default tab (#17283)
  Update ru.i18n.json (#16869)
  [FIX] Avatar on sidebar when showing real names (#17286)
  Update Apps-Engine to stable version (#17287)
  [NEW][ENTERPRISE] Auto close abandoned Omnichannel rooms (#17055)
  Static props for Administration route components (#17285)
  [NEW] Default favorite channels (#16025)
  Apply $and helper to message template (#17280)
@sampaiodiego sampaiodiego mentioned this pull request Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants