Skip to content
Snippets Groups Projects
Commit 78f60dc7 authored by Gabriel Engel's avatar Gabriel Engel Committed by GitHub
Browse files

Merge pull request #3834 from RocketChat/livechat-guest-pool-with-no-online-agents

Add option to accept livechats even if no agents online
parents 11047917 f47ae430
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
......@@ -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",
......
......@@ -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',
......
......@@ -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);
}
}
});
......@@ -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();
}
......
......@@ -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');
}
......
......@@ -71,7 +71,7 @@ class LivechatDepartmentAgents extends RocketChat.models._Base {
}
}
getForDepartment(departmentId) {
getOnlineForDepartment(departmentId) {
var agents = this.findByDepartmentId(departmentId).fetch();
if (agents.length === 0) {
......
......@@ -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
......
......@@ -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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment