31978acaa78baf24c14bce763670cf9f7deb1ed3
[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 _0xa630=['transfertargetuniqueid','isNil','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','[ACW][syncBlindTransfer]\x20%s','autopause','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','savePause','Auto-Pause','util','lodash','../../../config/logger','../rpc/user','voiceQueues','agents','timers','channels','agentconnect','syncAgentConnect','bind','hanguprequest','hangup','syncHangup','agentringnoanswer','syncAgentRingNoAnswer','attendedtransfer','syncAttendedTransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','seconds','prototype','startAcw','interface','queue','ACW','mandatoryDisposition','mandatoryDispositionPause','name','QueuePause','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','uniqueid','updateAcw','timer','update','then','[%s][UPDATE][ACWTIME:%s]','error','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','[ACW][START]\x20%s','message','[TIMER][STOP][AGENT:%s]','saveUnpause','[%s][UPDATE][ERRORS:%s]','[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer','[ACW][TIMERS]','stringify','[ACW][STOP]\x20%s','acw','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','syncHangupRequest','isUndefined','[%s][HANGUP:UNIQUEID]','linkedid','[%s][HANGUP:LINKEDID]','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[ACW][syncHangup]\x20%s','transfereeuniqueid','secondtransfereruniqueid'];(function(_0x115621,_0x341cde){var _0x5ef5ce=function(_0x2ca3f2){while(--_0x2ca3f2){_0x115621['push'](_0x115621['shift']());}};_0x5ef5ce(++_0x341cde);}(_0xa630,0xbe));var _0x0a63=function(_0x5ceb89,_0x1f5f0c){_0x5ceb89=_0x5ceb89-0x0;var _0x12f582=_0xa630[_0x5ceb89];return _0x12f582;};'use strict';var util=require(_0x0a63('0x0'));var _=require(_0x0a63('0x1'));var moment=require('moment');var ami=require('../ami');var logger=require(_0x0a63('0x2'))('acw');var RpcUser=require(_0x0a63('0x3'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x91a747){this[_0x0a63('0x4')]=_0x91a747[_0x0a63('0x4')];this[_0x0a63('0x5')]=_0x91a747[_0x0a63('0x5')];this['timers']=_0x91a747[_0x0a63('0x6')];this[_0x0a63('0x7')]={};ami['on'](_0x0a63('0x8'),this[_0x0a63('0x9')][_0x0a63('0xa')](this));ami['on'](_0x0a63('0xb'),this['syncHangupRequest'][_0x0a63('0xa')](this));ami['on'](_0x0a63('0xc'),this[_0x0a63('0xd')][_0x0a63('0xa')](this));ami['on'](_0x0a63('0xe'),this[_0x0a63('0xf')][_0x0a63('0xa')](this));ami['on'](_0x0a63('0x10'),this[_0x0a63('0x11')][_0x0a63('0xa')](this));ami['on']('blindtransfer',this[_0x0a63('0x12')][_0x0a63('0xa')](this));ami['on'](_0x0a63('0x13'),this[_0x0a63('0x14')]['bind'](this));}function getDiff(_0x23f655){var _0x4d68c0=moment()[_0x0a63('0x15')](0x0);var _0x19e922=moment(_0x23f655)[_0x0a63('0x15')](0x0);return _0x4d68c0[_0x0a63('0x16')](_0x19e922,_0x0a63('0x17'));}Acw[_0x0a63('0x18')][_0x0a63('0x19')]=function(_0x1e3251){try{var _0x524a98=this;var _0x47788e=this['channels'][_0x1e3251][_0x0a63('0x1a')];var _0x292170=this[_0x0a63('0x7')][_0x1e3251][_0x0a63('0x1b')];var _0x1f7481=this[_0x0a63('0x4')][_0x292170];var _0x30f292=![];var _0x374c52=_0x0a63('0x1c');if(_0x1f7481[_0x0a63('0x1d')]){if(_0x1f7481[_0x0a63('0x1e')]['name']){_0x30f292=!![];_0x374c52=_0x1f7481['mandatoryDispositionPause'][_0x0a63('0x1f')];}}ami['Action']({'action':_0x0a63('0x20'),'interface':_0x47788e,'paused':!![],'reason':_0x374c52})['then'](function(_0x58513d){if(_0x524a98[_0x0a63('0x5')][_0x47788e]){return RpcUser[_0x0a63('0x21')](_0x524a98[_0x0a63('0x5')][_0x47788e]['id'])['then'](function(_0x398a16){if(_0x398a16&&!_0x398a16['voicePause']){logger[_0x0a63('0x22')](_0x0a63('0x23'),_0x1e3251,_0x47788e,_0x292170);var _0x1bf64a=_0x524a98[_0x0a63('0x7')][_0x1e3251][_0x0a63('0x24')]&&_0x524a98[_0x0a63('0x7')][_0x1e3251][_0x0a63('0x25')]?_0x524a98[_0x0a63('0x7')][_0x1e3251]['destlinkedid']:_0x1e3251;return RpcUser['savePause'](_0x524a98['agents'][_0x47788e],_0x374c52,_0x1bf64a)['then'](function(_0xeacfc9){if(!_0x30f292){_0x524a98['timers'][_0x47788e]={};logger['info'](_0x0a63('0x26'),_0x1e3251,_0x524a98[_0x0a63('0x4')][_0x292170][_0x0a63('0x27')],_0x47788e,_0x292170);_0x524a98[_0x0a63('0x6')][_0x47788e]['timer']=setTimeout(_0x524a98[_0x0a63('0x28')][_0x0a63('0xa')](_0x524a98,_0x47788e),_0x524a98[_0x0a63('0x4')][_0x292170]['acwTimeout']*0x3e8);_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x29')]=moment()[_0x0a63('0x2a')](_0x0a63('0x2b'));_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x2c')]=_0x1e3251;_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x1b')]=_0x292170;_0x524a98['timers'][_0x47788e][_0x0a63('0x2d')]=function(){var _0x574c06=getDiff(_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x29')]);clearTimeout(_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x2e')]);_0x524a98[_0x0a63('0x6')][_0x47788e]['timer']=![];RpcVoiceAgentReport[_0x0a63('0x2f')]({'acwtime':_0x574c06},_0x524a98[_0x0a63('0x6')][_0x47788e][_0x0a63('0x2c')],_0x47788e)[_0x0a63('0x30')](function(_0x59d06c){logger[_0x0a63('0x22')](_0x0a63('0x31'),_0x1e3251,_0x574c06,_0x59d06c);})['catch'](function(_0x4a7145){logger[_0x0a63('0x32')]('[%s][UPDATE][ERRORS:%s]',_0x1e3251,_0x4a7145);});delete _0x524a98['timers'][_0x47788e];};}});}else{logger[_0x0a63('0x22')](_0x0a63('0x33'),_0x1e3251,_0x47788e,_0x292170);}});}})['catch'](function(_0xfd1e09){logger[_0x0a63('0x32')](_0x0a63('0x26'),_0x1e3251,_0x524a98[_0x0a63('0x4')][_0x292170][_0x0a63('0x27')],_0x47788e,_0x292170);})['finally'](function(){delete _0x524a98['channels'][_0x1e3251];});}catch(_0x22993d){logger[_0x0a63('0x32')](_0x0a63('0x34'),_0x22993d[_0x0a63('0x35')]);}};Acw[_0x0a63('0x18')][_0x0a63('0x28')]=function(_0x59912d){try{var _0x307fe2=this;if(_0x307fe2[_0x0a63('0x6')][_0x59912d]){_0x307fe2['timers'][_0x59912d][_0x0a63('0x2e')]=![];var _0x5b62b7=_0x307fe2['timers'][_0x59912d][_0x0a63('0x2c')];var _0x232388=_0x307fe2[_0x0a63('0x6')][_0x59912d]['queue'];var _0x209447=_0x307fe2[_0x0a63('0x4')][_0x232388][_0x0a63('0x27')];logger[_0x0a63('0x22')](_0x0a63('0x36'),_0x59912d);RpcUser[_0x0a63('0x37')](this[_0x0a63('0x5')][_0x59912d]);RpcVoiceAgentReport['update']({'acwtime':_0x209447,'agentacw':!![]},_0x5b62b7,_0x59912d)[_0x0a63('0x30')](function(_0x1c7e67){logger[_0x0a63('0x22')]('[%s][UPDATE][ACWTIME:%s]',_0x5b62b7,_0x209447,_0x1c7e67);})['catch'](function(_0x28f904){logger['error'](_0x0a63('0x38'),_0x5b62b7,_0x28f904);});}else{logger[_0x0a63('0x32')](_0x0a63('0x39'),_0x59912d);if(_0x307fe2['timers']){logger[_0x0a63('0x22')](_0x0a63('0x3a'),JSON[_0x0a63('0x3b')](_0x307fe2[_0x0a63('0x6')]));}}}catch(_0x5d94e2){logger[_0x0a63('0x32')](_0x0a63('0x3c'),_0x5d94e2[_0x0a63('0x35')]);}};Acw[_0x0a63('0x18')][_0x0a63('0x9')]=function(_0x38cfe4){try{if(this['voiceQueues'][_0x38cfe4[_0x0a63('0x1b')]]&&(this[_0x0a63('0x4')][_0x38cfe4[_0x0a63('0x1b')]][_0x0a63('0x3d')]||this[_0x0a63('0x4')][_0x38cfe4[_0x0a63('0x1b')]][_0x0a63('0x1d')])){if(this[_0x0a63('0x5')][_0x38cfe4[_0x0a63('0x1a')]]){this[_0x0a63('0x7')][_0x38cfe4[_0x0a63('0x2c')]]={'queue':_0x38cfe4[_0x0a63('0x1b')],'interface':_0x38cfe4[_0x0a63('0x1a')],'destlinkedid':_0x38cfe4[_0x0a63('0x25')]};}}}catch(_0x364a89){logger[_0x0a63('0x32')](_0x0a63('0x3e'),_0x364a89[_0x0a63('0x35')]);}};Acw['prototype'][_0x0a63('0x14')]=function(_0x5ef4e9){try{if(this['voiceQueues'][_0x5ef4e9[_0x0a63('0x1b')]]&&(this[_0x0a63('0x4')][_0x5ef4e9[_0x0a63('0x1b')]][_0x0a63('0x3d')]||this[_0x0a63('0x4')][_0x5ef4e9[_0x0a63('0x1b')]][_0x0a63('0x1d')])){if(this[_0x0a63('0x5')][_0x5ef4e9[_0x0a63('0x1a')]]){this[_0x0a63('0x7')][_0x5ef4e9[_0x0a63('0x2c')]]={'queue':_0x5ef4e9[_0x0a63('0x1b')],'interface':_0x5ef4e9[_0x0a63('0x1a')]};}}}catch(_0x27de0c){logger[_0x0a63('0x32')](_0x0a63('0x3f'),_0x27de0c[_0x0a63('0x35')]);}};Acw[_0x0a63('0x18')][_0x0a63('0x40')]=function(_0x148e0a){try{if(this['channels'][_0x148e0a[_0x0a63('0x2c')]]&&_[_0x0a63('0x41')](this['channels'][_0x148e0a['uniqueid']]['attended'])){logger['info'](_0x0a63('0x42'),_0x148e0a[_0x0a63('0x2c')]);this['startAcw'](_0x148e0a[_0x0a63('0x2c')]);}else if(this['channels'][_0x148e0a[_0x0a63('0x43')]]&&_[_0x0a63('0x41')](this['channels'][_0x148e0a['linkedid']]['attended'])){logger[_0x0a63('0x22')](_0x0a63('0x44'),_0x148e0a[_0x0a63('0x43')]);this[_0x0a63('0x19')](_0x148e0a[_0x0a63('0x43')]);}}catch(_0x4be904){logger[_0x0a63('0x32')](_0x0a63('0x45'),_0x4be904[_0x0a63('0x35')]);}};Acw[_0x0a63('0x18')][_0x0a63('0xd')]=function(_0x4a5b6e){try{if(this[_0x0a63('0x7')][_0x4a5b6e[_0x0a63('0x2c')]]&&this[_0x0a63('0x7')][_0x4a5b6e[_0x0a63('0x2c')]]['attended']){logger[_0x0a63('0x22')](_0x0a63('0x46'),_0x4a5b6e[_0x0a63('0x2c')]);this[_0x0a63('0x19')](_0x4a5b6e[_0x0a63('0x2c')]);}else if(this[_0x0a63('0x7')][_0x4a5b6e['linkedid']]&&this[_0x0a63('0x7')][_0x4a5b6e[_0x0a63('0x43')]][_0x0a63('0x24')]){logger[_0x0a63('0x22')]('[%s][HANGUPATTENDEDTRANSFER:LINKEDID]',_0x4a5b6e['linkedid']);this[_0x0a63('0x19')](_0x4a5b6e[_0x0a63('0x43')]);}}catch(_0x42514e){logger[_0x0a63('0x32')](_0x0a63('0x47'),_0x42514e['message']);}};Acw['prototype']['syncAttendedTransfer']=function(_0x42c1bb){try{if(!_['isNil'](this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x48')]])){this[_0x0a63('0x19')](_0x42c1bb['transfereeuniqueid']);if(this['channels'][_0x42c1bb[_0x0a63('0x49')]]){this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x49')]][_0x0a63('0x24')]=!![];this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x4a')]]=this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x49')]];delete this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x49')]];}}else if(!_[_0x0a63('0x4b')](this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x4a')]])){this[_0x0a63('0x19')](_0x42c1bb['transfertargetuniqueid']);if(this['channels'][_0x42c1bb[_0x0a63('0x4c')]]){this[_0x0a63('0x7')][_0x42c1bb['origtransfereruniqueid']][_0x0a63('0x24')]=!![];this[_0x0a63('0x7')][_0x42c1bb['transfereeuniqueid']]=this[_0x0a63('0x7')][_0x42c1bb[_0x0a63('0x4c')]];delete this['channels'][_0x42c1bb['origtransfereruniqueid']];}}}catch(_0x3b395a){logger[_0x0a63('0x32')](_0x0a63('0x4d'),_0x3b395a['message']);}};Acw[_0x0a63('0x18')][_0x0a63('0x12')]=function(_0x27141e){try{if(this[_0x0a63('0x7')][_0x27141e[_0x0a63('0x4e')]]){logger['info'](_0x0a63('0x4f'),JSON[_0x0a63('0x3b')](_0x27141e[_0x0a63('0x4e')]));this[_0x0a63('0x19')](_0x27141e[_0x0a63('0x4e')]);}else if(this[_0x0a63('0x7')][_0x27141e[_0x0a63('0x50')]]){logger['info'](_0x0a63('0x51'),JSON[_0x0a63('0x3b')](_0x27141e[_0x0a63('0x50')]));this[_0x0a63('0x19')](_0x27141e[_0x0a63('0x50')]);}}catch(_0xf814c7){logger[_0x0a63('0x32')](_0x0a63('0x52'),_0xf814c7['message']);}};Acw['prototype'][_0x0a63('0xf')]=function(_0x30e5f0){try{if(this[_0x0a63('0x4')][_0x30e5f0[_0x0a63('0x1b')]]&&this[_0x0a63('0x4')][_0x30e5f0['queue']][_0x0a63('0x53')]===_0x0a63('0x54')){if(this[_0x0a63('0x5')][_0x30e5f0[_0x0a63('0x1a')]]){logger[_0x0a63('0x22')](_0x0a63('0x55'),_0x30e5f0[_0x0a63('0x2c')],_0x30e5f0[_0x0a63('0x1a')],_0x30e5f0[_0x0a63('0x1b')]);return RpcUser[_0x0a63('0x56')](this[_0x0a63('0x5')][_0x30e5f0['interface']],_0x0a63('0x57'),_0x30e5f0['uniqueid']);}}}catch(_0xfa80c2){logger[_0x0a63('0x32')]('[ACW][syncAgentRingNoAnswer]\x20%s',_0xfa80c2['message']);}};module['exports']=Acw;