c0d840c76c49b31af5b07df643124d2c550ce7ac
[motion-next.git] / server / services / ami / acw / index.js
1 const a1049_0x3c0e=['lastPauseAt','[%s][HANGUP:LINKEDID]','linkedid','[ACW][syncHangupRequest]\x20%s','ACW','queue','all','[%s][START][AGENT:%s][QUEUE:%s]','mandatoryDispositionPause','uniqueid','[ACW][syncAttendedTransfer]\x20%s','custom:agentConnectPreview','saveUnpause','origtransfereruniqueid','[ACW][syncAgentConnectPreview]\x20%s','catch','secondtransfereruniqueid','voiceQueues','update','timer','agentringnoanswer','startAcw','QueuePause','message','[%s][UPDATE][ACWTIME:%s]','agentconnect','updateAcw','[ACW][TIMERS]','Action','bind','voicePause','stringify','attendedtransfer','format','transfererlinkedid','[ACW][STOP]\x20%s','transfereruniqueid','agents','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','then','transfertargetuniqueid','../rpc/user','../ami','lodash','prototype','diff','isUndefined','isNil','stopAcw','getAgent','[%s][BLINDTRANSFER:LINKEDID]','[%s][HANGUP:UNIQUEID]','YYYY-MM-DD\x20HH:mm:ss','hangup','[ACW][syncHangup]\x20%s','interface','syncBlindTransfer','syncHangup','exports','../rpc/voiceAgentReport','[ACW][syncAgentRingNoAnswer]\x20%s','savePause','../../../config/logger','syncAttendedTransfer','hanguprequest','acwTimeout','info','[%s][BLINDTRANSFER:UNIQUEID]','syncAgentConnect','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','acw','autopause','destlinkedid','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','seconds','transfereeuniqueid','timers','error','[TIMER][STOP][AGENT:%s]','[ACW][START]\x20%s','milliseconds','moment','attended','channels','syncAgentConnectPreview','name'];(function(_0x54a9de,_0x3c0ee0){const _0x239613=function(_0x235517){while(--_0x235517){_0x54a9de['push'](_0x54a9de['shift']());}};_0x239613(++_0x3c0ee0);}(a1049_0x3c0e,0xdd));const a1049_0x2396=function(_0x54a9de,_0x3c0ee0){_0x54a9de=_0x54a9de-0x0;let _0x239613=a1049_0x3c0e[_0x54a9de];return _0x239613;};const _0x3f51ed=a1049_0x2396;'use strict';const _=require(_0x3f51ed('0x50')),moment=require(_0x3f51ed('0x20')),ami=require(_0x3f51ed('0x4f')),logger=require(_0x3f51ed('0xd'))(_0x3f51ed('0x15')),RpcUser=require(_0x3f51ed('0x4e')),RpcVoiceAgentReport=require(_0x3f51ed('0xa'));function Acw(_0x235517){const _0x22e7c8=_0x3f51ed;this[_0x22e7c8('0x36')]=_0x235517[_0x22e7c8('0x36')],this[_0x22e7c8('0x4a')]=_0x235517[_0x22e7c8('0x4a')],this['timers']=_0x235517[_0x22e7c8('0x1b')],this[_0x22e7c8('0x22')]={},ami['on'](_0x22e7c8('0x3e'),this[_0x22e7c8('0x13')]['bind'](this)),ami['on'](_0x22e7c8('0xf'),this['syncHangupRequest']['bind'](this)),ami['on'](_0x22e7c8('0x4'),this['syncHangup'][_0x22e7c8('0x42')](this)),ami['on'](_0x22e7c8('0x39'),this['syncAgentRingNoAnswer'][_0x22e7c8('0x42')](this)),ami['on'](_0x22e7c8('0x45'),this['syncAttendedTransfer'][_0x22e7c8('0x42')](this)),ami['on']('blindtransfer',this['syncBlindTransfer'][_0x22e7c8('0x42')](this)),ami['on'](_0x22e7c8('0x30'),this[_0x22e7c8('0x23')][_0x22e7c8('0x42')](this));}function getDiff(_0x49941e){const _0x5076cc=_0x3f51ed,_0x489f37=moment()[_0x5076cc('0x1f')](0x0),_0x13f203=moment(_0x49941e)['milliseconds'](0x0);return _0x489f37[_0x5076cc('0x52')](_0x13f203,_0x5076cc('0x19'));}Acw[_0x3f51ed('0x51')]['startAcw']=function(_0x401050){const _0x4981a1=_0x3f51ed;try{const _0x2bb922=this,_0x4098dc=this[_0x4981a1('0x22')][_0x401050][_0x4981a1('0x6')],_0x4608ab=this[_0x4981a1('0x22')][_0x401050]['queue'],_0x134324=this[_0x4981a1('0x36')][_0x4608ab];let _0x5277f8=![],_0x37e88c=_0x4981a1('0x29');_0x134324['mandatoryDisposition']&&(_0x134324[_0x4981a1('0x2d')]['name']&&(_0x5277f8=!![],_0x37e88c=_0x134324[_0x4981a1('0x2d')][_0x4981a1('0x24')])),ami[_0x4981a1('0x41')]({'action':_0x4981a1('0x3b'),'interface':_0x4098dc,'paused':!![],'reason':_0x37e88c})['then'](function(){const _0x17e7cf=_0x4981a1;if(_0x2bb922['agents'][_0x4098dc])return RpcUser[_0x17e7cf('0x0')](_0x2bb922[_0x17e7cf('0x4a')][_0x4098dc]['id'])[_0x17e7cf('0x4c')](function(_0x353ec6){const _0x13e7b2=_0x17e7cf;if(_0x353ec6&&!_0x353ec6[_0x13e7b2('0x43')]){logger[_0x13e7b2('0x11')](_0x13e7b2('0x2c'),_0x401050,_0x4098dc,_0x4608ab);const _0x2081d7=_0x2bb922[_0x13e7b2('0x22')][_0x401050][_0x13e7b2('0x21')]&&_0x2bb922[_0x13e7b2('0x22')][_0x401050][_0x13e7b2('0x17')]?_0x2bb922[_0x13e7b2('0x22')][_0x401050][_0x13e7b2('0x17')]:_0x401050;return RpcUser[_0x13e7b2('0xc')](_0x2bb922[_0x13e7b2('0x4a')][_0x4098dc],_0x37e88c,_0x2081d7)[_0x13e7b2('0x4c')](function(){const _0x22016e=_0x13e7b2;!_0x5277f8&&(_0x2bb922[_0x22016e('0x1b')][_0x4098dc]={},logger[_0x22016e('0x11')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x401050,_0x2bb922[_0x22016e('0x36')][_0x4608ab][_0x22016e('0x10')],_0x4098dc,_0x4608ab),_0x2bb922[_0x22016e('0x1b')][_0x4098dc]['timer']=setTimeout(_0x2bb922[_0x22016e('0x55')][_0x22016e('0x42')](_0x2bb922,_0x4098dc),_0x2bb922[_0x22016e('0x36')][_0x4608ab][_0x22016e('0x10')]*0x3e8),_0x2bb922['timers'][_0x4098dc]['lastPauseAt']=moment()[_0x22016e('0x46')](_0x22016e('0x3')),_0x2bb922[_0x22016e('0x1b')][_0x4098dc][_0x22016e('0x2e')]=_0x401050,_0x2bb922[_0x22016e('0x1b')][_0x4098dc][_0x22016e('0x2a')]=_0x4608ab,_0x2bb922[_0x22016e('0x1b')][_0x4098dc][_0x22016e('0x3f')]=function(){const _0x580cb7=_0x22016e,_0x2e28b0=getDiff(_0x2bb922[_0x580cb7('0x1b')][_0x4098dc][_0x580cb7('0x25')]);clearTimeout(_0x2bb922['timers'][_0x4098dc]['timer']),_0x2bb922['timers'][_0x4098dc][_0x580cb7('0x38')]=![],RpcVoiceAgentReport[_0x580cb7('0x37')]({'acwtime':_0x2e28b0},_0x2bb922[_0x580cb7('0x1b')][_0x4098dc][_0x580cb7('0x2e')],_0x4098dc)[_0x580cb7('0x4c')](function(_0x2ef3b3){const _0x59b443=_0x580cb7;logger[_0x59b443('0x11')]('[%s][UPDATE][ACWTIME:%s]',_0x401050,_0x2e28b0,_0x2ef3b3);})[_0x580cb7('0x34')](function(_0x18786d){const _0x7fa22e=_0x580cb7;logger[_0x7fa22e('0x1c')]('[%s][UPDATE][ERRORS:%s]',_0x401050,_0x18786d);}),delete _0x2bb922['timers'][_0x4098dc];});});}else logger[_0x13e7b2('0x11')](_0x13e7b2('0x18'),_0x401050,_0x4098dc,_0x4608ab);});})[_0x4981a1('0x34')](function(){const _0x3145aa=_0x4981a1;logger[_0x3145aa('0x1c')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x401050,_0x2bb922[_0x3145aa('0x36')][_0x4608ab][_0x3145aa('0x10')],_0x4098dc,_0x4608ab);})['finally'](function(){const _0x313a46=_0x4981a1;delete _0x2bb922[_0x313a46('0x22')][_0x401050];});}catch(_0x2a07de){logger[_0x4981a1('0x1c')](_0x4981a1('0x1e'),_0x2a07de[_0x4981a1('0x3c')]);}},Acw[_0x3f51ed('0x51')][_0x3f51ed('0x55')]=function(_0x10a057){const _0x21f856=_0x3f51ed;try{const _0x39c74f=this;if(_0x39c74f[_0x21f856('0x1b')][_0x10a057]){_0x39c74f[_0x21f856('0x1b')][_0x10a057][_0x21f856('0x38')]=![];const _0xab9743=_0x39c74f['timers'][_0x10a057][_0x21f856('0x2e')],_0x24e7b8=_0x39c74f[_0x21f856('0x1b')][_0x10a057][_0x21f856('0x2a')],_0x35c291=_0x39c74f['voiceQueues'][_0x24e7b8]['acwTimeout'];logger[_0x21f856('0x11')](_0x21f856('0x1d'),_0x10a057),RpcUser[_0x21f856('0x31')](this[_0x21f856('0x4a')][_0x10a057]),RpcVoiceAgentReport[_0x21f856('0x37')]({'acwtime':_0x35c291,'agentacw':!![]},_0xab9743,_0x10a057)[_0x21f856('0x4c')](function(_0x21368c){const _0x557637=_0x21f856;logger['info'](_0x557637('0x3d'),_0xab9743,_0x35c291,_0x21368c);})['catch'](function(_0x4d4ffc){logger['error']('[%s][UPDATE][ERRORS:%s]',_0xab9743,_0x4d4ffc);});}else logger[_0x21f856('0x1c')]('[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer',_0x10a057),_0x39c74f[_0x21f856('0x1b')]&&logger[_0x21f856('0x11')](_0x21f856('0x40'),JSON[_0x21f856('0x44')](_0x39c74f['timers']));}catch(_0x3dd5cb){logger[_0x21f856('0x1c')](_0x21f856('0x48'),_0x3dd5cb[_0x21f856('0x3c')]);}},Acw[_0x3f51ed('0x51')][_0x3f51ed('0x13')]=function(_0x5a625d){const _0x26db39=_0x3f51ed;try{this[_0x26db39('0x36')][_0x5a625d[_0x26db39('0x2a')]]&&(this[_0x26db39('0x36')][_0x5a625d[_0x26db39('0x2a')]]['acw']||this['voiceQueues'][_0x5a625d[_0x26db39('0x2a')]]['mandatoryDisposition'])&&(this[_0x26db39('0x4a')][_0x5a625d[_0x26db39('0x6')]]&&(this['channels'][_0x5a625d['uniqueid']]={'queue':_0x5a625d[_0x26db39('0x2a')],'interface':_0x5a625d[_0x26db39('0x6')],'destlinkedid':_0x5a625d[_0x26db39('0x17')]}));}catch(_0x39aa99){logger[_0x26db39('0x1c')]('[ACW][syncAgentConnect]\x20%s',_0x39aa99[_0x26db39('0x3c')]);}},Acw[_0x3f51ed('0x51')]['syncAgentConnectPreview']=function(_0x1f4342){const _0x447a23=_0x3f51ed;try{this[_0x447a23('0x36')][_0x1f4342['queue']]&&(this[_0x447a23('0x36')][_0x1f4342[_0x447a23('0x2a')]][_0x447a23('0x15')]||this['voiceQueues'][_0x1f4342[_0x447a23('0x2a')]]['mandatoryDisposition'])&&(this[_0x447a23('0x4a')][_0x1f4342[_0x447a23('0x6')]]&&(this[_0x447a23('0x22')][_0x1f4342['uniqueid']]={'queue':_0x1f4342[_0x447a23('0x2a')],'interface':_0x1f4342['interface']}));}catch(_0x344a72){logger['error'](_0x447a23('0x33'),_0x344a72[_0x447a23('0x3c')]);}},Acw[_0x3f51ed('0x51')]['syncHangupRequest']=function(_0x56da59){const _0x36ac37=_0x3f51ed;try{if(this[_0x36ac37('0x22')][_0x56da59[_0x36ac37('0x2e')]]&&_[_0x36ac37('0x53')](this[_0x36ac37('0x22')][_0x56da59[_0x36ac37('0x2e')]][_0x36ac37('0x21')]))logger[_0x36ac37('0x11')](_0x36ac37('0x2'),_0x56da59[_0x36ac37('0x2e')]),this['startAcw'](_0x56da59['uniqueid']);else this['channels'][_0x56da59[_0x36ac37('0x27')]]&&_[_0x36ac37('0x53')](this[_0x36ac37('0x22')][_0x56da59['linkedid']][_0x36ac37('0x21')])&&(logger[_0x36ac37('0x11')](_0x36ac37('0x26'),_0x56da59[_0x36ac37('0x27')]),this[_0x36ac37('0x3a')](_0x56da59['linkedid']));}catch(_0x3bbfd6){logger[_0x36ac37('0x1c')](_0x36ac37('0x28'),_0x3bbfd6[_0x36ac37('0x3c')]);}},Acw[_0x3f51ed('0x51')][_0x3f51ed('0x8')]=function(_0x1eab2d){const _0x56a8fe=_0x3f51ed;try{if(this[_0x56a8fe('0x22')][_0x1eab2d['uniqueid']]&&this[_0x56a8fe('0x22')][_0x1eab2d['uniqueid']]['attended'])logger[_0x56a8fe('0x11')](_0x56a8fe('0x14'),_0x1eab2d[_0x56a8fe('0x2e')]),this[_0x56a8fe('0x3a')](_0x1eab2d[_0x56a8fe('0x2e')]);else this[_0x56a8fe('0x22')][_0x1eab2d[_0x56a8fe('0x27')]]&&this[_0x56a8fe('0x22')][_0x1eab2d[_0x56a8fe('0x27')]][_0x56a8fe('0x21')]&&(logger[_0x56a8fe('0x11')]('[%s][HANGUPATTENDEDTRANSFER:LINKEDID]',_0x1eab2d[_0x56a8fe('0x27')]),this[_0x56a8fe('0x3a')](_0x1eab2d[_0x56a8fe('0x27')]));}catch(_0x59729d){logger[_0x56a8fe('0x1c')](_0x56a8fe('0x5'),_0x59729d[_0x56a8fe('0x3c')]);}},Acw['prototype'][_0x3f51ed('0xe')]=function(_0x304cfb){const _0x5f25c6=_0x3f51ed;try{if(!_[_0x5f25c6('0x54')](this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x1a')]]))this['startAcw'](_0x304cfb[_0x5f25c6('0x1a')]),this[_0x5f25c6('0x22')][_0x304cfb['secondtransfereruniqueid']]&&(this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x35')]][_0x5f25c6('0x21')]=!![],this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x4d')]]=this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x35')]],delete this['channels'][_0x304cfb[_0x5f25c6('0x35')]]);else!_[_0x5f25c6('0x54')](this[_0x5f25c6('0x22')][_0x304cfb['transfertargetuniqueid']])&&(this['startAcw'](_0x304cfb['transfertargetuniqueid']),this['channels'][_0x304cfb[_0x5f25c6('0x32')]]&&(this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x32')]][_0x5f25c6('0x21')]=!![],this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x1a')]]=this['channels'][_0x304cfb['origtransfereruniqueid']],delete this[_0x5f25c6('0x22')][_0x304cfb[_0x5f25c6('0x32')]]));}catch(_0x214d25){logger[_0x5f25c6('0x1c')](_0x5f25c6('0x2f'),_0x214d25['message']);}},Acw[_0x3f51ed('0x51')][_0x3f51ed('0x7')]=function(_0x319a43){const _0x383d58=_0x3f51ed;try{if(this[_0x383d58('0x22')][_0x319a43[_0x383d58('0x49')]])logger['info'](_0x383d58('0x12'),JSON[_0x383d58('0x44')](_0x319a43['transfereruniqueid'])),this[_0x383d58('0x3a')](_0x319a43[_0x383d58('0x49')]);else this[_0x383d58('0x22')][_0x319a43[_0x383d58('0x47')]]&&(logger[_0x383d58('0x11')](_0x383d58('0x1'),JSON[_0x383d58('0x44')](_0x319a43['transfererlinkedid'])),this[_0x383d58('0x3a')](_0x319a43[_0x383d58('0x47')]));}catch(_0x23393d){logger[_0x383d58('0x1c')]('[ACW][syncBlindTransfer]\x20%s',_0x23393d[_0x383d58('0x3c')]);}},Acw[_0x3f51ed('0x51')]['syncAgentRingNoAnswer']=function(_0xfb4323){const _0x32a2f8=_0x3f51ed;try{if(this[_0x32a2f8('0x36')][_0xfb4323[_0x32a2f8('0x2a')]]&&this[_0x32a2f8('0x36')][_0xfb4323[_0x32a2f8('0x2a')]][_0x32a2f8('0x16')]===_0x32a2f8('0x2b')){if(this[_0x32a2f8('0x4a')][_0xfb4323[_0x32a2f8('0x6')]])return logger[_0x32a2f8('0x11')](_0x32a2f8('0x4b'),_0xfb4323[_0x32a2f8('0x2e')],_0xfb4323[_0x32a2f8('0x6')],_0xfb4323[_0x32a2f8('0x2a')]),RpcUser[_0x32a2f8('0xc')](this[_0x32a2f8('0x4a')][_0xfb4323[_0x32a2f8('0x6')]],'Auto-Pause',_0xfb4323[_0x32a2f8('0x2e')]);}}catch(_0x2fdbd3){logger[_0x32a2f8('0x1c')](_0x32a2f8('0xb'),_0x2fdbd3[_0x32a2f8('0x3c')]);}},module[_0x3f51ed('0x9')]=Acw;