diff --git a/packages/rocketchat-lib/i18n/en.i18n.json b/packages/rocketchat-lib/i18n/en.i18n.json index c10e790675e141827892526f2dc72989985562e7..cd747807f005301812c43d5be624f32b04c22277 100644 --- a/packages/rocketchat-lib/i18n/en.i18n.json +++ b/packages/rocketchat-lib/i18n/en.i18n.json @@ -6,6 +6,8 @@ "500" : "Internal Server Error", "__username__is_no_longer__role__defined_by__user_by_" : "__username__ is no longer __role__ by __user_by__", "__username__was_set__role__by__user_by_" : "__username__ was set __role__ by __user_by__", + "Accept_with_no_online_agents" : "Accept with no online agents", + "Accept_incoming_livechat_requests_even_if_there_are_no_online_agents" : "Accept incoming livechat requests even if there are no online agents", "Access_not_authorized" : "Access not authorized", "Access_Token_URL" : "Access Token URL", "Accessing_permissions" : "Accessing permissions", diff --git a/packages/rocketchat-lib/i18n/pt.i18n.json b/packages/rocketchat-lib/i18n/pt.i18n.json index 90b4328676592d66be0558c4d4b573be4318072f..6ff947dc30c524f98f078fe69f46a2463eebec56 100644 --- a/packages/rocketchat-lib/i18n/pt.i18n.json +++ b/packages/rocketchat-lib/i18n/pt.i18n.json @@ -6,6 +6,8 @@ "500" : "Erro Interno do Servidor", "__username__is_no_longer__role__defined_by__user_by_" : "__username__ não pertence mais à __role__, por __user_by__", "__username__was_set__role__by__user_by_" : "__username__ foi definido como __role__ por __user_by__", + "Accept_with_no_online_agents" : "Aceitar sem agentes online", + "Accept_incoming_livechat_requests_even_if_there_are_no_online_agents" : "Aceitar requisições de livechat mesmo se não houverem agentes online", "Access_not_authorized" : "Acesso não autorizado", "Access_Token_URL" : "URL do Token de Acesso", "Accessing_permissions" : "Acessando permissões", diff --git a/packages/rocketchat-livechat/config.js b/packages/rocketchat-livechat/config.js index d53d1029422454c51245253d811e1f60ea49afc9..01879dd9140626d91bf6226cdbea84c5faa85d1e 100644 --- a/packages/rocketchat-livechat/config.js +++ b/packages/rocketchat-livechat/config.js @@ -150,6 +150,14 @@ Meteor.startup(function() { ] }); + RocketChat.settings.add('Livechat_guest_pool_with_no_agents', false, { + type: 'boolean', + group: 'Livechat', + i18nLabel: 'Accept_with_no_online_agents', + i18nDescription: 'Accept_incoming_livechat_requests_even_if_there_are_no_online_agents', + enableQuery: { _id: 'Livechat_Routing_Method', value: 'Guest_Pool' } + }); + RocketChat.settings.add('Livechat_show_queue_list_link', false, { type: 'boolean', group: 'Livechat', diff --git a/packages/rocketchat-livechat/server/api.js b/packages/rocketchat-livechat/server/api.js index 59c1a04bd25b131e26627479e7fa625efb45b0ea..6e13ba0a86d3b8d76fd58b5968df13fb883490a8 100644 --- a/packages/rocketchat-livechat/server/api.js +++ b/packages/rocketchat-livechat/server/api.js @@ -49,25 +49,28 @@ Api.addRoute('sms-incoming/:service', { } sendMessage.message.msg = sms.body; - sendMessage.guest = visitor; - const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); + try { + const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); - Meteor.defer(() => { - if (sms.extra) { - if (sms.extra.fromCountry) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'country', sms.extra.fromCountry); - } - if (sms.extra.fromState) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'state', sms.extra.fromState); - } - if (sms.extra.fromCity) { - Meteor.call('livechat:setCustomField', sendMessage.message.token, 'city', sms.extra.fromCity); + Meteor.defer(() => { + if (sms.extra) { + if (sms.extra.fromCountry) { + Meteor.call('livechat:setCustomField', sendMessage.message.token, 'country', sms.extra.fromCountry); + } + if (sms.extra.fromState) { + Meteor.call('livechat:setCustomField', sendMessage.message.token, 'state', sms.extra.fromState); + } + if (sms.extra.fromCity) { + Meteor.call('livechat:setCustomField', sendMessage.message.token, 'city', sms.extra.fromCity); + } } - } - }); + }); - return message; + return message; + } catch (e) { + return SMSService.error.call(this, e); + } } }); diff --git a/packages/rocketchat-livechat/server/lib/Livechat.js b/packages/rocketchat-livechat/server/lib/Livechat.js index 7fb25c7bc6442bce836036041120b625021900b2..820da9473da9cf9bf5c535d1ec3005e36597207a 100644 --- a/packages/rocketchat-livechat/server/lib/Livechat.js +++ b/packages/rocketchat-livechat/server/lib/Livechat.js @@ -16,7 +16,14 @@ RocketChat.Livechat = { }, getAgents(department) { if (department) { - return RocketChat.models.LivechatDepartmentAgents.getForDepartment(department); + return RocketChat.models.LivechatDepartmentAgents.findByDepartmentId(department); + } else { + return RocketChat.models.Users.findAgents(); + } + }, + getOnlineAgents(department) { + if (department) { + return RocketChat.models.LivechatDepartmentAgents.getOnlineForDepartment(department); } else { return RocketChat.models.Users.findOnlineAgents(); } diff --git a/packages/rocketchat-livechat/server/lib/QueueMethods.js b/packages/rocketchat-livechat/server/lib/QueueMethods.js index 44a2969b6c4bcf5832371c734c4ac02b4700e3ba..35d44456c238ab0cb2412b4e09f86e7e964ae601 100644 --- a/packages/rocketchat-livechat/server/lib/QueueMethods.js +++ b/packages/rocketchat-livechat/server/lib/QueueMethods.js @@ -64,8 +64,13 @@ RocketChat.QueueMethods = { * only the client until paired with an agent */ 'Guest_Pool' : function(guest, message, roomInfo) { - const agents = RocketChat.Livechat.getAgents(guest.department); - if (!agents) { + let agents = RocketChat.Livechat.getOnlineAgents(guest.department); + + if (agents.count() === 0 && RocketChat.settings.get('Livechat_guest_pool_with_no_agents')) { + agents = RocketChat.Livechat.getAgents(guest.department); + } + + if (agents.count() === 0) { throw new Meteor.Error('no-agent-online', 'Sorry, no online agents'); } diff --git a/packages/rocketchat-livechat/server/models/LivechatDepartmentAgents.js b/packages/rocketchat-livechat/server/models/LivechatDepartmentAgents.js index 5d985fd682da304f29241680d938e707c40b7ca6..e9ebd44358a92535955db656323af8d8cefdd0e9 100644 --- a/packages/rocketchat-livechat/server/models/LivechatDepartmentAgents.js +++ b/packages/rocketchat-livechat/server/models/LivechatDepartmentAgents.js @@ -71,7 +71,7 @@ class LivechatDepartmentAgents extends RocketChat.models._Base { } } - getForDepartment(departmentId) { + getOnlineForDepartment(departmentId) { var agents = this.findByDepartmentId(departmentId).fetch(); if (agents.length === 0) { diff --git a/packages/rocketchat-livechat/server/models/Users.js b/packages/rocketchat-livechat/server/models/Users.js index 955fdab9095f493156911f5332cf2097639f43b8..f9cfbc3594a866e346ffcfdb4a4f602293f1c65e 100644 --- a/packages/rocketchat-livechat/server/models/Users.js +++ b/packages/rocketchat-livechat/server/models/Users.js @@ -27,6 +27,18 @@ RocketChat.models.Users.findOnlineAgents = function() { return this.find(query); }; +/** + * Gets all agents + * @return + */ +RocketChat.models.Users.findAgents = function() { + var query = { + roles: 'livechat-agent' + }; + + return this.find(query); +}; + /** * Find online users from a list * @param {array} userList - array of usernames diff --git a/packages/rocketchat-sms/services/twilio.js b/packages/rocketchat-sms/services/twilio.js index 6516384f2d1a3aaf537276f47cd537576b282492..b449b745268b2c95e1f1244be455347731616ffb 100644 --- a/packages/rocketchat-sms/services/twilio.js +++ b/packages/rocketchat-sms/services/twilio.js @@ -39,6 +39,18 @@ class Twilio { body: '<Response></Response>' }; } + error(error) { + let message = ''; + if (error.reason) { + message = `<Message>${error.reason}</Message>`; + } + return { + headers: { + 'Content-Type': 'text/xml' + }, + body: `<Response>${message}</Response>` + }; + } } RocketChat.SMS.registerService('twilio', Twilio);