[NEW] Add new Livechat REST endpoint to update the visitor's status (#13108)

* New endpoint add to notify the backend side when de Livechat visitor status changed.

* Meteor package added.
pull/12540/head^2
Renato Becker 6 years ago committed by Rodrigo Nascimento
parent b435b14145
commit 7690a07346
  1. 26
      packages/rocketchat-livechat/server/api/v1/visitor.js
  2. 5
      packages/rocketchat-livechat/server/lib/Livechat.js
  3. 3
      packages/rocketchat-livechat/server/visitorStatus.js

@ -1,6 +1,8 @@
import { Meteor } from 'meteor/meteor';
import { Match, check } from 'meteor/check';
import { RocketChat } from 'meteor/rocketchat:lib';
import LivechatVisitors from '../../../server/models/LivechatVisitors';
import { findGuest } from '../lib/livechat';
RocketChat.API.v1.addRoute('livechat/visitor', {
post() {
@ -94,3 +96,27 @@ RocketChat.API.v1.addRoute('livechat/visitor/:token/room', { authRequired: true
return RocketChat.API.v1.success({ rooms });
},
});
RocketChat.API.v1.addRoute('livechat/visitor.status', {
post() {
try {
check(this.bodyParams, {
token: String,
status: String,
});
const { token, status } = this.bodyParams;
const guest = findGuest(token);
if (!guest) {
throw new Meteor.Error('invalid-token');
}
RocketChat.Livechat.notifyGuestStatusChanged(token, status);
return RocketChat.API.v1.success({ token, status });
} catch (e) {
return RocketChat.API.v1.failure(e);
}
},
});

@ -832,6 +832,11 @@ RocketChat.Livechat = {
return true;
},
notifyGuestStatusChanged(token, status) {
RocketChat.models.LivechatInquiry.updateVisitorStatus(token, status);
RocketChat.models.Rooms.updateVisitorStatus(token, status);
},
sendOfflineMessage(data = {}) {
if (!RocketChat.settings.get('Livechat_display_offline_form')) {
return false;

@ -5,8 +5,7 @@ import { UserPresenceEvents } from 'meteor/konecty:user-presence';
Meteor.startup(() => {
UserPresenceEvents.on('setStatus', (session, status, metadata) => {
if (metadata && metadata.visitor) {
RocketChat.models.LivechatInquiry.updateVisitorStatus(metadata.visitor, status);
RocketChat.models.Rooms.updateVisitorStatus(metadata.visitor, status);
RocketChat.Livechat.notifyGuestStatusChanged(metadata.visitor, status);
}
});
});

Loading…
Cancel
Save