|
|
|
|
@ -5,11 +5,12 @@ import { Livechat } from '../../lib/Livechat'; |
|
|
|
|
import { settings, findOpenRoom, getExtraConfigInfo, findAgent } from '../lib/livechat'; |
|
|
|
|
|
|
|
|
|
API.v1.addRoute('livechat/config', { |
|
|
|
|
get() { |
|
|
|
|
async get() { |
|
|
|
|
try { |
|
|
|
|
check(this.queryParams, { |
|
|
|
|
token: Match.Maybe(String), |
|
|
|
|
department: Match.Maybe(String), |
|
|
|
|
businessUnit: Match.Maybe(String), |
|
|
|
|
}); |
|
|
|
|
const enabled = Livechat.enabled(); |
|
|
|
|
|
|
|
|
|
@ -17,16 +18,17 @@ API.v1.addRoute('livechat/config', { |
|
|
|
|
return API.v1.success({ config: { enabled: false } }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const config = Promise.await(settings()); |
|
|
|
|
const { token, department, businessUnit } = this.queryParams; |
|
|
|
|
|
|
|
|
|
const config = await settings({ businessUnit }); |
|
|
|
|
|
|
|
|
|
const { token, department } = this.queryParams; |
|
|
|
|
const status = Livechat.online(department); |
|
|
|
|
const guest = token && Livechat.findGuest(token); |
|
|
|
|
|
|
|
|
|
const room = guest && findOpenRoom(token); |
|
|
|
|
const agent = guest && room && room.servedBy && findAgent(room.servedBy._id); |
|
|
|
|
|
|
|
|
|
const extra = Promise.await(getExtraConfigInfo(room)); |
|
|
|
|
const extra = await getExtraConfigInfo(room); |
|
|
|
|
return API.v1.success({ |
|
|
|
|
config: { ...config, online: status, guest, room, agent, ...extra }, |
|
|
|
|
}); |
|
|
|
|
|