Built motion from commit dbf3a7e2.|2.6.30
[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 _0x269c=['QueuePause','getAgent','voicePause','info','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','[%s][START][AGENT:%s][QUEUE:%s]','destlinkedid','savePause','paused','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','stopAcw','format','YYYY-MM-DD\x20HH:mm:ss','uniqueid','acwTimeout','message','[%s][TIMER][STOP][AGENT:%s]','pauseType','saveUnpause','[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer','[ACW][TIMERS]','acw','mandatoryDisposition','interface','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','linkedid','attended','[%s][HANGUP:LINKEDID]','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','syncAttendedTransfer','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','deleteChannelAfterTimeout','[ACW][syncAttendedTransfer]\x20%s','[%s][BLINDTRANSFER:UNIQUEID]','transfereruniqueid','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','[ACW][syncBlindTransfer]\x20%s','autopause','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s','lodash','moment','../../../config/logger','../rpc/voiceAgentReport','voiceQueues','agents','timers','channels','agentconnect','syncAgentConnect','bind','hanguprequest','syncHangupRequest','hangup','syncHangup','agentringnoanswer','syncAgentRingNoAnswer','blindtransfer','custom:agentConnectPreview','milliseconds','diff','seconds','prototype','updateAcw','lastPauseAt','timer','update','then','[%s][UPDATE][ACWTIME:%s]','catch','error','[%s][UPDATE][ERRORS:%s]','finally','startAcw','queue','ACW','mandatoryDispositionPause','name','Action'];(function(_0x5cb89a,_0x3f108e){var _0x39181f=function(_0xe78bbf){while(--_0xe78bbf){_0x5cb89a['push'](_0x5cb89a['shift']());}};_0x39181f(++_0x3f108e);}(_0x269c,0x1ef));var _0xc269=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x269c[_0x20a584];return _0x4b41a8;};'use strict';var _=require(_0xc269('0x0'));var moment=require(_0xc269('0x1'));var ami=require('../ami');var logger=require(_0xc269('0x2'))('acw');var RpcUser=require('../rpc/user');var RpcVoiceAgentReport=require(_0xc269('0x3'));function Acw(_0x4be9a7){this[_0xc269('0x4')]=_0x4be9a7['voiceQueues'];this['agents']=_0x4be9a7[_0xc269('0x5')];this[_0xc269('0x6')]=_0x4be9a7[_0xc269('0x6')];this[_0xc269('0x7')]={};ami['on'](_0xc269('0x8'),this[_0xc269('0x9')][_0xc269('0xa')](this));ami['on'](_0xc269('0xb'),this[_0xc269('0xc')]['bind'](this));ami['on'](_0xc269('0xd'),this[_0xc269('0xe')][_0xc269('0xa')](this));ami['on'](_0xc269('0xf'),this[_0xc269('0x10')][_0xc269('0xa')](this));ami['on']('attendedtransfer',this['syncAttendedTransfer']['bind'](this));ami['on'](_0xc269('0x11'),this['syncBlindTransfer']['bind'](this));ami['on'](_0xc269('0x12'),this['syncAgentConnectPreview'][_0xc269('0xa')](this));}function getDiff(_0x366561){var _0x37b325=moment()[_0xc269('0x13')](0x0);var _0xe60d56=moment(_0x366561)[_0xc269('0x13')](0x0);return _0x37b325[_0xc269('0x14')](_0xe60d56,_0xc269('0x15'));}Acw[_0xc269('0x16')][_0xc269('0x17')]=function(_0x1b74e7,_0x18b89b){var _0x329e7a=this;var _0x391cea=getDiff(_0x329e7a['timers'][_0x1b74e7][_0xc269('0x18')]);clearTimeout(_0x329e7a[_0xc269('0x6')][_0x1b74e7][_0xc269('0x19')]);_0x329e7a[_0xc269('0x6')][_0x1b74e7][_0xc269('0x19')]=![];return RpcVoiceAgentReport[_0xc269('0x1a')]({'acwtime':_0x391cea},_0x329e7a[_0xc269('0x6')][_0x1b74e7]['uniqueid'],_0x1b74e7)[_0xc269('0x1b')](function(_0x3bb219){logger['info'](_0xc269('0x1c'),_0x18b89b,_0x391cea,_0x3bb219);})[_0xc269('0x1d')](function(_0x38af59){logger[_0xc269('0x1e')](_0xc269('0x1f'),_0x18b89b,_0x38af59);})[_0xc269('0x20')](function(){delete _0x329e7a['timers'][_0x1b74e7];});};Acw['prototype'][_0xc269('0x21')]=function(_0x5de1fd){try{var _0x175a5a=this;var _0x46afb3=this['channels'][_0x5de1fd]['interface'];var _0x1cf120=this[_0xc269('0x7')][_0x5de1fd][_0xc269('0x22')];var _0x13643f=this[_0xc269('0x4')][_0x1cf120];var _0x4560b0=![];var _0x33cd6f=_0xc269('0x23');if(_0x13643f['mandatoryDisposition']&&_0x13643f[_0xc269('0x24')][_0xc269('0x25')]){_0x4560b0=!![];_0x33cd6f=_0x13643f[_0xc269('0x24')][_0xc269('0x25')];}return ami[_0xc269('0x26')]({'action':_0xc269('0x27'),'interface':_0x46afb3,'paused':!![],'reason':_0x33cd6f})[_0xc269('0x1b')](function(){if(_0x175a5a[_0xc269('0x5')][_0x46afb3]){return RpcUser[_0xc269('0x28')](_0x175a5a[_0xc269('0x5')][_0x46afb3]['id'])[_0xc269('0x1b')](function(_0xe8a7b2){if(!_0xe8a7b2||_0xe8a7b2[_0xc269('0x29')]){logger[_0xc269('0x2a')](_0xc269('0x2b'),_0x5de1fd,_0x46afb3,_0x1cf120);return;}logger[_0xc269('0x2a')](_0xc269('0x2c'),_0x5de1fd,_0x46afb3,_0x1cf120);var _0x3d64b8=_0x175a5a[_0xc269('0x7')][_0x5de1fd]['attended']&&_0x175a5a[_0xc269('0x7')][_0x5de1fd]['destlinkedid']?_0x175a5a['channels'][_0x5de1fd][_0xc269('0x2d')]:_0x5de1fd;return RpcUser[_0xc269('0x2e')](_0x175a5a[_0xc269('0x5')][_0x46afb3],_0x33cd6f,_0x3d64b8)[_0xc269('0x1b')](function(_0x484568){_0x175a5a['voiceQueues'][_0x1cf120]['available']-=0x1;_0x175a5a[_0xc269('0x4')][_0x1cf120][_0xc269('0x2f')]+=0x1;return _0x484568;});})[_0xc269('0x1b')](function(_0x6542a5){if(_0x4560b0||!_0x6542a5){return;}_0x175a5a[_0xc269('0x6')][_0x46afb3]={};logger[_0xc269('0x2a')](_0xc269('0x30'),_0x5de1fd,_0x175a5a[_0xc269('0x4')][_0x1cf120]['acwTimeout'],_0x46afb3,_0x1cf120);_0x175a5a[_0xc269('0x6')][_0x46afb3][_0xc269('0x19')]=setTimeout(_0x175a5a[_0xc269('0x31')][_0xc269('0xa')](_0x175a5a,_0x46afb3),_0x175a5a[_0xc269('0x4')][_0x1cf120]['acwTimeout']*0x3e8);_0x175a5a[_0xc269('0x6')][_0x46afb3][_0xc269('0x18')]=moment()[_0xc269('0x32')](_0xc269('0x33'));_0x175a5a[_0xc269('0x6')][_0x46afb3][_0xc269('0x34')]=_0x5de1fd;_0x175a5a[_0xc269('0x6')][_0x46afb3][_0xc269('0x22')]=_0x1cf120;_0x175a5a[_0xc269('0x6')][_0x46afb3][_0xc269('0x17')]=_0x175a5a['updateAcw'][_0xc269('0xa')](_0x175a5a,_0x46afb3,_0x5de1fd);});}})[_0xc269('0x1d')](function(){logger['error'](_0xc269('0x30'),_0x5de1fd,_0x175a5a[_0xc269('0x4')][_0x1cf120][_0xc269('0x35')],_0x46afb3,_0x1cf120);})[_0xc269('0x20')](function(){delete _0x175a5a['channels'][_0x5de1fd];});}catch(_0x20ebb2){logger[_0xc269('0x1e')]('[ACW][START]\x20%s',_0x20ebb2[_0xc269('0x36')]);}};Acw[_0xc269('0x16')][_0xc269('0x31')]=function(_0x4a41f5){try{var _0x271eeb=this;if(_0x271eeb[_0xc269('0x6')][_0x4a41f5]){_0x271eeb[_0xc269('0x6')][_0x4a41f5][_0xc269('0x19')]=![];var _0x1f7533=_0x271eeb[_0xc269('0x6')][_0x4a41f5][_0xc269('0x34')];var _0xe1f46d=_0x271eeb[_0xc269('0x6')][_0x4a41f5][_0xc269('0x22')];var _0x1fadb8=_0x271eeb[_0xc269('0x4')][_0xe1f46d][_0xc269('0x35')];logger['info'](_0xc269('0x37'),_0x1f7533,_0x4a41f5);RpcUser[_0xc269('0x28')](this[_0xc269('0x5')][_0x4a41f5]['id'])['then'](function(_0x5b2984){if(_0x5b2984[_0xc269('0x38')]===_0xc269('0x23')){return RpcUser[_0xc269('0x39')](_0x271eeb[_0xc269('0x5')][_0x4a41f5]);}});RpcVoiceAgentReport['update']({'acwtime':_0x1fadb8,'agentacw':!![]},_0x1f7533,_0x4a41f5)[_0xc269('0x1b')](function(_0x1b4420){logger[_0xc269('0x2a')](_0xc269('0x1c'),_0x1f7533,_0x1fadb8,_0x1b4420);})['catch'](function(_0x56f7af){logger['error']('[%s][UPDATE][ERRORS:%s]',_0x1f7533,_0x56f7af);});}else{logger[_0xc269('0x1e')](_0xc269('0x3a'),_0x4a41f5);if(_0x271eeb[_0xc269('0x6')]){logger[_0xc269('0x2a')](_0xc269('0x3b'),JSON['stringify'](_0x271eeb['timers']));}}}catch(_0x32a409){logger[_0xc269('0x1e')]('[ACW][STOP]\x20%s',_0x32a409[_0xc269('0x36')]);}};Acw[_0xc269('0x16')][_0xc269('0x9')]=function(_0x8404a){try{if(this[_0xc269('0x4')][_0x8404a[_0xc269('0x22')]]&&(this[_0xc269('0x4')][_0x8404a['queue']][_0xc269('0x3c')]||this[_0xc269('0x4')][_0x8404a['queue']][_0xc269('0x3d')])){if(this[_0xc269('0x5')][_0x8404a['interface']]){this[_0xc269('0x7')][_0x8404a[_0xc269('0x34')]]={'queue':_0x8404a[_0xc269('0x22')],'interface':_0x8404a[_0xc269('0x3e')],'destlinkedid':_0x8404a[_0xc269('0x2d')]};}}}catch(_0x240066){logger[_0xc269('0x1e')](_0xc269('0x3f'),_0x240066[_0xc269('0x36')]);}};Acw['prototype']['syncAgentConnectPreview']=function(_0x263e42){try{if(this['voiceQueues'][_0x263e42[_0xc269('0x22')]]&&(this[_0xc269('0x4')][_0x263e42[_0xc269('0x22')]][_0xc269('0x3c')]||this['voiceQueues'][_0x263e42[_0xc269('0x22')]]['mandatoryDisposition'])){if(this[_0xc269('0x5')][_0x263e42[_0xc269('0x3e')]]){this[_0xc269('0x7')][_0x263e42[_0xc269('0x34')]]={'queue':_0x263e42['queue'],'interface':_0x263e42[_0xc269('0x3e')]};}}}catch(_0x4af85f){logger[_0xc269('0x1e')](_0xc269('0x40'),_0x4af85f[_0xc269('0x36')]);}};Acw['prototype'][_0xc269('0xc')]=function(_0x1a57cf){try{if(this['channels'][_0x1a57cf[_0xc269('0x34')]]&&_['isUndefined'](this['channels'][_0x1a57cf[_0xc269('0x34')]]['attended'])){logger[_0xc269('0x2a')]('[%s][HANGUP:UNIQUEID]',_0x1a57cf['uniqueid']);this[_0xc269('0x21')](_0x1a57cf[_0xc269('0x34')]);}else if(this['channels'][_0x1a57cf[_0xc269('0x41')]]&&_['isUndefined'](this['channels'][_0x1a57cf[_0xc269('0x41')]][_0xc269('0x42')])){logger['info'](_0xc269('0x43'),_0x1a57cf[_0xc269('0x41')]);this['startAcw'](_0x1a57cf['linkedid']);}}catch(_0x28e597){logger['error'](_0xc269('0x44'),_0x28e597[_0xc269('0x36')]);}};Acw[_0xc269('0x16')][_0xc269('0xe')]=function(_0x1acf76){try{if(this[_0xc269('0x7')][_0x1acf76[_0xc269('0x34')]]&&this[_0xc269('0x7')][_0x1acf76['uniqueid']][_0xc269('0x42')]){logger[_0xc269('0x2a')]('[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]',_0x1acf76[_0xc269('0x34')]);this[_0xc269('0x21')](_0x1acf76[_0xc269('0x34')]);}else if(this[_0xc269('0x7')][_0x1acf76[_0xc269('0x41')]]&&this[_0xc269('0x7')][_0x1acf76[_0xc269('0x41')]][_0xc269('0x42')]){logger['info'](_0xc269('0x45'),_0x1acf76['linkedid']);this[_0xc269('0x21')](_0x1acf76[_0xc269('0x41')]);}}catch(_0xfe8e09){logger[_0xc269('0x1e')](_0xc269('0x46'),_0xfe8e09[_0xc269('0x36')]);}};Acw[_0xc269('0x16')][_0xc269('0x47')]=function(_0x4e4f23){try{if(!_[_0xc269('0x48')](this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x49')]])){this[_0xc269('0x21')](_0x4e4f23[_0xc269('0x49')]);if(this['channels'][_0x4e4f23[_0xc269('0x4a')]]){this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x4a')]][_0xc269('0x42')]=!![];this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x4b')]]=this['channels'][_0x4e4f23[_0xc269('0x4a')]];this['deleteChannelAfterTimeout'](_0x4e4f23[_0xc269('0x4a')]);}}else if(!_['isNil'](this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x4b')]])){this['startAcw'](_0x4e4f23[_0xc269('0x4b')]);if(this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x4c')]]){this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x4c')]][_0xc269('0x42')]=!![];this[_0xc269('0x7')][_0x4e4f23[_0xc269('0x49')]]=this['channels'][_0x4e4f23['origtransfereruniqueid']];this[_0xc269('0x4d')](_0x4e4f23[_0xc269('0x4c')]);}}}catch(_0x297837){logger[_0xc269('0x1e')](_0xc269('0x4e'),_0x297837['message']);}};Acw['prototype']['syncBlindTransfer']=function(_0x11c465){try{if(this['channels'][_0x11c465['transfereruniqueid']]){logger['info'](_0xc269('0x4f'),JSON['stringify'](_0x11c465[_0xc269('0x50')]));this[_0xc269('0x21')](_0x11c465[_0xc269('0x50')]);}else if(this[_0xc269('0x7')][_0x11c465[_0xc269('0x51')]]){logger['info'](_0xc269('0x52'),JSON['stringify'](_0x11c465[_0xc269('0x51')]));this[_0xc269('0x21')](_0x11c465[_0xc269('0x51')]);}}catch(_0x2f19d2){logger[_0xc269('0x1e')](_0xc269('0x53'),_0x2f19d2[_0xc269('0x36')]);}};Acw['prototype'][_0xc269('0x10')]=function(_0x30db49){try{if(this[_0xc269('0x4')][_0x30db49[_0xc269('0x22')]]&&this[_0xc269('0x4')][_0x30db49[_0xc269('0x22')]][_0xc269('0x54')]===_0xc269('0x55')){if(this[_0xc269('0x5')][_0x30db49[_0xc269('0x3e')]]){logger[_0xc269('0x2a')](_0xc269('0x56'),_0x30db49[_0xc269('0x34')],_0x30db49['interface'],_0x30db49[_0xc269('0x22')]);return RpcUser[_0xc269('0x2e')](this[_0xc269('0x5')][_0x30db49[_0xc269('0x3e')]],_0xc269('0x57'),_0x30db49[_0xc269('0x34')]);}}}catch(_0x4d6748){logger['error'](_0xc269('0x58'),_0x4d6748[_0xc269('0x36')]);}};Acw['prototype'][_0xc269('0x4d')]=function(_0x411aa9,_0x59e548=0x2710){if(this[_0xc269('0x7')][_0x411aa9]){setTimeout(()=>{delete this[_0xc269('0x7')][_0x411aa9];},_0x59e548);}};module['exports']=Acw;