Built motion from commit 43538d75.|2.5.35
[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 _0xc927=['isUndefined','[%s][HANGUP:UNIQUEID]','linkedid','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','isNil','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','transfereeuniqueid','syncBlindTransfer','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','stringify','[ACW][syncBlindTransfer]\x20%s','autopause','all','Auto-Pause','exports','lodash','../ami','../../../config/logger','acw','../rpc/user','voiceQueues','agents','timers','channels','syncAgentConnect','bind','hangup','syncHangup','syncAgentRingNoAnswer','attendedtransfer','syncAttendedTransfer','syncAgentConnectPreview','milliseconds','diff','seconds','prototype','startAcw','interface','queue','ACW','mandatoryDisposition','mandatoryDispositionPause','name','Action','then','getAgent','info','[%s][START][AGENT:%s][QUEUE:%s]','attended','destlinkedid','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','acwTimeout','stopAcw','lastPauseAt','format','YYYY-MM-DD\x20HH:mm:ss','updateAcw','timer','update','uniqueid','[%s][UPDATE][ACWTIME:%s]','error','[%s][UPDATE][ERRORS:%s]','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','catch','finally','[ACW][START]\x20%s','message','[%s][TIMER][STOP][AGENT:%s]','saveUnpause','[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer','[ACW][TIMERS]','[ACW][STOP]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','syncHangupRequest'];(function(_0x249be1,_0xae7153){var _0x514cbe=function(_0x3b9d08){while(--_0x3b9d08){_0x249be1['push'](_0x249be1['shift']());}};_0x514cbe(++_0xae7153);}(_0xc927,0xbd));var _0x7c92=function(_0x36c4f4,_0x5d0d6e){_0x36c4f4=_0x36c4f4-0x0;var _0x370b73=_0xc927[_0x36c4f4];return _0x370b73;};'use strict';var util=require('util');var _=require(_0x7c92('0x0'));var moment=require('moment');var ami=require(_0x7c92('0x1'));var logger=require(_0x7c92('0x2'))(_0x7c92('0x3'));var RpcUser=require(_0x7c92('0x4'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x374a47){this['voiceQueues']=_0x374a47[_0x7c92('0x5')];this[_0x7c92('0x6')]=_0x374a47[_0x7c92('0x6')];this[_0x7c92('0x7')]=_0x374a47['timers'];this[_0x7c92('0x8')]={};ami['on']('agentconnect',this[_0x7c92('0x9')][_0x7c92('0xa')](this));ami['on']('hanguprequest',this['syncHangupRequest']['bind'](this));ami['on'](_0x7c92('0xb'),this[_0x7c92('0xc')][_0x7c92('0xa')](this));ami['on']('agentringnoanswer',this[_0x7c92('0xd')]['bind'](this));ami['on'](_0x7c92('0xe'),this[_0x7c92('0xf')]['bind'](this));ami['on']('blindtransfer',this['syncBlindTransfer']['bind'](this));ami['on']('custom:agentConnectPreview',this[_0x7c92('0x10')][_0x7c92('0xa')](this));}function getDiff(_0x51135e){var _0x5e6219=moment()[_0x7c92('0x11')](0x0);var _0x7202b4=moment(_0x51135e)['milliseconds'](0x0);return _0x5e6219[_0x7c92('0x12')](_0x7202b4,_0x7c92('0x13'));}Acw[_0x7c92('0x14')][_0x7c92('0x15')]=function(_0x32a44d){try{var _0x18bbec=this;var _0x3b5103=this[_0x7c92('0x8')][_0x32a44d][_0x7c92('0x16')];var _0x5573ff=this[_0x7c92('0x8')][_0x32a44d][_0x7c92('0x17')];var _0x4c34df=this[_0x7c92('0x5')][_0x5573ff];var _0x53d8c7=![];var _0x1337f=_0x7c92('0x18');if(_0x4c34df[_0x7c92('0x19')]){if(_0x4c34df[_0x7c92('0x1a')][_0x7c92('0x1b')]){_0x53d8c7=!![];_0x1337f=_0x4c34df[_0x7c92('0x1a')]['name'];}}ami[_0x7c92('0x1c')]({'action':'QueuePause','interface':_0x3b5103,'paused':!![],'reason':_0x1337f})[_0x7c92('0x1d')](function(_0x32d4a4){if(_0x18bbec[_0x7c92('0x6')][_0x3b5103]){return RpcUser[_0x7c92('0x1e')](_0x18bbec[_0x7c92('0x6')][_0x3b5103]['id'])[_0x7c92('0x1d')](function(_0x5e515b){if(_0x5e515b&&!_0x5e515b['voicePause']){logger[_0x7c92('0x1f')](_0x7c92('0x20'),_0x32a44d,_0x3b5103,_0x5573ff);var _0x3b8415=_0x18bbec['channels'][_0x32a44d][_0x7c92('0x21')]&&_0x18bbec[_0x7c92('0x8')][_0x32a44d][_0x7c92('0x22')]?_0x18bbec['channels'][_0x32a44d]['destlinkedid']:_0x32a44d;return RpcUser['savePause'](_0x18bbec[_0x7c92('0x6')][_0x3b5103],_0x1337f,_0x3b8415)[_0x7c92('0x1d')](function(_0x938ee3){if(!_0x53d8c7){_0x18bbec[_0x7c92('0x7')][_0x3b5103]={};logger[_0x7c92('0x1f')](_0x7c92('0x23'),_0x32a44d,_0x18bbec[_0x7c92('0x5')][_0x5573ff][_0x7c92('0x24')],_0x3b5103,_0x5573ff);_0x18bbec['timers'][_0x3b5103]['timer']=setTimeout(_0x18bbec[_0x7c92('0x25')]['bind'](_0x18bbec,_0x3b5103),_0x18bbec['voiceQueues'][_0x5573ff]['acwTimeout']*0x3e8);_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x26')]=moment()[_0x7c92('0x27')](_0x7c92('0x28'));_0x18bbec[_0x7c92('0x7')][_0x3b5103]['uniqueid']=_0x32a44d;_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x17')]=_0x5573ff;_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x29')]=function(){var _0xfcd7dc=getDiff(_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x26')]);clearTimeout(_0x18bbec[_0x7c92('0x7')][_0x3b5103]['timer']);_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x2a')]=![];RpcVoiceAgentReport[_0x7c92('0x2b')]({'acwtime':_0xfcd7dc},_0x18bbec[_0x7c92('0x7')][_0x3b5103][_0x7c92('0x2c')],_0x3b5103)['then'](function(_0x1345d0){logger[_0x7c92('0x1f')](_0x7c92('0x2d'),_0x32a44d,_0xfcd7dc,_0x1345d0);})['catch'](function(_0x490805){logger[_0x7c92('0x2e')](_0x7c92('0x2f'),_0x32a44d,_0x490805);});delete _0x18bbec['timers'][_0x3b5103];};}});}else{logger[_0x7c92('0x1f')](_0x7c92('0x30'),_0x32a44d,_0x3b5103,_0x5573ff);}});}})[_0x7c92('0x31')](function(_0x3e85cc){logger['error'](_0x7c92('0x23'),_0x32a44d,_0x18bbec[_0x7c92('0x5')][_0x5573ff][_0x7c92('0x24')],_0x3b5103,_0x5573ff);})[_0x7c92('0x32')](function(){delete _0x18bbec['channels'][_0x32a44d];});}catch(_0x3e39b6){logger[_0x7c92('0x2e')](_0x7c92('0x33'),_0x3e39b6[_0x7c92('0x34')]);}};Acw[_0x7c92('0x14')]['stopAcw']=function(_0x5dda3a){try{var _0x59b6c6=this;if(_0x59b6c6[_0x7c92('0x7')][_0x5dda3a]){_0x59b6c6[_0x7c92('0x7')][_0x5dda3a][_0x7c92('0x2a')]=![];var _0x25e45b=_0x59b6c6[_0x7c92('0x7')][_0x5dda3a][_0x7c92('0x2c')];var _0x1f14d0=_0x59b6c6[_0x7c92('0x7')][_0x5dda3a][_0x7c92('0x17')];var _0x45f63f=_0x59b6c6['voiceQueues'][_0x1f14d0][_0x7c92('0x24')];logger['info'](_0x7c92('0x35'),_0x25e45b,_0x5dda3a);RpcUser[_0x7c92('0x36')](this[_0x7c92('0x6')][_0x5dda3a]);RpcVoiceAgentReport[_0x7c92('0x2b')]({'acwtime':_0x45f63f,'agentacw':!![]},_0x25e45b,_0x5dda3a)[_0x7c92('0x1d')](function(_0x4daa11){logger[_0x7c92('0x1f')](_0x7c92('0x2d'),_0x25e45b,_0x45f63f,_0x4daa11);})[_0x7c92('0x31')](function(_0x2ae0d7){logger[_0x7c92('0x2e')]('[%s][UPDATE][ERRORS:%s]',_0x25e45b,_0x2ae0d7);});}else{logger['error'](_0x7c92('0x37'),_0x5dda3a);if(_0x59b6c6[_0x7c92('0x7')]){logger[_0x7c92('0x1f')](_0x7c92('0x38'),JSON['stringify'](_0x59b6c6[_0x7c92('0x7')]));}}}catch(_0x429d1f){logger['error'](_0x7c92('0x39'),_0x429d1f[_0x7c92('0x34')]);}};Acw[_0x7c92('0x14')][_0x7c92('0x9')]=function(_0x1adf10){try{if(this['voiceQueues'][_0x1adf10[_0x7c92('0x17')]]&&(this['voiceQueues'][_0x1adf10[_0x7c92('0x17')]][_0x7c92('0x3')]||this[_0x7c92('0x5')][_0x1adf10['queue']][_0x7c92('0x19')])){if(this['agents'][_0x1adf10[_0x7c92('0x16')]]){this[_0x7c92('0x8')][_0x1adf10['uniqueid']]={'queue':_0x1adf10['queue'],'interface':_0x1adf10[_0x7c92('0x16')],'destlinkedid':_0x1adf10[_0x7c92('0x22')]};}}}catch(_0x407033){logger['error']('[ACW][syncAgentConnect]\x20%s',_0x407033[_0x7c92('0x34')]);}};Acw[_0x7c92('0x14')]['syncAgentConnectPreview']=function(_0x2c6b6f){try{if(this[_0x7c92('0x5')][_0x2c6b6f['queue']]&&(this[_0x7c92('0x5')][_0x2c6b6f['queue']][_0x7c92('0x3')]||this[_0x7c92('0x5')][_0x2c6b6f[_0x7c92('0x17')]][_0x7c92('0x19')])){if(this[_0x7c92('0x6')][_0x2c6b6f[_0x7c92('0x16')]]){this[_0x7c92('0x8')][_0x2c6b6f[_0x7c92('0x2c')]]={'queue':_0x2c6b6f[_0x7c92('0x17')],'interface':_0x2c6b6f[_0x7c92('0x16')]};}}}catch(_0x1bc64f){logger[_0x7c92('0x2e')](_0x7c92('0x3a'),_0x1bc64f[_0x7c92('0x34')]);}};Acw['prototype'][_0x7c92('0x3b')]=function(_0x412155){try{if(this['channels'][_0x412155['uniqueid']]&&_[_0x7c92('0x3c')](this[_0x7c92('0x8')][_0x412155[_0x7c92('0x2c')]]['attended'])){logger[_0x7c92('0x1f')](_0x7c92('0x3d'),_0x412155[_0x7c92('0x2c')]);this['startAcw'](_0x412155[_0x7c92('0x2c')]);}else if(this[_0x7c92('0x8')][_0x412155['linkedid']]&&_['isUndefined'](this[_0x7c92('0x8')][_0x412155[_0x7c92('0x3e')]][_0x7c92('0x21')])){logger[_0x7c92('0x1f')]('[%s][HANGUP:LINKEDID]',_0x412155['linkedid']);this[_0x7c92('0x15')](_0x412155[_0x7c92('0x3e')]);}}catch(_0x4d55af){logger[_0x7c92('0x2e')](_0x7c92('0x3f'),_0x4d55af[_0x7c92('0x34')]);}};Acw[_0x7c92('0x14')]['syncHangup']=function(_0x179917){try{if(this[_0x7c92('0x8')][_0x179917[_0x7c92('0x2c')]]&&this['channels'][_0x179917[_0x7c92('0x2c')]]['attended']){logger[_0x7c92('0x1f')](_0x7c92('0x40'),_0x179917[_0x7c92('0x2c')]);this[_0x7c92('0x15')](_0x179917['uniqueid']);}else if(this['channels'][_0x179917[_0x7c92('0x3e')]]&&this[_0x7c92('0x8')][_0x179917[_0x7c92('0x3e')]]['attended']){logger[_0x7c92('0x1f')](_0x7c92('0x41'),_0x179917[_0x7c92('0x3e')]);this[_0x7c92('0x15')](_0x179917[_0x7c92('0x3e')]);}}catch(_0x18f82e){logger[_0x7c92('0x2e')](_0x7c92('0x42'),_0x18f82e[_0x7c92('0x34')]);}};Acw['prototype'][_0x7c92('0xf')]=function(_0x507654){try{if(!_[_0x7c92('0x43')](this['channels'][_0x507654['transfereeuniqueid']])){this[_0x7c92('0x15')](_0x507654['transfereeuniqueid']);if(this[_0x7c92('0x8')][_0x507654[_0x7c92('0x44')]]){this[_0x7c92('0x8')][_0x507654[_0x7c92('0x44')]][_0x7c92('0x21')]=!![];this[_0x7c92('0x8')][_0x507654[_0x7c92('0x45')]]=this['channels'][_0x507654['secondtransfereruniqueid']];delete this[_0x7c92('0x8')][_0x507654[_0x7c92('0x44')]];}}else if(!_[_0x7c92('0x43')](this['channels'][_0x507654[_0x7c92('0x45')]])){this[_0x7c92('0x15')](_0x507654[_0x7c92('0x45')]);if(this['channels'][_0x507654[_0x7c92('0x46')]]){this[_0x7c92('0x8')][_0x507654[_0x7c92('0x46')]][_0x7c92('0x21')]=!![];this['channels'][_0x507654[_0x7c92('0x47')]]=this[_0x7c92('0x8')][_0x507654[_0x7c92('0x46')]];delete this[_0x7c92('0x8')][_0x507654['origtransfereruniqueid']];}}}catch(_0x2fabd9){logger[_0x7c92('0x2e')]('[ACW][syncAttendedTransfer]\x20%s',_0x2fabd9[_0x7c92('0x34')]);}};Acw[_0x7c92('0x14')][_0x7c92('0x48')]=function(_0x35be83){try{if(this[_0x7c92('0x8')][_0x35be83[_0x7c92('0x49')]]){logger[_0x7c92('0x1f')](_0x7c92('0x4a'),JSON['stringify'](_0x35be83[_0x7c92('0x49')]));this[_0x7c92('0x15')](_0x35be83[_0x7c92('0x49')]);}else if(this[_0x7c92('0x8')][_0x35be83[_0x7c92('0x4b')]]){logger[_0x7c92('0x1f')](_0x7c92('0x4c'),JSON[_0x7c92('0x4d')](_0x35be83[_0x7c92('0x4b')]));this[_0x7c92('0x15')](_0x35be83[_0x7c92('0x4b')]);}}catch(_0x264af1){logger[_0x7c92('0x2e')](_0x7c92('0x4e'),_0x264af1[_0x7c92('0x34')]);}};Acw['prototype'][_0x7c92('0xd')]=function(_0x519845){try{if(this[_0x7c92('0x5')][_0x519845['queue']]&&this['voiceQueues'][_0x519845[_0x7c92('0x17')]][_0x7c92('0x4f')]===_0x7c92('0x50')){if(this['agents'][_0x519845['interface']]){logger['info']('[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]',_0x519845[_0x7c92('0x2c')],_0x519845['interface'],_0x519845[_0x7c92('0x17')]);return RpcUser['savePause'](this[_0x7c92('0x6')][_0x519845[_0x7c92('0x16')]],_0x7c92('0x51'),_0x519845[_0x7c92('0x2c')]);}}}catch(_0x525261){logger[_0x7c92('0x2e')]('[ACW][syncAgentRingNoAnswer]\x20%s',_0x525261['message']);}};module[_0x7c92('0x52')]=Acw;