1 var moment = require('moment');
2 var asteriskManager = null;
6 console.log('ACW Initialization...');
10 ACW.prototype.agentcomplete = function(evt) {
11 if (asteriskManager && asteriskManager.isConnected()) {
12 if (evt.interface === 'SIP/massimiliano.bungaro') {
13 asteriskManager.action({
15 interface: evt.interface,
17 reason: 'UNAVAILABLE BY ACW'
18 }, function(err, res) {
23 console.log('PAUSE ACW in all queue for the agent ' + evt.interface);
24 asteriskManager.action({
26 interface: evt.interface,
30 }, function(err, res) {
35 console.log('SINGLE PAUSE ACW in ' + evt.queue + ' for the agent ' + evt.interface);
36 findAndUpdateFlag(evt);
37 setTimeout(function() {
38 asteriskManager.action({
40 interface: evt.interface,
42 }, function(err, res) {
46 console.log('UNPAUSE ACW in all queue for the agent ' + evt.interface);
55 ACW.prototype.agentpause = function(evt) {
56 if ((evt.reason === 'ACW' || evt.reason === 'UNAVAILABLE BY ACW') && evt.paused === '1') {
60 // findAndUpdateTime(evt);
63 function findAndUpdateTime(evt) {
64 var agent = require('../../models').ReportAgent;
72 interface: evt.interface
75 .then(function(agents) {
76 if (agents.length > 0) {
77 var agent = agents[agents.length - 1]; // get last inserted agent
78 var diff = moment().diff(agent.agentcompleteAt, 'seconds'); // diff seconds now - completeAt
84 console.log('[acw] agent acw ' + res.membername + ' updated seconds ' + diff + ' ACW in queue ' + res.queue);
86 .catch(function(err) {
87 console.error('[acw] agent acw ' + err);
90 console.error(new Error('[acw] agent acw not found!'));
93 .catch(function(err) {
94 console.error('[acw] agent acw ' + err);
98 function findAndUpdateFlag(evt) {
100 var agent = require('../../models').ReportAgent;
106 uniqueid: evt.uniqueid,
107 destuniqueid: evt.destuniqueid
110 .then(function(agent) {
111 console.log('[acw] agent acw updated');
113 .catch(function(err) {
114 console.error('[acw] agent acw update error: ' + err);
118 module.exports = ACW;