Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / services / ami / acw / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xe753=['Action','QueuePause','then','getAgent','voicePause','info','destlinkedid','savePause','acwTimeout','timer','stopAcw','lastPauseAt','format','YYYY-MM-DD\x20HH:mm:ss','uniqueid','updateAcw','update','catch','error','[%s][UPDATE][ERRORS:%s]','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','finally','message','saveUnpause','[%s][UPDATE][ACWTIME:%s]','[ACW][TIMERS]','[ACW][STOP]\x20%s','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','isUndefined','attended','linkedid','[%s][HANGUP:LINKEDID]','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','stringify','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','autopause','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s','exports','util','lodash','moment','../ami','acw','../rpc/user','voiceQueues','agents','timers','agentconnect','syncAgentConnect','hanguprequest','bind','syncHangup','agentringnoanswer','syncAgentRingNoAnswer','attendedtransfer','syncAttendedTransfer','blindtransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','prototype','startAcw','channels','interface','queue','ACW','mandatoryDisposition','mandatoryDispositionPause','name'];(function(_0xb6408d,_0x5add08){var _0x406b0d=function(_0x225b3e){while(--_0x225b3e){_0xb6408d['push'](_0xb6408d['shift']());}};_0x406b0d(++_0x5add08);}(_0xe753,0x13f));var _0x3e75=function(_0x1a8e9d,_0x34808a){_0x1a8e9d=_0x1a8e9d-0x0;var _0x5a9810=_0xe753[_0x1a8e9d];return _0x5a9810;};'use strict';var util=require(_0x3e75('0x0'));var _=require(_0x3e75('0x1'));var moment=require(_0x3e75('0x2'));var ami=require(_0x3e75('0x3'));var logger=require('../../../config/logger')(_0x3e75('0x4'));var RpcUser=require(_0x3e75('0x5'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x341739){this[_0x3e75('0x6')]=_0x341739['voiceQueues'];this[_0x3e75('0x7')]=_0x341739[_0x3e75('0x7')];this[_0x3e75('0x8')]=_0x341739[_0x3e75('0x8')];this['channels']={};ami['on'](_0x3e75('0x9'),this[_0x3e75('0xa')]['bind'](this));ami['on'](_0x3e75('0xb'),this['syncHangupRequest'][_0x3e75('0xc')](this));ami['on']('hangup',this[_0x3e75('0xd')]['bind'](this));ami['on'](_0x3e75('0xe'),this[_0x3e75('0xf')][_0x3e75('0xc')](this));ami['on'](_0x3e75('0x10'),this[_0x3e75('0x11')]['bind'](this));ami['on'](_0x3e75('0x12'),this[_0x3e75('0x13')][_0x3e75('0xc')](this));ami['on'](_0x3e75('0x14'),this[_0x3e75('0x15')]['bind'](this));}function getDiff(_0x4e55b2){var _0x381c99=moment()[_0x3e75('0x16')](0x0);var _0x44be26=moment(_0x4e55b2)[_0x3e75('0x16')](0x0);return _0x381c99[_0x3e75('0x17')](_0x44be26,'seconds');}Acw[_0x3e75('0x18')][_0x3e75('0x19')]=function(_0x45ca39){try{var _0xedf93b=this;var _0x4351a9=this[_0x3e75('0x1a')][_0x45ca39][_0x3e75('0x1b')];var _0x27c8ab=this[_0x3e75('0x1a')][_0x45ca39][_0x3e75('0x1c')];var _0x259a18=this[_0x3e75('0x6')][_0x27c8ab];var _0x2f1c62=![];var _0x8981d4=_0x3e75('0x1d');if(_0x259a18[_0x3e75('0x1e')]){if(_0x259a18[_0x3e75('0x1f')][_0x3e75('0x20')]){_0x2f1c62=!![];_0x8981d4=_0x259a18['mandatoryDispositionPause'][_0x3e75('0x20')];}}ami[_0x3e75('0x21')]({'action':_0x3e75('0x22'),'interface':_0x4351a9,'paused':!![],'reason':_0x8981d4})[_0x3e75('0x23')](function(_0x506b39){if(_0xedf93b[_0x3e75('0x7')][_0x4351a9]){return RpcUser[_0x3e75('0x24')](_0xedf93b[_0x3e75('0x7')][_0x4351a9]['id'])['then'](function(_0x344db2){if(_0x344db2&&!_0x344db2[_0x3e75('0x25')]){logger[_0x3e75('0x26')]('[%s][START][AGENT:%s][QUEUE:%s]',_0x45ca39,_0x4351a9,_0x27c8ab);var _0x1c4122=_0xedf93b['channels'][_0x45ca39]['attended']&&_0xedf93b[_0x3e75('0x1a')][_0x45ca39][_0x3e75('0x27')]?_0xedf93b[_0x3e75('0x1a')][_0x45ca39][_0x3e75('0x27')]:_0x45ca39;return RpcUser[_0x3e75('0x28')](_0xedf93b[_0x3e75('0x7')][_0x4351a9],_0x8981d4,_0x1c4122)[_0x3e75('0x23')](function(_0xb8ee23){if(!_0x2f1c62){_0xedf93b[_0x3e75('0x8')][_0x4351a9]={};logger[_0x3e75('0x26')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x45ca39,_0xedf93b['voiceQueues'][_0x27c8ab][_0x3e75('0x29')],_0x4351a9,_0x27c8ab);_0xedf93b['timers'][_0x4351a9][_0x3e75('0x2a')]=setTimeout(_0xedf93b[_0x3e75('0x2b')]['bind'](_0xedf93b,_0x4351a9),_0xedf93b[_0x3e75('0x6')][_0x27c8ab][_0x3e75('0x29')]*0x3e8);_0xedf93b[_0x3e75('0x8')][_0x4351a9][_0x3e75('0x2c')]=moment()[_0x3e75('0x2d')](_0x3e75('0x2e'));_0xedf93b[_0x3e75('0x8')][_0x4351a9][_0x3e75('0x2f')]=_0x45ca39;_0xedf93b['timers'][_0x4351a9]['queue']=_0x27c8ab;_0xedf93b[_0x3e75('0x8')][_0x4351a9][_0x3e75('0x30')]=function(){var _0x3b7fc5=getDiff(_0xedf93b['timers'][_0x4351a9][_0x3e75('0x2c')]);clearTimeout(_0xedf93b[_0x3e75('0x8')][_0x4351a9]['timer']);_0xedf93b['timers'][_0x4351a9][_0x3e75('0x2a')]=![];RpcVoiceAgentReport[_0x3e75('0x31')]({'acwtime':_0x3b7fc5},_0xedf93b[_0x3e75('0x8')][_0x4351a9][_0x3e75('0x2f')],_0x4351a9)[_0x3e75('0x23')](function(_0x294da9){logger['info']('[%s][UPDATE][ACWTIME:%s]',_0x45ca39,_0x3b7fc5,_0x294da9);})[_0x3e75('0x32')](function(_0x26ef85){logger[_0x3e75('0x33')](_0x3e75('0x34'),_0x45ca39,_0x26ef85);});delete _0xedf93b[_0x3e75('0x8')][_0x4351a9];};}});}else{logger[_0x3e75('0x26')](_0x3e75('0x35'),_0x45ca39,_0x4351a9,_0x27c8ab);}});}})[_0x3e75('0x32')](function(_0x239138){logger[_0x3e75('0x33')](_0x3e75('0x36'),_0x45ca39,_0xedf93b[_0x3e75('0x6')][_0x27c8ab]['acwTimeout'],_0x4351a9,_0x27c8ab);})[_0x3e75('0x37')](function(){delete _0xedf93b[_0x3e75('0x1a')][_0x45ca39];});}catch(_0x43dcb7){logger['error']('[ACW][START]\x20%s',_0x43dcb7[_0x3e75('0x38')]);}};Acw[_0x3e75('0x18')]['stopAcw']=function(_0x53cf0d){try{var _0x58d18a=this;if(_0x58d18a[_0x3e75('0x8')][_0x53cf0d]){_0x58d18a[_0x3e75('0x8')][_0x53cf0d][_0x3e75('0x2a')]=![];var _0x46e222=_0x58d18a[_0x3e75('0x8')][_0x53cf0d][_0x3e75('0x2f')];var _0x5555e7=_0x58d18a[_0x3e75('0x8')][_0x53cf0d][_0x3e75('0x1c')];var _0x2e955e=_0x58d18a[_0x3e75('0x6')][_0x5555e7]['acwTimeout'];logger[_0x3e75('0x26')]('[%s][TIMER][STOP][AGENT:%s]',_0x46e222,_0x53cf0d);RpcUser[_0x3e75('0x39')](this['agents'][_0x53cf0d]);RpcVoiceAgentReport['update']({'acwtime':_0x2e955e,'agentacw':!![]},_0x46e222,_0x53cf0d)[_0x3e75('0x23')](function(_0xd95d26){logger[_0x3e75('0x26')](_0x3e75('0x3a'),_0x46e222,_0x2e955e,_0xd95d26);})[_0x3e75('0x32')](function(_0x113898){logger[_0x3e75('0x33')](_0x3e75('0x34'),_0x46e222,_0x113898);});}else{logger[_0x3e75('0x33')]('[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer',_0x53cf0d);if(_0x58d18a[_0x3e75('0x8')]){logger['info'](_0x3e75('0x3b'),JSON['stringify'](_0x58d18a[_0x3e75('0x8')]));}}}catch(_0x579f0e){logger['error'](_0x3e75('0x3c'),_0x579f0e[_0x3e75('0x38')]);}};Acw['prototype']['syncAgentConnect']=function(_0x26819e){try{if(this['voiceQueues'][_0x26819e[_0x3e75('0x1c')]]&&(this[_0x3e75('0x6')][_0x26819e[_0x3e75('0x1c')]][_0x3e75('0x4')]||this['voiceQueues'][_0x26819e['queue']][_0x3e75('0x1e')])){if(this[_0x3e75('0x7')][_0x26819e[_0x3e75('0x1b')]]){this[_0x3e75('0x1a')][_0x26819e[_0x3e75('0x2f')]]={'queue':_0x26819e['queue'],'interface':_0x26819e[_0x3e75('0x1b')],'destlinkedid':_0x26819e[_0x3e75('0x27')]};}}}catch(_0x3664c3){logger['error'](_0x3e75('0x3d'),_0x3664c3['message']);}};Acw[_0x3e75('0x18')]['syncAgentConnectPreview']=function(_0x3ec2e2){try{if(this[_0x3e75('0x6')][_0x3ec2e2[_0x3e75('0x1c')]]&&(this[_0x3e75('0x6')][_0x3ec2e2[_0x3e75('0x1c')]]['acw']||this[_0x3e75('0x6')][_0x3ec2e2[_0x3e75('0x1c')]]['mandatoryDisposition'])){if(this['agents'][_0x3ec2e2[_0x3e75('0x1b')]]){this[_0x3e75('0x1a')][_0x3ec2e2[_0x3e75('0x2f')]]={'queue':_0x3ec2e2[_0x3e75('0x1c')],'interface':_0x3ec2e2[_0x3e75('0x1b')]};}}}catch(_0x88812d){logger['error'](_0x3e75('0x3e'),_0x88812d[_0x3e75('0x38')]);}};Acw[_0x3e75('0x18')]['syncHangupRequest']=function(_0x54672c){try{if(this[_0x3e75('0x1a')][_0x54672c[_0x3e75('0x2f')]]&&_[_0x3e75('0x3f')](this[_0x3e75('0x1a')][_0x54672c[_0x3e75('0x2f')]][_0x3e75('0x40')])){logger['info']('[%s][HANGUP:UNIQUEID]',_0x54672c[_0x3e75('0x2f')]);this[_0x3e75('0x19')](_0x54672c[_0x3e75('0x2f')]);}else if(this[_0x3e75('0x1a')][_0x54672c[_0x3e75('0x41')]]&&_[_0x3e75('0x3f')](this[_0x3e75('0x1a')][_0x54672c[_0x3e75('0x41')]][_0x3e75('0x40')])){logger[_0x3e75('0x26')](_0x3e75('0x42'),_0x54672c[_0x3e75('0x41')]);this[_0x3e75('0x19')](_0x54672c[_0x3e75('0x41')]);}}catch(_0x4214f2){logger[_0x3e75('0x33')](_0x3e75('0x43'),_0x4214f2[_0x3e75('0x38')]);}};Acw[_0x3e75('0x18')]['syncHangup']=function(_0x28033c){try{if(this[_0x3e75('0x1a')][_0x28033c[_0x3e75('0x2f')]]&&this[_0x3e75('0x1a')][_0x28033c[_0x3e75('0x2f')]]['attended']){logger['info'](_0x3e75('0x44'),_0x28033c[_0x3e75('0x2f')]);this['startAcw'](_0x28033c[_0x3e75('0x2f')]);}else if(this[_0x3e75('0x1a')][_0x28033c[_0x3e75('0x41')]]&&this['channels'][_0x28033c[_0x3e75('0x41')]][_0x3e75('0x40')]){logger['info'](_0x3e75('0x45'),_0x28033c[_0x3e75('0x41')]);this[_0x3e75('0x19')](_0x28033c[_0x3e75('0x41')]);}}catch(_0x5be5f9){logger['error'](_0x3e75('0x46'),_0x5be5f9[_0x3e75('0x38')]);}};Acw['prototype'][_0x3e75('0x11')]=function(_0x3275e4){try{if(!_[_0x3e75('0x47')](this[_0x3e75('0x1a')][_0x3275e4[_0x3e75('0x48')]])){this[_0x3e75('0x19')](_0x3275e4[_0x3e75('0x48')]);if(this[_0x3e75('0x1a')][_0x3275e4['secondtransfereruniqueid']]){this[_0x3e75('0x1a')][_0x3275e4[_0x3e75('0x49')]][_0x3e75('0x40')]=!![];this['channels'][_0x3275e4[_0x3e75('0x4a')]]=this['channels'][_0x3275e4['secondtransfereruniqueid']];delete this[_0x3e75('0x1a')][_0x3275e4[_0x3e75('0x49')]];}}else if(!_[_0x3e75('0x47')](this[_0x3e75('0x1a')][_0x3275e4[_0x3e75('0x4a')]])){this[_0x3e75('0x19')](_0x3275e4[_0x3e75('0x4a')]);if(this['channels'][_0x3275e4[_0x3e75('0x4b')]]){this['channels'][_0x3275e4[_0x3e75('0x4b')]][_0x3e75('0x40')]=!![];this['channels'][_0x3275e4[_0x3e75('0x48')]]=this['channels'][_0x3275e4['origtransfereruniqueid']];delete this['channels'][_0x3275e4[_0x3e75('0x4b')]];}}}catch(_0x473bcd){logger[_0x3e75('0x33')](_0x3e75('0x4c'),_0x473bcd[_0x3e75('0x38')]);}};Acw[_0x3e75('0x18')][_0x3e75('0x13')]=function(_0x3a42ef){try{if(this['channels'][_0x3a42ef[_0x3e75('0x4d')]]){logger[_0x3e75('0x26')](_0x3e75('0x4e'),JSON[_0x3e75('0x4f')](_0x3a42ef['transfereruniqueid']));this[_0x3e75('0x19')](_0x3a42ef[_0x3e75('0x4d')]);}else if(this[_0x3e75('0x1a')][_0x3a42ef[_0x3e75('0x50')]]){logger['info'](_0x3e75('0x51'),JSON[_0x3e75('0x4f')](_0x3a42ef[_0x3e75('0x50')]));this[_0x3e75('0x19')](_0x3a42ef[_0x3e75('0x50')]);}}catch(_0x2d0100){logger[_0x3e75('0x33')]('[ACW][syncBlindTransfer]\x20%s',_0x2d0100[_0x3e75('0x38')]);}};Acw[_0x3e75('0x18')]['syncAgentRingNoAnswer']=function(_0xf6c7a){try{if(this['voiceQueues'][_0xf6c7a[_0x3e75('0x1c')]]&&this[_0x3e75('0x6')][_0xf6c7a[_0x3e75('0x1c')]][_0x3e75('0x52')]===_0x3e75('0x53')){if(this[_0x3e75('0x7')][_0xf6c7a[_0x3e75('0x1b')]]){logger[_0x3e75('0x26')](_0x3e75('0x54'),_0xf6c7a['uniqueid'],_0xf6c7a[_0x3e75('0x1b')],_0xf6c7a[_0x3e75('0x1c')]);return RpcUser[_0x3e75('0x28')](this['agents'][_0xf6c7a['interface']],_0x3e75('0x55'),_0xf6c7a['uniqueid']);}}}catch(_0xb0811){logger['error'](_0x3e75('0x56'),_0xb0811[_0x3e75('0x38')]);}};module[_0x3e75('0x57')]=Acw;