[FIX] Receiving agent for new livechats from REST API (#14103)

pull/14116/head
Renato Becker 7 years ago committed by Diego Sampaio
parent 19abded78f
commit 4e92002c11
  1. 4
      app/livechat/server/api/lib/livechat.js
  2. 13
      app/livechat/server/api/v1/room.js
  3. 3
      app/livechat/server/api/v1/videoCall.js
  4. 2
      app/livechat/server/lib/QueueMethods.js

@ -64,7 +64,7 @@ export function findOpenRoom(token, departmentId) {
return room;
}
export function getRoom(guest, rid, roomInfo) {
export function getRoom({ guest, rid, roomInfo, agent }) {
const token = guest && guest.token;
const message = {
@ -75,7 +75,7 @@ export function getRoom(guest, rid, roomInfo) {
ts: new Date(),
};
return Livechat.getRoom(guest, message, roomInfo);
return Livechat.getRoom(guest, message, roomInfo, agent);
}
export function findAgent(agentId) {

@ -5,7 +5,7 @@ import { TAPi18n } from 'meteor/tap:i18n';
import { settings as rcSettings } from '../../../../settings';
import { Messages, Rooms } from '../../../../models';
import { API } from '../../../../api';
import { findGuest, findRoom, getRoom, settings } from '../lib/livechat';
import { findGuest, findRoom, getRoom, settings, findAgent } from '../lib/livechat';
import { Livechat } from '../../lib/Livechat';
API.v1.addRoute('livechat/room', {
@ -14,6 +14,7 @@ API.v1.addRoute('livechat/room', {
check(this.queryParams, {
token: String,
rid: Match.Maybe(String),
agentId: Match.Maybe(String),
});
const { token } = this.queryParams;
@ -22,8 +23,16 @@ API.v1.addRoute('livechat/room', {
throw new Meteor.Error('invalid-token');
}
let agent;
const { agentId } = this.queryParams;
const agentObj = agentId && findAgent(agentId);
if (agentObj) {
const { username } = agentObj;
agent = Object.assign({}, { agentId, username });
}
const rid = this.queryParams.rid || Random.id();
const room = getRoom(guest, rid);
const room = getRoom({ guest, rid, agent });
return API.v1.success(room);
} catch (e) {

@ -25,7 +25,8 @@ API.v1.addRoute('livechat/video.call/:token', {
}
const rid = this.queryParams.rid || Random.id();
const { room } = getRoom(guest, rid, { jitsiTimeout: new Date(Date.now() + 3600 * 1000) });
const roomInfo = { jitsiTimeout: new Date(Date.now() + 3600 * 1000) };
const { room } = getRoom({ guest, rid, roomInfo });
const config = settings();
if (!config.theme || !config.theme.actionLinks) {
throw new Meteor.Error('invalid-livechat-config');

@ -14,7 +14,7 @@ export const QueueMethods = {
* of open chats is paired with the incoming livechat
*/
'Least_Amount'(guest, message, roomInfo, agent) {
if (!agent) {
if (!agent || (agent.username && !Users.findOneOnlineAgentByUsername(agent.username))) {
agent = Livechat.getNextAgent(guest.department);
if (!agent) {
throw new Meteor.Error('no-agent-online', 'Sorry, no online agents');

Loading…
Cancel
Save