diff --git a/packages/rocketchat-livechat/imports/server/rest/departments.js b/packages/rocketchat-livechat/imports/server/rest/departments.js index 981a4003c96..635f89b32de 100644 --- a/packages/rocketchat-livechat/imports/server/rest/departments.js +++ b/packages/rocketchat-livechat/imports/server/rest/departments.js @@ -1,7 +1,8 @@ import { check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; -import { LivechatDepartment, LivechatDepartmentAgents } from '../../../server/models'; import { API } from 'meteor/rocketchat:api'; +import { LivechatDepartment, LivechatDepartmentAgents } from '../../../server/models'; +import { Livechat } from '../../../server/lib/Livechat'; API.v1.addRoute('livechat/department', { authRequired: true }, { get() { @@ -24,7 +25,7 @@ API.v1.addRoute('livechat/department', { authRequired: true }, { agents: Array, }); - const department = RocketChat.Livechat.saveDepartment(null, this.bodyParams.department, this.bodyParams.agents); + const department = Livechat.saveDepartment(null, this.bodyParams.department, this.bodyParams.agents); if (department) { return API.v1.success({ @@ -74,7 +75,7 @@ API.v1.addRoute('livechat/department/:_id', { authRequired: true }, { agents: Array, }); - if (RocketChat.Livechat.saveDepartment(this.urlParams._id, this.bodyParams.department, this.bodyParams.agents)) { + if (Livechat.saveDepartment(this.urlParams._id, this.bodyParams.department, this.bodyParams.agents)) { return API.v1.success({ department: LivechatDepartment.findOneById(this.urlParams._id), agents: LivechatDepartmentAgents.find({ departmentId: this.urlParams._id }).fetch(), @@ -96,7 +97,7 @@ API.v1.addRoute('livechat/department/:_id', { authRequired: true }, { _id: String, }); - if (RocketChat.Livechat.removeDepartment(this.urlParams._id)) { + if (Livechat.removeDepartment(this.urlParams._id)) { return API.v1.success(); } diff --git a/packages/rocketchat-livechat/imports/server/rest/facebook.js b/packages/rocketchat-livechat/imports/server/rest/facebook.js index 0e05e98d216..d10c0664be2 100644 --- a/packages/rocketchat-livechat/imports/server/rest/facebook.js +++ b/packages/rocketchat-livechat/imports/server/rest/facebook.js @@ -4,6 +4,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import LivechatVisitors from '../../../server/models/LivechatVisitors'; +import { Livechat } from '../../../server/lib/Livechat'; /** * @api {post} /livechat/facebook Send Facebook message @@ -71,7 +72,7 @@ API.v1.addRoute('livechat/facebook', { sendMessage.message.rid = Random.id(); sendMessage.message.token = this.bodyParams.token; - const userId = RocketChat.Livechat.registerGuest({ + const userId = Livechat.registerGuest({ token: sendMessage.message.token, name: `${ this.bodyParams.first_name } ${ this.bodyParams.last_name }`, }); @@ -85,7 +86,7 @@ API.v1.addRoute('livechat/facebook', { try { return { sucess: true, - message: RocketChat.Livechat.sendMessage(sendMessage), + message: Livechat.sendMessage(sendMessage), }; } catch (e) { console.error('Error using Facebook ->', e); diff --git a/packages/rocketchat-livechat/imports/server/rest/sms.js b/packages/rocketchat-livechat/imports/server/rest/sms.js index 43b44b0a598..8b7861fcd60 100644 --- a/packages/rocketchat-livechat/imports/server/rest/sms.js +++ b/packages/rocketchat-livechat/imports/server/rest/sms.js @@ -4,6 +4,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import { SMS } from 'meteor/rocketchat:sms'; import LivechatVisitors from '../../../server/models/LivechatVisitors'; +import { Livechat } from '../../../server/lib/Livechat'; API.v1.addRoute('livechat/sms-incoming/:service', { post() { @@ -37,7 +38,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', { sendMessage.message.rid = Random.id(); sendMessage.message.token = Random.id(); - const visitorId = RocketChat.Livechat.registerGuest({ + const visitorId = Livechat.registerGuest({ username: sms.from.replace(/[^0-9]/g, ''), token: sendMessage.message.token, phone: { @@ -73,7 +74,7 @@ API.v1.addRoute('livechat/sms-incoming/:service', { }); try { - const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); + const message = SMSService.response.call(this, Livechat.sendMessage(sendMessage)); Meteor.defer(() => { if (sms.extra) { diff --git a/packages/rocketchat-livechat/imports/server/rest/users.js b/packages/rocketchat-livechat/imports/server/rest/users.js index 3892da0bbb5..e8df87995b4 100644 --- a/packages/rocketchat-livechat/imports/server/rest/users.js +++ b/packages/rocketchat-livechat/imports/server/rest/users.js @@ -1,6 +1,7 @@ import { check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; +import { Livechat } from '../../../server/lib/Livechat'; import _ from 'underscore'; API.v1.addRoute('livechat/users/:type', { authRequired: true }, { @@ -46,12 +47,12 @@ API.v1.addRoute('livechat/users/:type', { authRequired: true }, { }); if (this.urlParams.type === 'agent') { - const user = RocketChat.Livechat.addAgent(this.bodyParams.username); + const user = Livechat.addAgent(this.bodyParams.username); if (user) { return API.v1.success({ user }); } } else if (this.urlParams.type === 'manager') { - const user = RocketChat.Livechat.addManager(this.bodyParams.username); + const user = Livechat.addManager(this.bodyParams.username); if (user) { return API.v1.success({ user }); } @@ -125,11 +126,11 @@ API.v1.addRoute('livechat/users/:type/:_id', { authRequired: true }, { } if (this.urlParams.type === 'agent') { - if (RocketChat.Livechat.removeAgent(user.username)) { + if (Livechat.removeAgent(user.username)) { return API.v1.success(); } } else if (this.urlParams.type === 'manager') { - if (RocketChat.Livechat.removeManager(user.username)) { + if (Livechat.removeManager(user.username)) { return API.v1.success(); } } else { diff --git a/packages/rocketchat-livechat/lib/messageTypes.js b/packages/rocketchat-livechat/lib/messageTypes.js index b76b7508fe0..ae0f7763045 100644 --- a/packages/rocketchat-livechat/lib/messageTypes.js +++ b/packages/rocketchat-livechat/lib/messageTypes.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { TAPi18n } from 'meteor/tap:i18n'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from 'meteor/rocketchat:livechat'; RocketChat.MessageTypes.registerType({ id: 'livechat_navigation_history', @@ -37,7 +38,7 @@ RocketChat.actionLinks.register('denyLivechatCall', function(message/* , params* const language = user.language || RocketChat.settings.get('Language') || 'en'; - RocketChat.Livechat.closeRoom({ + Livechat.closeRoom({ user, room: RocketChat.models.Rooms.findOneById(message.rid), comment: TAPi18n.__('Videocall_declined', { lng: language }), diff --git a/packages/rocketchat-livechat/server/agentStatus.js b/packages/rocketchat-livechat/server/agentStatus.js index 919b6f84f6a..04628283dec 100644 --- a/packages/rocketchat-livechat/server/agentStatus.js +++ b/packages/rocketchat-livechat/server/agentStatus.js @@ -1,8 +1,9 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import { UserPresenceMonitor } from 'meteor/konecty:user-presence'; +import { Livechat } from './lib/Livechat'; UserPresenceMonitor.onSetUserStatus((user, status) => { if (RocketChat.authz.hasRole(user._id, 'livechat-manager') || RocketChat.authz.hasRole(user._id, 'livechat-agent')) { - RocketChat.Livechat.notifyAgentStatusChanged(user._id, status); + Livechat.notifyAgentStatusChanged(user._id, status); } }); diff --git a/packages/rocketchat-livechat/server/api/lib/livechat.js b/packages/rocketchat-livechat/server/api/lib/livechat.js index 8624fe8bd06..03b55517b42 100644 --- a/packages/rocketchat-livechat/server/api/lib/livechat.js +++ b/packages/rocketchat-livechat/server/api/lib/livechat.js @@ -4,6 +4,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import { LivechatDepartment, LivechatTrigger } from '../../models'; import _ from 'underscore'; import LivechatVisitors from '../../models/LivechatVisitors'; +import { Livechat } from '../../lib/Livechat'; export function online() { return RocketChat.models.Users.findOnlineAgents().count() > 0; @@ -72,7 +73,7 @@ export function getRoom(guest, rid, roomInfo) { ts: new Date(), }; - return RocketChat.Livechat.getRoom(guest, message, roomInfo); + return Livechat.getRoom(guest, message, roomInfo); } export function findAgent(agentId) { @@ -80,7 +81,7 @@ export function findAgent(agentId) { } export function settings() { - const initSettings = RocketChat.Livechat.getInitSettings(); + const initSettings = Livechat.getInitSettings(); const triggers = findTriggers(); const departments = findDepartments(); const sound = `${ Meteor.absoluteUrl() }sounds/chime.mp3`; diff --git a/packages/rocketchat-livechat/server/api/v1/agent.js b/packages/rocketchat-livechat/server/api/v1/agent.js index d5f30d82d09..dd6f73c648f 100644 --- a/packages/rocketchat-livechat/server/api/v1/agent.js +++ b/packages/rocketchat-livechat/server/api/v1/agent.js @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import { findRoom, findGuest, findAgent, findOpenRoom } from '../lib/livechat'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/agent.info/:rid/:token', { get() { @@ -53,13 +53,13 @@ API.v1.addRoute('livechat/agent.next/:token', { let { department } = this.queryParams; if (!department) { - const requireDeparment = RocketChat.Livechat.getRequiredDepartment(); + const requireDeparment = Livechat.getRequiredDepartment(); if (requireDeparment) { department = requireDeparment._id; } } - const agentData = RocketChat.Livechat.getNextAgent(department); + const agentData = Livechat.getNextAgent(department); if (!agentData) { throw new Meteor.Error('agent-not-found'); } diff --git a/packages/rocketchat-livechat/server/api/v1/customField.js b/packages/rocketchat-livechat/server/api/v1/customField.js index e2818fa2f46..39832d2ab76 100644 --- a/packages/rocketchat-livechat/server/api/v1/customField.js +++ b/packages/rocketchat-livechat/server/api/v1/customField.js @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import { findGuest } from '../lib/livechat'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/custom.field', { post() { @@ -21,7 +21,7 @@ API.v1.addRoute('livechat/custom.field', { throw new Meteor.Error('invalid-token'); } - if (!RocketChat.Livechat.setCustomFields({ token, key, value, overwrite })) { + if (!Livechat.setCustomFields({ token, key, value, overwrite })) { return API.v1.failure(); } @@ -53,7 +53,7 @@ API.v1.addRoute('livechat/custom.fields', { const fields = this.bodyParams.customFields.map((customField) => { const data = Object.assign({ token }, customField); - if (!RocketChat.Livechat.setCustomFields(data)) { + if (!Livechat.setCustomFields(data)) { return API.v1.failure(); } diff --git a/packages/rocketchat-livechat/server/api/v1/message.js b/packages/rocketchat-livechat/server/api/v1/message.js index 8abdaa6b761..a988bbb9d4b 100644 --- a/packages/rocketchat-livechat/server/api/v1/message.js +++ b/packages/rocketchat-livechat/server/api/v1/message.js @@ -5,6 +5,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import LivechatVisitors from '../../../server/models/LivechatVisitors'; import { findGuest, findRoom } from '../lib/livechat'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/message', { post() { @@ -45,7 +46,7 @@ API.v1.addRoute('livechat/message', { agent, }; - const result = RocketChat.Livechat.sendMessage(sendMessage); + const result = Livechat.sendMessage(sendMessage); if (result) { const message = { _id: result._id, rid: result.rid, msg: result.msg, u: result.u, ts: result.ts }; return API.v1.success({ message }); @@ -91,7 +92,7 @@ API.v1.addRoute('livechat/message/:_id', { const message = { _id: msg._id, msg: this.bodyParams.msg }; - const result = RocketChat.Livechat.updateMessage({ guest, message }); + const result = Livechat.updateMessage({ guest, message }); if (result) { const data = RocketChat.models.Messages.findOneById(_id); return API.v1.success({ @@ -133,7 +134,7 @@ API.v1.addRoute('livechat/message/:_id', { throw new Meteor.Error('invalid-message'); } - const result = RocketChat.Livechat.deleteMessage({ guest, message }); + const result = Livechat.deleteMessage({ guest, message }); if (result) { return API.v1.success({ message: { @@ -232,7 +233,7 @@ API.v1.addRoute('livechat/messages', { authRequired: true }, { } } else { rid = Random.id(); - const visitorId = RocketChat.Livechat.registerGuest(this.bodyParams.visitor); + const visitorId = Livechat.registerGuest(this.bodyParams.visitor); visitor = LivechatVisitors.findOneById(visitorId); } @@ -246,7 +247,7 @@ API.v1.addRoute('livechat/messages', { authRequired: true }, { msg: message.msg, }, }; - const sentMessage = RocketChat.Livechat.sendMessage(sendMessage); + const sentMessage = Livechat.sendMessage(sendMessage); return { username: sentMessage.u.username, msg: sentMessage.msg, diff --git a/packages/rocketchat-livechat/server/api/v1/offlineMessage.js b/packages/rocketchat-livechat/server/api/v1/offlineMessage.js index 338573084eb..1adc871f349 100644 --- a/packages/rocketchat-livechat/server/api/v1/offlineMessage.js +++ b/packages/rocketchat-livechat/server/api/v1/offlineMessage.js @@ -1,7 +1,7 @@ import { check } from 'meteor/check'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/offline.message', { post() { @@ -13,7 +13,7 @@ API.v1.addRoute('livechat/offline.message', { }); const { name, email, message } = this.bodyParams; - if (!RocketChat.Livechat.sendOfflineMessage({ name, email, message })) { + if (!Livechat.sendOfflineMessage({ name, email, message })) { return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_offline_message') }); } diff --git a/packages/rocketchat-livechat/server/api/v1/pageVisited.js b/packages/rocketchat-livechat/server/api/v1/pageVisited.js index 1a0fc1098b6..da7717e6f7e 100644 --- a/packages/rocketchat-livechat/server/api/v1/pageVisited.js +++ b/packages/rocketchat-livechat/server/api/v1/pageVisited.js @@ -1,9 +1,9 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import _ from 'underscore'; import { findGuest, findRoom } from '../lib/livechat'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/page.visited', { post() { @@ -32,7 +32,7 @@ API.v1.addRoute('livechat/page.visited', { throw new Meteor.Error('invalid-room'); } - const obj = RocketChat.Livechat.savePageHistory(token, rid, pageInfo); + const obj = Livechat.savePageHistory(token, rid, pageInfo); if (obj) { const page = _.pick(obj, 'msg', 'navigation'); return API.v1.success({ page }); diff --git a/packages/rocketchat-livechat/server/api/v1/room.js b/packages/rocketchat-livechat/server/api/v1/room.js index b052aca96e8..3a6161222c6 100644 --- a/packages/rocketchat-livechat/server/api/v1/room.js +++ b/packages/rocketchat-livechat/server/api/v1/room.js @@ -5,6 +5,7 @@ import { TAPi18n } from 'meteor/tap:i18n'; import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; import { findGuest, findRoom, getRoom, settings } from '../lib/livechat'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/room', { get() { @@ -57,7 +58,7 @@ API.v1.addRoute('livechat/room.close', { const language = RocketChat.settings.get('Language') || 'en'; const comment = TAPi18n.__('Closed_by_visitor', { lng: language }); - if (!RocketChat.Livechat.closeRoom({ visitor, room, comment })) { + if (!Livechat.closeRoom({ visitor, room, comment })) { return API.v1.failure(); } @@ -92,7 +93,7 @@ API.v1.addRoute('livechat/room.transfer', { // update visited page history to not expire RocketChat.models.Messages.keepHistoryForToken(token); - if (!RocketChat.Livechat.transfer(room, guest, { roomId: rid, departmentId: department })) { + if (!Livechat.transfer(room, guest, { roomId: rid, departmentId: department })) { return API.v1.failure(); } diff --git a/packages/rocketchat-livechat/server/api/v1/transcript.js b/packages/rocketchat-livechat/server/api/v1/transcript.js index efcf64e48bb..9666993cea2 100644 --- a/packages/rocketchat-livechat/server/api/v1/transcript.js +++ b/packages/rocketchat-livechat/server/api/v1/transcript.js @@ -1,7 +1,7 @@ import { check } from 'meteor/check'; import { TAPi18n } from 'meteor/tap:i18n'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { API } from 'meteor/rocketchat:api'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/transcript', { post() { @@ -13,7 +13,7 @@ API.v1.addRoute('livechat/transcript', { }); const { token, rid, email } = this.bodyParams; - if (!RocketChat.Livechat.sendTranscript({ token, rid, email })) { + if (!Livechat.sendTranscript({ token, rid, email })) { return API.v1.failure({ message: TAPi18n.__('Error_sending_livechat_transcript') }); } diff --git a/packages/rocketchat-livechat/server/api/v1/visitor.js b/packages/rocketchat-livechat/server/api/v1/visitor.js index aa7c69541dd..d0c3b08fc47 100644 --- a/packages/rocketchat-livechat/server/api/v1/visitor.js +++ b/packages/rocketchat-livechat/server/api/v1/visitor.js @@ -5,6 +5,7 @@ import { API } from 'meteor/rocketchat:api'; import LivechatVisitors from '../../../server/models/LivechatVisitors'; import { findGuest } from '../lib/livechat'; import { LivechatCustomField } from '../../models'; +import { Livechat } from '../../lib/Livechat'; API.v1.addRoute('livechat/visitor', { post() { @@ -34,13 +35,13 @@ API.v1.addRoute('livechat/visitor', { guest.phone = { number: this.bodyParams.visitor.phone }; } - const visitorId = RocketChat.Livechat.registerGuest(guest); + const visitorId = Livechat.registerGuest(guest); let visitor = LivechatVisitors.getVisitorByToken(token); // If it's updating an existing visitor, it must also update the roomInfo const cursor = RocketChat.models.Rooms.findOpenByVisitorToken(token); cursor.forEach((room) => { - RocketChat.Livechat.saveRoomInfo(room, visitor); + Livechat.saveRoomInfo(room, visitor); }); if (customFields && customFields instanceof Array) { @@ -89,7 +90,7 @@ API.v1.addRoute('livechat/visitor/:token', { } const { _id } = visitor; - const result = RocketChat.Livechat.removeGuest(_id); + const result = Livechat.removeGuest(_id); if (result) { return API.v1.success({ visitor: { @@ -141,7 +142,7 @@ API.v1.addRoute('livechat/visitor.status', { throw new Meteor.Error('invalid-token'); } - RocketChat.Livechat.notifyGuestStatusChanged(token, status); + Livechat.notifyGuestStatusChanged(token, status); return API.v1.success({ token, status }); } catch (e) { diff --git a/packages/rocketchat-livechat/server/hooks/RDStation.js b/packages/rocketchat-livechat/server/hooks/RDStation.js index a078959407c..5e04f5e5a8b 100644 --- a/packages/rocketchat-livechat/server/hooks/RDStation.js +++ b/packages/rocketchat-livechat/server/hooks/RDStation.js @@ -1,12 +1,13 @@ import { HTTP } from 'meteor/http'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; function sendToRDStation(room) { if (!RocketChat.settings.get('Livechat_RDStation_Token')) { return room; } - const livechatData = RocketChat.Livechat.getLivechatRoomGuestInfo(room); + const livechatData = Livechat.getLivechatRoomGuestInfo(room); if (!livechatData.visitor.email) { return room; diff --git a/packages/rocketchat-livechat/server/hooks/offlineMessage.js b/packages/rocketchat-livechat/server/hooks/offlineMessage.js index 93474d1aac8..31a916e13ae 100644 --- a/packages/rocketchat-livechat/server/hooks/offlineMessage.js +++ b/packages/rocketchat-livechat/server/hooks/offlineMessage.js @@ -1,4 +1,5 @@ import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; RocketChat.callbacks.add('livechat.offlineMessage', (data) => { if (!RocketChat.settings.get('Livechat_webhook_on_offline_msg')) { @@ -15,5 +16,5 @@ RocketChat.callbacks.add('livechat.offlineMessage', (data) => { message: data.message, }; - RocketChat.Livechat.sendRequest(postData); + Livechat.sendRequest(postData); }, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-email-offline-message'); diff --git a/packages/rocketchat-livechat/server/hooks/sendToCRM.js b/packages/rocketchat-livechat/server/hooks/sendToCRM.js index 8ec36034f8c..301b61988ea 100644 --- a/packages/rocketchat-livechat/server/hooks/sendToCRM.js +++ b/packages/rocketchat-livechat/server/hooks/sendToCRM.js @@ -1,4 +1,5 @@ import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; const msgNavType = 'livechat_navigation_history'; @@ -19,7 +20,7 @@ function sendToCRM(type, room, includeMessages = true) { return room; } - const postData = RocketChat.Livechat.getLivechatRoomGuestInfo(room); + const postData = Livechat.getLivechatRoomGuestInfo(room); postData.type = type; @@ -57,7 +58,7 @@ function sendToCRM(type, room, includeMessages = true) { }); } - const response = RocketChat.Livechat.sendRequest(postData); + const response = Livechat.sendRequest(postData); if (response && response.data && response.data.data) { RocketChat.models.Rooms.saveCRMDataByRoomId(room._id, response.data.data); diff --git a/packages/rocketchat-livechat/server/index.js b/packages/rocketchat-livechat/server/index.js index d46385d3252..74b654b8c83 100644 --- a/packages/rocketchat-livechat/server/index.js +++ b/packages/rocketchat-livechat/server/index.js @@ -66,7 +66,7 @@ import './models/LivechatPageVisited'; import './models/LivechatTrigger'; import '../lib/LivechatInquiry'; import './models/LivechatOfficeHour'; -import './lib/Livechat'; +export { Livechat } from './lib/Livechat'; import './lib/Analytics'; import './lib/QueueMethods'; import './lib/OfficeClock'; diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 9d77d592955..c8f3522de3e 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -17,7 +17,7 @@ import { LivechatInquiry } from '../../lib/LivechatInquiry'; import LivechatVisitors from '../models/LivechatVisitors'; import { Analytics } from './Analytics'; -RocketChat.Livechat = { +export const Livechat = { Analytics, historyMonitorType: 'url', @@ -414,7 +414,7 @@ RocketChat.Livechat = { }, savePageHistory(token, roomId, pageInfo) { - if (pageInfo.change === RocketChat.Livechat.historyMonitorType) { + if (pageInfo.change === Livechat.historyMonitorType) { const user = RocketChat.models.Users.findOneById('rocket.cat'); @@ -455,9 +455,9 @@ RocketChat.Livechat = { const { _id: agentId, username } = user; agent = Object.assign({}, { agentId, username }); } else if (RocketChat.settings.get('Livechat_Routing_Method') !== 'Guest_Pool') { - agent = RocketChat.Livechat.getNextAgent(transferData.departmentId); + agent = Livechat.getNextAgent(transferData.departmentId); } else { - return RocketChat.Livechat.returnRoomAsInquiry(room._id, transferData.departmentId); + return Livechat.returnRoomAsInquiry(room._id, transferData.departmentId); } const { servedBy } = room; @@ -502,7 +502,7 @@ RocketChat.Livechat = { this.setDepartmentForGuest(guestData); const data = RocketChat.models.Users.getAgentInfo(agent.agentId); - RocketChat.Livechat.stream.emit(room._id, { + Livechat.stream.emit(room._id, { type: 'agentData', data, }); @@ -531,10 +531,10 @@ RocketChat.Livechat = { const agentIds = []; // get the agents of the department if (departmentId) { - let agents = RocketChat.Livechat.getOnlineAgents(departmentId); + let agents = Livechat.getOnlineAgents(departmentId); if (agents.count() === 0 && RocketChat.settings.get('Livechat_guest_pool_with_no_agents')) { - agents = RocketChat.Livechat.getAgents(departmentId); + agents = Livechat.getAgents(departmentId); } if (agents.count() === 0) { @@ -571,7 +571,7 @@ RocketChat.Livechat = { if (openInq) { RocketChat.models.Messages.createUserLeaveWithRoomIdAndUser(rid, { _id: room.servedBy._id, username: room.servedBy.username }); - RocketChat.Livechat.stream.emit(rid, { + Livechat.stream.emit(rid, { type: 'agentData', data: null, }); @@ -590,13 +590,13 @@ RocketChat.Livechat = { }; return HTTP.post(RocketChat.settings.get('Livechat_webhookUrl'), options); } catch (e) { - RocketChat.Livechat.logger.webhook.error(`Response error on ${ trying } try ->`, e); + Livechat.logger.webhook.error(`Response error on ${ trying } try ->`, e); // try 10 times after 10 seconds each if (trying < 10) { - RocketChat.Livechat.logger.webhook.warn('Will try again in 10 seconds ...'); + Livechat.logger.webhook.warn('Will try again in 10 seconds ...'); trying++; setTimeout(Meteor.bindEnvironment(() => { - RocketChat.Livechat.sendRequest(postData, callback, trying); + Livechat.sendRequest(postData, callback, trying); }), 10000); } } @@ -919,7 +919,7 @@ RocketChat.Livechat = { notifyAgentStatusChanged(userId, status) { RocketChat.models.Rooms.findOpenByAgent(userId).forEach((room) => { - RocketChat.Livechat.stream.emit(room._id, { + Livechat.stream.emit(room._id, { type: 'agentStatus', status, }); @@ -927,9 +927,9 @@ RocketChat.Livechat = { }, }; -RocketChat.Livechat.stream = new Meteor.Streamer('livechat-room'); +Livechat.stream = new Meteor.Streamer('livechat-room'); -RocketChat.Livechat.stream.allowRead((roomId, extraData) => { +Livechat.stream.allowRead((roomId, extraData) => { const room = RocketChat.models.Rooms.findOneById(roomId); if (!room) { @@ -944,5 +944,5 @@ RocketChat.Livechat.stream.allowRead((roomId, extraData) => { }); RocketChat.settings.get('Livechat_history_monitor_type', (key, value) => { - RocketChat.Livechat.historyMonitorType = value; + Livechat.historyMonitorType = value; }); diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index 9bae4280dcf..bcea885b482 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -4,6 +4,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import _ from 'underscore'; import { sendNotification } from 'meteor/rocketchat:lib'; import { LivechatInquiry } from '../../lib/LivechatInquiry'; +import { Livechat } from './Livechat'; RocketChat.QueueMethods = { /* Least Amount Queuing method: @@ -13,7 +14,7 @@ RocketChat.QueueMethods = { */ 'Least_Amount'(guest, message, roomInfo, agent) { if (!agent) { - agent = RocketChat.Livechat.getNextAgent(guest.department); + agent = Livechat.getNextAgent(guest.department); if (!agent) { throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); } @@ -72,7 +73,7 @@ RocketChat.QueueMethods = { RocketChat.models.Subscriptions.insert(subscriptionData); - RocketChat.Livechat.stream.emit(room._id, { + Livechat.stream.emit(room._id, { type: 'agentData', data: RocketChat.models.Users.getAgentInfo(agent.agentId), }); @@ -89,10 +90,10 @@ RocketChat.QueueMethods = { * only the client until paired with an agent */ 'Guest_Pool'(guest, message, roomInfo) { - let agents = RocketChat.Livechat.getOnlineAgents(guest.department); + let agents = Livechat.getOnlineAgents(guest.department); if (agents.count() === 0 && RocketChat.settings.get('Livechat_guest_pool_with_no_agents')) { - agents = RocketChat.Livechat.getAgents(guest.department); + agents = Livechat.getAgents(guest.department); } if (agents.count() === 0) { diff --git a/packages/rocketchat-livechat/server/methods/addAgent.js b/packages/rocketchat-livechat/server/methods/addAgent.js index d9d444c96ef..b9a7cc01baa 100644 --- a/packages/rocketchat-livechat/server/methods/addAgent.js +++ b/packages/rocketchat-livechat/server/methods/addAgent.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:addAgent'(username) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:addAgent' }); } - return RocketChat.Livechat.addAgent(username); + return Livechat.addAgent(username); }, }); diff --git a/packages/rocketchat-livechat/server/methods/addManager.js b/packages/rocketchat-livechat/server/methods/addManager.js index 14a2fb0ab75..a83ce7bfa3d 100644 --- a/packages/rocketchat-livechat/server/methods/addManager.js +++ b/packages/rocketchat-livechat/server/methods/addManager.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:addManager'(username) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:addManager' }); } - return RocketChat.Livechat.addManager(username); + return Livechat.addManager(username); }, }); diff --git a/packages/rocketchat-livechat/server/methods/closeByVisitor.js b/packages/rocketchat-livechat/server/methods/closeByVisitor.js index 3d2541e43f9..5acee57cb3f 100644 --- a/packages/rocketchat-livechat/server/methods/closeByVisitor.js +++ b/packages/rocketchat-livechat/server/methods/closeByVisitor.js @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { TAPi18n } from 'meteor/tap:i18n'; import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:closeByVisitor'({ roomId, token }) { @@ -9,7 +10,7 @@ Meteor.methods({ const language = (visitor && visitor.language) || RocketChat.settings.get('Language') || 'en'; - return RocketChat.Livechat.closeRoom({ + return Livechat.closeRoom({ visitor, room: RocketChat.models.Rooms.findOneOpenByRoomIdAndVisitorToken(roomId, token), comment: TAPi18n.__('Closed_by_visitor', { lng: language }), diff --git a/packages/rocketchat-livechat/server/methods/closeRoom.js b/packages/rocketchat-livechat/server/methods/closeRoom.js index 5d983c5b1b7..5f9b558dc78 100644 --- a/packages/rocketchat-livechat/server/methods/closeRoom.js +++ b/packages/rocketchat-livechat/server/methods/closeRoom.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:closeRoom'(roomId, comment) { @@ -15,7 +16,7 @@ Meteor.methods({ throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeRoom' }); } - return RocketChat.Livechat.closeRoom({ + return Livechat.closeRoom({ user, room: RocketChat.models.Rooms.findOneById(roomId), comment, diff --git a/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js b/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js index 2906fe1e7e4..3a9ef314253 100644 --- a/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js +++ b/packages/rocketchat-livechat/server/methods/getAgentOverviewData.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:getAgentOverviewData'(options) { @@ -14,6 +15,6 @@ Meteor.methods({ return; } - return RocketChat.Livechat.Analytics.getAgentOverviewData(options); + return Livechat.Analytics.getAgentOverviewData(options); }, }); diff --git a/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js b/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js index 4ba3a38372d..13d42697145 100644 --- a/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js +++ b/packages/rocketchat-livechat/server/methods/getAnalyticsChartData.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:getAnalyticsChartData'(options) { @@ -14,6 +15,6 @@ Meteor.methods({ return; } - return RocketChat.Livechat.Analytics.getAnalyticsChartData(options); + return Livechat.Analytics.getAnalyticsChartData(options); }, }); diff --git a/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js b/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js index f945084bb51..aacae224b0c 100644 --- a/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js +++ b/packages/rocketchat-livechat/server/methods/getAnalyticsOverviewData.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:getAnalyticsOverviewData'(options) { @@ -14,6 +15,6 @@ Meteor.methods({ return; } - return RocketChat.Livechat.Analytics.getAnalyticsOverviewData(options); + return Livechat.Analytics.getAnalyticsOverviewData(options); }, }); diff --git a/packages/rocketchat-livechat/server/methods/getInitialData.js b/packages/rocketchat-livechat/server/methods/getInitialData.js index a32797ea1b5..5112786cf2f 100644 --- a/packages/rocketchat-livechat/server/methods/getInitialData.js +++ b/packages/rocketchat-livechat/server/methods/getInitialData.js @@ -3,6 +3,7 @@ import { RocketChat } from 'meteor/rocketchat:lib'; import _ from 'underscore'; import { LivechatDepartment, LivechatTrigger } from '../models'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:getInitialData'(visitorToken, departmentId) { @@ -60,7 +61,7 @@ Meteor.methods({ info.visitor = visitor; } - const initSettings = RocketChat.Livechat.getInitSettings(); + const initSettings = Livechat.getInitSettings(); info.title = initSettings.Livechat_title; info.color = initSettings.Livechat_title_color; diff --git a/packages/rocketchat-livechat/server/methods/getNextAgent.js b/packages/rocketchat-livechat/server/methods/getNextAgent.js index 52b617d8840..5e6792c41ac 100644 --- a/packages/rocketchat-livechat/server/methods/getNextAgent.js +++ b/packages/rocketchat-livechat/server/methods/getNextAgent.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:getNextAgent'({ token, department }) { @@ -13,13 +14,13 @@ Meteor.methods({ } if (!department) { - const requireDeparment = RocketChat.Livechat.getRequiredDepartment(); + const requireDeparment = Livechat.getRequiredDepartment(); if (requireDeparment) { department = requireDeparment._id; } } - const agent = RocketChat.Livechat.getNextAgent(department); + const agent = Livechat.getNextAgent(department); if (!agent) { return; } diff --git a/packages/rocketchat-livechat/server/methods/pageVisited.js b/packages/rocketchat-livechat/server/methods/pageVisited.js index 11f262dcd8e..114108f87fc 100644 --- a/packages/rocketchat-livechat/server/methods/pageVisited.js +++ b/packages/rocketchat-livechat/server/methods/pageVisited.js @@ -1,8 +1,8 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:pageVisited'(token, room, pageInfo) { - RocketChat.Livechat.savePageHistory(token, room, pageInfo); + Livechat.savePageHistory(token, room, pageInfo); }, }); diff --git a/packages/rocketchat-livechat/server/methods/registerGuest.js b/packages/rocketchat-livechat/server/methods/registerGuest.js index 11bc8d87a46..a743fbad85f 100644 --- a/packages/rocketchat-livechat/server/methods/registerGuest.js +++ b/packages/rocketchat-livechat/server/methods/registerGuest.js @@ -1,10 +1,11 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:registerGuest'({ token, name, email, department, customFields } = {}) { - const userId = RocketChat.Livechat.registerGuest.call(this, { + const userId = Livechat.registerGuest.call(this, { token, name, email, @@ -27,7 +28,7 @@ Meteor.methods({ // If it's updating an existing visitor, it must also update the roomInfo const cursor = RocketChat.models.Rooms.findOpenByVisitorToken(token); cursor.forEach((room) => { - RocketChat.Livechat.saveRoomInfo(room, visitor); + Livechat.saveRoomInfo(room, visitor); }); if (customFields && customFields instanceof Array) { diff --git a/packages/rocketchat-livechat/server/methods/removeAgent.js b/packages/rocketchat-livechat/server/methods/removeAgent.js index 2a95649e1a3..a1b28a619c6 100644 --- a/packages/rocketchat-livechat/server/methods/removeAgent.js +++ b/packages/rocketchat-livechat/server/methods/removeAgent.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:removeAgent'(username) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeAgent' }); } - return RocketChat.Livechat.removeAgent(username); + return Livechat.removeAgent(username); }, }); diff --git a/packages/rocketchat-livechat/server/methods/removeDepartment.js b/packages/rocketchat-livechat/server/methods/removeDepartment.js index df211c3dc7f..40ad21fa293 100644 --- a/packages/rocketchat-livechat/server/methods/removeDepartment.js +++ b/packages/rocketchat-livechat/server/methods/removeDepartment.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:removeDepartment'(_id) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeDepartment' }); } - return RocketChat.Livechat.removeDepartment(_id); + return Livechat.removeDepartment(_id); }, }); diff --git a/packages/rocketchat-livechat/server/methods/removeManager.js b/packages/rocketchat-livechat/server/methods/removeManager.js index 411ce4a0b72..549f50b8555 100644 --- a/packages/rocketchat-livechat/server/methods/removeManager.js +++ b/packages/rocketchat-livechat/server/methods/removeManager.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:removeManager'(username) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeManager' }); } - return RocketChat.Livechat.removeManager(username); + return Livechat.removeManager(username); }, }); diff --git a/packages/rocketchat-livechat/server/methods/returnAsInquiry.js b/packages/rocketchat-livechat/server/methods/returnAsInquiry.js index af3f50d96d9..59c127fea28 100644 --- a/packages/rocketchat-livechat/server/methods/returnAsInquiry.js +++ b/packages/rocketchat-livechat/server/methods/returnAsInquiry.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:returnAsInquiry'(rid, departmentId) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveDepartment' }); } - return RocketChat.Livechat.returnRoomAsInquiry(rid, departmentId); + return Livechat.returnRoomAsInquiry(rid, departmentId); }, }); diff --git a/packages/rocketchat-livechat/server/methods/saveDepartment.js b/packages/rocketchat-livechat/server/methods/saveDepartment.js index b54849bb5c1..ce400a0e456 100644 --- a/packages/rocketchat-livechat/server/methods/saveDepartment.js +++ b/packages/rocketchat-livechat/server/methods/saveDepartment.js @@ -1,5 +1,6 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:saveDepartment'(_id, departmentData, departmentAgents) { @@ -7,6 +8,6 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveDepartment' }); } - return RocketChat.Livechat.saveDepartment(_id, departmentData, departmentAgents); + return Livechat.saveDepartment(_id, departmentData, departmentAgents); }, }); diff --git a/packages/rocketchat-livechat/server/methods/saveInfo.js b/packages/rocketchat-livechat/server/methods/saveInfo.js index 663a8abf56c..6bfb2779441 100644 --- a/packages/rocketchat-livechat/server/methods/saveInfo.js +++ b/packages/rocketchat-livechat/server/methods/saveInfo.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:saveInfo'(guestData, roomData) { @@ -31,7 +32,7 @@ Meteor.methods({ throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveInfo' }); } - const ret = RocketChat.Livechat.saveGuest(guestData) && RocketChat.Livechat.saveRoomInfo(roomData, guestData); + const ret = Livechat.saveGuest(guestData) && Livechat.saveRoomInfo(roomData, guestData); Meteor.defer(() => { RocketChat.callbacks.run('livechat.saveInfo', RocketChat.models.Rooms.findOneById(roomData._id)); diff --git a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js index ec4d05abec3..cfd737709d0 100644 --- a/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js +++ b/packages/rocketchat-livechat/server/methods/sendMessageLivechat.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ sendMessageLivechat({ token, _id, rid, msg, attachments }, agent) { @@ -28,7 +28,7 @@ Meteor.methods({ throw new Meteor.Error('invalid-token'); } - return RocketChat.Livechat.sendMessage({ + return Livechat.sendMessage({ guest, message: { _id, diff --git a/packages/rocketchat-livechat/server/methods/sendOfflineMessage.js b/packages/rocketchat-livechat/server/methods/sendOfflineMessage.js index 2ace9354065..d9dde597fed 100644 --- a/packages/rocketchat-livechat/server/methods/sendOfflineMessage.js +++ b/packages/rocketchat-livechat/server/methods/sendOfflineMessage.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:sendOfflineMessage'(data) { @@ -11,7 +11,7 @@ Meteor.methods({ message: String, }); - return RocketChat.Livechat.sendOfflineMessage(data); + return Livechat.sendOfflineMessage(data); }, }); diff --git a/packages/rocketchat-livechat/server/methods/sendTranscript.js b/packages/rocketchat-livechat/server/methods/sendTranscript.js index f6b2eb05f53..2ba0aa49343 100644 --- a/packages/rocketchat-livechat/server/methods/sendTranscript.js +++ b/packages/rocketchat-livechat/server/methods/sendTranscript.js @@ -1,14 +1,14 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:sendTranscript'(token, rid, email) { check(rid, String); check(email, String); - return RocketChat.Livechat.sendTranscript({ token, rid, email }); + return Livechat.sendTranscript({ token, rid, email }); }, }); diff --git a/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js b/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js index 0fdea7260e0..551a2f29bc5 100644 --- a/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js +++ b/packages/rocketchat-livechat/server/methods/setDepartmentForVisitor.js @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:setDepartmentForVisitor'({ roomId, visitorToken, departmentId } = {}) { @@ -24,6 +25,6 @@ Meteor.methods({ departmentId, }; - return RocketChat.Livechat.transfer(room, visitor, transferData); + return Livechat.transfer(room, visitor, transferData); }, }); diff --git a/packages/rocketchat-livechat/server/methods/startFileUploadRoom.js b/packages/rocketchat-livechat/server/methods/startFileUploadRoom.js index 9c7322242fb..ec55ac0a803 100644 --- a/packages/rocketchat-livechat/server/methods/startFileUploadRoom.js +++ b/packages/rocketchat-livechat/server/methods/startFileUploadRoom.js @@ -1,7 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; -import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:startFileUploadRoom'(roomId, token) { @@ -15,6 +15,6 @@ Meteor.methods({ token: guest.token, }; - return RocketChat.Livechat.getRoom(guest, message); + return Livechat.getRoom(guest, message); }, }); diff --git a/packages/rocketchat-livechat/server/methods/startVideoCall.js b/packages/rocketchat-livechat/server/methods/startVideoCall.js index 12da5cdd76d..b9a384f3f83 100644 --- a/packages/rocketchat-livechat/server/methods/startVideoCall.js +++ b/packages/rocketchat-livechat/server/methods/startVideoCall.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; import { RocketChat } from 'meteor/rocketchat:lib'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:startVideoCall'(roomId) { @@ -17,7 +18,7 @@ Meteor.methods({ ts: new Date(), }; - const { room } = RocketChat.Livechat.getRoom(guest, message, { jitsiTimeout: new Date(Date.now() + 3600 * 1000) }); + const { room } = Livechat.getRoom(guest, message, { jitsiTimeout: new Date(Date.now() + 3600 * 1000) }); message.rid = room._id; RocketChat.models.Messages.createWithTypeRoomIdMessageAndUser('livechat_video_call', room._id, '', guest, { diff --git a/packages/rocketchat-livechat/server/methods/takeInquiry.js b/packages/rocketchat-livechat/server/methods/takeInquiry.js index 9eb2177019b..49cbf2f888f 100644 --- a/packages/rocketchat-livechat/server/methods/takeInquiry.js +++ b/packages/rocketchat-livechat/server/methods/takeInquiry.js @@ -1,6 +1,7 @@ import { Meteor } from 'meteor/meteor'; import { RocketChat } from 'meteor/rocketchat:lib'; import { LivechatInquiry } from '../../lib/LivechatInquiry'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:takeInquiry'(inquiryId) { @@ -63,7 +64,7 @@ Meteor.methods({ // and inquiry being taken, message would not be switched off. RocketChat.models.Messages.createCommandWithRoomIdAndUser('connected', room._id, user); - RocketChat.Livechat.stream.emit(room._id, { + Livechat.stream.emit(room._id, { type: 'agentData', data: RocketChat.models.Users.getAgentInfo(agent.agentId), }); diff --git a/packages/rocketchat-livechat/server/methods/transfer.js b/packages/rocketchat-livechat/server/methods/transfer.js index d6a59b3ac24..bd101c13680 100644 --- a/packages/rocketchat-livechat/server/methods/transfer.js +++ b/packages/rocketchat-livechat/server/methods/transfer.js @@ -2,6 +2,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { RocketChat } from 'meteor/rocketchat:lib'; import LivechatVisitors from '../models/LivechatVisitors'; +import { Livechat } from '../lib/Livechat'; Meteor.methods({ 'livechat:transfer'(transferData) { @@ -27,6 +28,6 @@ Meteor.methods({ const guest = LivechatVisitors.findOneById(room.v && room.v._id); - return RocketChat.Livechat.transfer(room, guest, transferData); + return Livechat.transfer(room, guest, transferData); }, }); diff --git a/packages/rocketchat-livechat/server/visitorStatus.js b/packages/rocketchat-livechat/server/visitorStatus.js index 5d7efd2f79e..18775e7da01 100644 --- a/packages/rocketchat-livechat/server/visitorStatus.js +++ b/packages/rocketchat-livechat/server/visitorStatus.js @@ -1,11 +1,11 @@ import { Meteor } from 'meteor/meteor'; -import { RocketChat } from 'meteor/rocketchat:lib'; import { UserPresenceEvents } from 'meteor/konecty:user-presence'; +import { Livechat } from './lib/Livechat'; Meteor.startup(() => { UserPresenceEvents.on('setStatus', (session, status, metadata) => { if (metadata && metadata.visitor) { - RocketChat.Livechat.notifyGuestStatusChanged(metadata.visitor, status); + Livechat.notifyGuestStatusChanged(metadata.visitor, status); } }); });