Built motion from commit f861bcb808219e66da88ba48b61bddb35224a65e. Version 3.0.0...
[motion-next.git] / server / services / ami / acw / index.js
1 'use strict';const a1241_0x46de=['error','agents','syncBlindTransfer','Action','87tAhxgP','syncAgentConnectPreview','[ACW][syncAgentRingNoAnswer]\x20%s','YYYY-MM-DD\x20HH:mm:ss','uniqueid','828908beTCRb','[%s][HANGUP:LINKEDID]','bind','lastPauseAt','format','@config/logger','getAgent','13486ZamNrX','acw','[ACW][syncAgentConnect]\x20%s','syncHangupRequest','[ACW][syncBlindTransfer]\x20%s','627865QbSSmq','transfererlinkedid','stringify','[%s][TIMER][STOP][AGENT:%s]','[%s][UPDATE][ERRORS:%s]','catch','agentconnect','savePause','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','voiceQueues','timer','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[ACW][START]\x20%s','autopause','startAcw','lodash','../ami','info','saveUnpause','attended','origtransfereruniqueid','syncAgentRingNoAnswer','[ACW][syncAttendedTransfer]\x20%s','channels','moment','hangup','acwTimeout','[%s][BLINDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','destlinkedid','1185036EItDoK','syncAttendedTransfer','all','1hgKLWC','2585376emGdWs','syncAgentConnect','ACW','name','[%s][UPDATE][ACWTIME:%s]','secondtransfereruniqueid','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','640xUmtXQ','queue','../rpc/user','transfereruniqueid','1IcQWPE','isUndefined','transfereeuniqueid','QueuePause','attendedtransfer','syncHangup','stopAcw','timers','exports','[ACW][syncAgentConnectPreview]\x20%s','then','../rpc/voiceAgentReport','1114270ujnaJG','isNil','mandatoryDispositionPause','custom:agentConnectPreview','transfertargetuniqueid','diff','mandatoryDisposition','message','milliseconds','interface','update','prototype','[ACW][TIMERS]','blindtransfer','seconds','[ACW][syncHangupRequest]\x20%s','linkedid'];const a1241_0x316d=function(_0x347c8a,_0x29dbec){_0x347c8a=_0x347c8a-0x102;let _0x46de1f=a1241_0x46de[_0x347c8a];return _0x46de1f;};const a1241_0x2461b4=a1241_0x316d;(function(_0x22ff64,_0x2c1856){const _0x1a8b19=a1241_0x316d;while(!![]){try{const _0x4ededd=parseInt(_0x1a8b19(0x14c))*parseInt(_0x1a8b19(0x11a))+parseInt(_0x1a8b19(0x13b))*parseInt(_0x1a8b19(0x147))+-parseInt(_0x1a8b19(0x116))+-parseInt(_0x1a8b19(0x10e))*-parseInt(_0x1a8b19(0x126))+-parseInt(_0x1a8b19(0x140))+parseInt(_0x1a8b19(0x10b))+-parseInt(_0x1a8b19(0x10f));if(_0x4ededd===_0x2c1856)break;else _0x22ff64['push'](_0x22ff64['shift']());}catch(_0x390155){_0x22ff64['push'](_0x22ff64['shift']());}}}(a1241_0x46de,0xa75d9));const _=require(a1241_0x2461b4(0x15b)),moment=require(a1241_0x2461b4(0x105)),{getAmi}=require(a1241_0x2461b4(0x15c)),ami=getAmi(),logger=require(a1241_0x2461b4(0x145))(a1241_0x2461b4(0x148)),RpcUser=require(a1241_0x2461b4(0x118)),RpcVoiceAgentReport=require(a1241_0x2461b4(0x125));function Acw(_0x24a16e){const _0x3e26ea=a1241_0x2461b4;this['voiceQueues']=_0x24a16e[_0x3e26ea(0x155)],this[_0x3e26ea(0x138)]=_0x24a16e[_0x3e26ea(0x138)],this[_0x3e26ea(0x121)]=_0x24a16e[_0x3e26ea(0x121)],this[_0x3e26ea(0x104)]={},ami['on'](_0x3e26ea(0x152),this[_0x3e26ea(0x110)][_0x3e26ea(0x142)](this)),ami['on']('hanguprequest',this[_0x3e26ea(0x14a)][_0x3e26ea(0x142)](this)),ami['on'](_0x3e26ea(0x106),this['syncHangup'][_0x3e26ea(0x142)](this)),ami['on']('agentringnoanswer',this[_0x3e26ea(0x102)][_0x3e26ea(0x142)](this)),ami['on'](_0x3e26ea(0x11e),this[_0x3e26ea(0x10c)][_0x3e26ea(0x142)](this)),ami['on'](_0x3e26ea(0x133),this[_0x3e26ea(0x139)][_0x3e26ea(0x142)](this)),ami['on'](_0x3e26ea(0x129),this[_0x3e26ea(0x13c)][_0x3e26ea(0x142)](this));}function getDiff(_0x5ba38d){const _0x50241e=a1241_0x2461b4,_0x4e5c9d=moment()[_0x50241e(0x12e)](0x0),_0x43c5a0=moment(_0x5ba38d)[_0x50241e(0x12e)](0x0);return _0x4e5c9d[_0x50241e(0x12b)](_0x43c5a0,_0x50241e(0x134));}Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x15a)]=function(_0x241d4c){const _0x1e2126=a1241_0x2461b4;try{const _0x19268b=this,_0x5c6210=this[_0x1e2126(0x104)][_0x241d4c][_0x1e2126(0x12f)],_0x1cd8e5=this['channels'][_0x241d4c][_0x1e2126(0x117)],_0x3a8f69=this[_0x1e2126(0x155)][_0x1cd8e5];let _0x1d7b64=![],_0x1efbc1=_0x1e2126(0x111);_0x3a8f69['mandatoryDisposition']&&(_0x3a8f69[_0x1e2126(0x128)][_0x1e2126(0x112)]&&(_0x1d7b64=!![],_0x1efbc1=_0x3a8f69[_0x1e2126(0x128)]['name'])),ami[_0x1e2126(0x13a)]({'action':_0x1e2126(0x11d),'interface':_0x5c6210,'paused':!![],'reason':_0x1efbc1})[_0x1e2126(0x124)](function(){const _0x413ef1=_0x1e2126;if(_0x19268b[_0x413ef1(0x138)][_0x5c6210])return RpcUser[_0x413ef1(0x146)](_0x19268b[_0x413ef1(0x138)][_0x5c6210]['id'])['then'](function(_0x2f94d4){const _0x40bfbc=_0x413ef1;if(_0x2f94d4&&!_0x2f94d4['voicePause']){logger['info']('[%s][START][AGENT:%s][QUEUE:%s]',_0x241d4c,_0x5c6210,_0x1cd8e5);const _0x1dba78=_0x19268b['channels'][_0x241d4c][_0x40bfbc(0x15f)]&&_0x19268b[_0x40bfbc(0x104)][_0x241d4c][_0x40bfbc(0x10a)]?_0x19268b[_0x40bfbc(0x104)][_0x241d4c][_0x40bfbc(0x10a)]:_0x241d4c;return RpcUser[_0x40bfbc(0x153)](_0x19268b[_0x40bfbc(0x138)][_0x5c6210],_0x1efbc1,_0x1dba78)['then'](function(){const _0x515fee=_0x40bfbc;!_0x1d7b64&&(_0x19268b[_0x515fee(0x121)][_0x5c6210]={},logger[_0x515fee(0x15d)](_0x515fee(0x115),_0x241d4c,_0x19268b[_0x515fee(0x155)][_0x1cd8e5]['acwTimeout'],_0x5c6210,_0x1cd8e5),_0x19268b[_0x515fee(0x121)][_0x5c6210][_0x515fee(0x156)]=setTimeout(_0x19268b[_0x515fee(0x120)][_0x515fee(0x142)](_0x19268b,_0x5c6210),_0x19268b[_0x515fee(0x155)][_0x1cd8e5]['acwTimeout']*0x3e8),_0x19268b[_0x515fee(0x121)][_0x5c6210][_0x515fee(0x143)]=moment()[_0x515fee(0x144)](_0x515fee(0x13e)),_0x19268b[_0x515fee(0x121)][_0x5c6210]['uniqueid']=_0x241d4c,_0x19268b[_0x515fee(0x121)][_0x5c6210][_0x515fee(0x117)]=_0x1cd8e5,_0x19268b[_0x515fee(0x121)][_0x5c6210]['updateAcw']=function(){const _0x307bd6=_0x515fee,_0x5c3a3b=getDiff(_0x19268b['timers'][_0x5c6210][_0x307bd6(0x143)]);clearTimeout(_0x19268b[_0x307bd6(0x121)][_0x5c6210][_0x307bd6(0x156)]),_0x19268b[_0x307bd6(0x121)][_0x5c6210][_0x307bd6(0x156)]=![],RpcVoiceAgentReport[_0x307bd6(0x130)]({'acwtime':_0x5c3a3b},_0x19268b['timers'][_0x5c6210][_0x307bd6(0x13f)],_0x5c6210)['then'](function(_0x4c0c91){const _0x1c8ee2=_0x307bd6;logger[_0x1c8ee2(0x15d)](_0x1c8ee2(0x113),_0x241d4c,_0x5c3a3b,_0x4c0c91);})[_0x307bd6(0x151)](function(_0x228f78){const _0x49bd3d=_0x307bd6;logger['error'](_0x49bd3d(0x150),_0x241d4c,_0x228f78);}),delete _0x19268b['timers'][_0x5c6210];});});}else logger[_0x40bfbc(0x15d)]('[%s][INPAUSE][AGENT:%s][QUEUE:%s]',_0x241d4c,_0x5c6210,_0x1cd8e5);});})[_0x1e2126(0x151)](function(){const _0x2948e7=_0x1e2126;logger['error']('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x241d4c,_0x19268b[_0x2948e7(0x155)][_0x1cd8e5][_0x2948e7(0x107)],_0x5c6210,_0x1cd8e5);})['finally'](function(){const _0x39ac28=_0x1e2126;delete _0x19268b[_0x39ac28(0x104)][_0x241d4c];});}catch(_0x2d5e9b){logger[_0x1e2126(0x137)](_0x1e2126(0x158),_0x2d5e9b['message']);}},Acw['prototype'][a1241_0x2461b4(0x120)]=function(_0x4a0f13){const _0x6983a7=a1241_0x2461b4;try{const _0x194f0b=this;if(_0x194f0b[_0x6983a7(0x121)][_0x4a0f13]){_0x194f0b[_0x6983a7(0x121)][_0x4a0f13][_0x6983a7(0x156)]=![];const _0xc92f15=_0x194f0b[_0x6983a7(0x121)][_0x4a0f13]['uniqueid'],_0x495e77=_0x194f0b[_0x6983a7(0x121)][_0x4a0f13][_0x6983a7(0x117)],_0xf8d19=_0x194f0b[_0x6983a7(0x155)][_0x495e77][_0x6983a7(0x107)];logger[_0x6983a7(0x15d)](_0x6983a7(0x14f),_0xc92f15,_0x4a0f13),RpcUser[_0x6983a7(0x15e)](this[_0x6983a7(0x138)][_0x4a0f13]),RpcVoiceAgentReport[_0x6983a7(0x130)]({'acwtime':_0xf8d19,'agentacw':!![]},_0xc92f15,_0x4a0f13)[_0x6983a7(0x124)](function(_0x4a54aa){const _0x12fa52=_0x6983a7;logger[_0x12fa52(0x15d)](_0x12fa52(0x113),_0xc92f15,_0xf8d19,_0x4a54aa);})[_0x6983a7(0x151)](function(_0x18a6f0){const _0x2325c3=_0x6983a7;logger['error'](_0x2325c3(0x150),_0xc92f15,_0x18a6f0);});}else logger['error']('[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer',_0x4a0f13),_0x194f0b[_0x6983a7(0x121)]&&logger[_0x6983a7(0x15d)](_0x6983a7(0x132),JSON[_0x6983a7(0x14e)](_0x194f0b[_0x6983a7(0x121)]));}catch(_0x3b70ad){logger[_0x6983a7(0x137)]('[ACW][STOP]\x20%s',_0x3b70ad[_0x6983a7(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x110)]=function(_0x83931a){const _0x43da55=a1241_0x2461b4;try{this[_0x43da55(0x155)][_0x83931a[_0x43da55(0x117)]]&&(this[_0x43da55(0x155)][_0x83931a['queue']][_0x43da55(0x148)]||this[_0x43da55(0x155)][_0x83931a[_0x43da55(0x117)]][_0x43da55(0x12c)])&&(this[_0x43da55(0x138)][_0x83931a[_0x43da55(0x12f)]]&&(this[_0x43da55(0x104)][_0x83931a[_0x43da55(0x13f)]]={'queue':_0x83931a[_0x43da55(0x117)],'interface':_0x83931a['interface'],'destlinkedid':_0x83931a[_0x43da55(0x10a)]}));}catch(_0x321ffc){logger[_0x43da55(0x137)](_0x43da55(0x149),_0x321ffc[_0x43da55(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x13c)]=function(_0x2fabc9){const _0x69d995=a1241_0x2461b4;try{this['voiceQueues'][_0x2fabc9[_0x69d995(0x117)]]&&(this[_0x69d995(0x155)][_0x2fabc9[_0x69d995(0x117)]][_0x69d995(0x148)]||this['voiceQueues'][_0x2fabc9[_0x69d995(0x117)]]['mandatoryDisposition'])&&(this[_0x69d995(0x138)][_0x2fabc9[_0x69d995(0x12f)]]&&(this[_0x69d995(0x104)][_0x2fabc9['uniqueid']]={'queue':_0x2fabc9[_0x69d995(0x117)],'interface':_0x2fabc9[_0x69d995(0x12f)]}));}catch(_0x15af83){logger[_0x69d995(0x137)](_0x69d995(0x123),_0x15af83[_0x69d995(0x12d)]);}},Acw[a1241_0x2461b4(0x131)]['syncHangupRequest']=function(_0x83fa93){const _0xbf53f8=a1241_0x2461b4;try{if(this['channels'][_0x83fa93[_0xbf53f8(0x13f)]]&&_[_0xbf53f8(0x11b)](this[_0xbf53f8(0x104)][_0x83fa93[_0xbf53f8(0x13f)]][_0xbf53f8(0x15f)]))logger[_0xbf53f8(0x15d)]('[%s][HANGUP:UNIQUEID]',_0x83fa93['uniqueid']),this[_0xbf53f8(0x15a)](_0x83fa93[_0xbf53f8(0x13f)]);else this[_0xbf53f8(0x104)][_0x83fa93['linkedid']]&&_['isUndefined'](this[_0xbf53f8(0x104)][_0x83fa93['linkedid']][_0xbf53f8(0x15f)])&&(logger[_0xbf53f8(0x15d)](_0xbf53f8(0x141),_0x83fa93[_0xbf53f8(0x136)]),this[_0xbf53f8(0x15a)](_0x83fa93[_0xbf53f8(0x136)]));}catch(_0x194ee7){logger[_0xbf53f8(0x137)](_0xbf53f8(0x135),_0x194ee7[_0xbf53f8(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x11f)]=function(_0x88c737){const _0x105fa4=a1241_0x2461b4;try{if(this['channels'][_0x88c737[_0x105fa4(0x13f)]]&&this['channels'][_0x88c737[_0x105fa4(0x13f)]][_0x105fa4(0x15f)])logger[_0x105fa4(0x15d)](_0x105fa4(0x157),_0x88c737[_0x105fa4(0x13f)]),this[_0x105fa4(0x15a)](_0x88c737[_0x105fa4(0x13f)]);else this['channels'][_0x88c737[_0x105fa4(0x136)]]&&this[_0x105fa4(0x104)][_0x88c737[_0x105fa4(0x136)]][_0x105fa4(0x15f)]&&(logger[_0x105fa4(0x15d)](_0x105fa4(0x109),_0x88c737[_0x105fa4(0x136)]),this[_0x105fa4(0x15a)](_0x88c737[_0x105fa4(0x136)]));}catch(_0x24059f){logger['error']('[ACW][syncHangup]\x20%s',_0x24059f[_0x105fa4(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x10c)]=function(_0x59fd39){const _0x33804e=a1241_0x2461b4;try{if(!_[_0x33804e(0x127)](this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x11c)]]))this[_0x33804e(0x15a)](_0x59fd39[_0x33804e(0x11c)]),this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x114)]]&&(this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x114)]][_0x33804e(0x15f)]=!![],this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x12a)]]=this[_0x33804e(0x104)][_0x59fd39['secondtransfereruniqueid']],delete this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x114)]]);else!_[_0x33804e(0x127)](this['channels'][_0x59fd39[_0x33804e(0x12a)]])&&(this[_0x33804e(0x15a)](_0x59fd39[_0x33804e(0x12a)]),this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x160)]]&&(this['channels'][_0x59fd39[_0x33804e(0x160)]][_0x33804e(0x15f)]=!![],this['channels'][_0x59fd39[_0x33804e(0x11c)]]=this[_0x33804e(0x104)][_0x59fd39[_0x33804e(0x160)]],delete this[_0x33804e(0x104)][_0x59fd39['origtransfereruniqueid']]));}catch(_0x12b892){logger[_0x33804e(0x137)](_0x33804e(0x103),_0x12b892[_0x33804e(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x139)]=function(_0x5cba88){const _0x5db5f1=a1241_0x2461b4;try{if(this[_0x5db5f1(0x104)][_0x5cba88[_0x5db5f1(0x119)]])logger[_0x5db5f1(0x15d)](_0x5db5f1(0x108),JSON['stringify'](_0x5cba88[_0x5db5f1(0x119)])),this[_0x5db5f1(0x15a)](_0x5cba88['transfereruniqueid']);else this['channels'][_0x5cba88[_0x5db5f1(0x14d)]]&&(logger[_0x5db5f1(0x15d)]('[%s][BLINDTRANSFER:LINKEDID]',JSON[_0x5db5f1(0x14e)](_0x5cba88[_0x5db5f1(0x14d)])),this[_0x5db5f1(0x15a)](_0x5cba88[_0x5db5f1(0x14d)]));}catch(_0x541c89){logger['error'](_0x5db5f1(0x14b),_0x541c89[_0x5db5f1(0x12d)]);}},Acw[a1241_0x2461b4(0x131)][a1241_0x2461b4(0x102)]=function(_0x32d488){const _0x280743=a1241_0x2461b4;try{if(this[_0x280743(0x155)][_0x32d488[_0x280743(0x117)]]&&this[_0x280743(0x155)][_0x32d488[_0x280743(0x117)]][_0x280743(0x159)]===_0x280743(0x10d)){if(this[_0x280743(0x138)][_0x32d488[_0x280743(0x12f)]])return logger[_0x280743(0x15d)](_0x280743(0x154),_0x32d488[_0x280743(0x13f)],_0x32d488[_0x280743(0x12f)],_0x32d488[_0x280743(0x117)]),RpcUser[_0x280743(0x153)](this[_0x280743(0x138)][_0x32d488[_0x280743(0x12f)]],'Auto-Pause',_0x32d488['uniqueid']);}}catch(_0xc25d77){logger['error'](_0x280743(0x13d),_0xc25d77[_0x280743(0x12d)]);}},module[a1241_0x2461b4(0x122)]=Acw;