Built motion from commit (unavailable).|2.4.3
[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 _0x5c12=['timers','syncAgentConnect','bind','hanguprequest','syncHangupRequest','syncHangup','agentringnoanswer','syncAgentRingNoAnswer','syncAttendedTransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','seconds','prototype','interface','name','mandatoryDispositionPause','Action','then','getAgent','voicePause','info','[%s][START][AGENT:%s][QUEUE:%s]','channels','attended','destlinkedid','savePause','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','acwTimeout','timer','stopAcw','format','uniqueid','queue','updateAcw','lastPauseAt','update','catch','error','[%s][UPDATE][ERRORS:%s]','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','finally','[ACW][START]\x20%s','message','saveUnpause','[%s][UPDATE][ACWTIME:%s]','[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer','[ACW][TIMERS]','[ACW][STOP]\x20%s','mandatoryDisposition','[ACW][syncAgentConnectPreview]\x20%s','isUndefined','[%s][HANGUP:UNIQUEID]','startAcw','linkedid','[%s][HANGUP:LINKEDID]','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','stringify','transfererlinkedid','autopause','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','lodash','moment','../../../config/logger','acw','../rpc/user','../rpc/voiceAgentReport','voiceQueues','agents'];(function(_0x42245d,_0x51758f){var _0x4b211a=function(_0x2634e){while(--_0x2634e){_0x42245d['push'](_0x42245d['shift']());}};_0x4b211a(++_0x51758f);}(_0x5c12,0x188));var _0x25c1=function(_0x81dcac,_0x8ff7db){_0x81dcac=_0x81dcac-0x0;var _0xc7803b=_0x5c12[_0x81dcac];return _0xc7803b;};'use strict';var util=require('util');var _=require(_0x25c1('0x0'));var moment=require(_0x25c1('0x1'));var ami=require('../ami');var logger=require(_0x25c1('0x2'))(_0x25c1('0x3'));var RpcUser=require(_0x25c1('0x4'));var RpcVoiceAgentReport=require(_0x25c1('0x5'));function Acw(_0x2c5df0){this[_0x25c1('0x6')]=_0x2c5df0[_0x25c1('0x6')];this['agents']=_0x2c5df0[_0x25c1('0x7')];this[_0x25c1('0x8')]=_0x2c5df0[_0x25c1('0x8')];this['channels']={};ami['on']('agentconnect',this[_0x25c1('0x9')][_0x25c1('0xa')](this));ami['on'](_0x25c1('0xb'),this[_0x25c1('0xc')][_0x25c1('0xa')](this));ami['on']('hangup',this[_0x25c1('0xd')][_0x25c1('0xa')](this));ami['on'](_0x25c1('0xe'),this[_0x25c1('0xf')][_0x25c1('0xa')](this));ami['on']('attendedtransfer',this[_0x25c1('0x10')][_0x25c1('0xa')](this));ami['on']('blindtransfer',this[_0x25c1('0x11')][_0x25c1('0xa')](this));ami['on'](_0x25c1('0x12'),this[_0x25c1('0x13')]['bind'](this));}function getDiff(_0x569ef9){var _0x4ef5d7=moment()['milliseconds'](0x0);var _0x3ef429=moment(_0x569ef9)[_0x25c1('0x14')](0x0);return _0x4ef5d7[_0x25c1('0x15')](_0x3ef429,_0x25c1('0x16'));}Acw[_0x25c1('0x17')]['startAcw']=function(_0x4638f0){try{var _0x55b62d=this;var _0x5d631e=this['channels'][_0x4638f0][_0x25c1('0x18')];var _0x1a08b5=this['channels'][_0x4638f0]['queue'];var _0x61a29f=this['voiceQueues'][_0x1a08b5];var _0x7175d4=![];var _0x23a418='ACW';if(_0x61a29f['mandatoryDisposition']){if(_0x61a29f['mandatoryDispositionPause'][_0x25c1('0x19')]){_0x7175d4=!![];_0x23a418=_0x61a29f[_0x25c1('0x1a')][_0x25c1('0x19')];}}ami[_0x25c1('0x1b')]({'action':'QueuePause','interface':_0x5d631e,'paused':!![],'reason':_0x23a418})[_0x25c1('0x1c')](function(_0x9f54e3){if(_0x55b62d[_0x25c1('0x7')][_0x5d631e]){return RpcUser[_0x25c1('0x1d')](_0x55b62d['agents'][_0x5d631e]['id'])['then'](function(_0x2a8a84){if(_0x2a8a84&&!_0x2a8a84[_0x25c1('0x1e')]){logger[_0x25c1('0x1f')](_0x25c1('0x20'),_0x4638f0,_0x5d631e,_0x1a08b5);var _0x15cf2f=_0x55b62d[_0x25c1('0x21')][_0x4638f0][_0x25c1('0x22')]&&_0x55b62d[_0x25c1('0x21')][_0x4638f0][_0x25c1('0x23')]?_0x55b62d[_0x25c1('0x21')][_0x4638f0][_0x25c1('0x23')]:_0x4638f0;return RpcUser[_0x25c1('0x24')](_0x55b62d[_0x25c1('0x7')][_0x5d631e],_0x23a418,_0x15cf2f)['then'](function(_0x2dadae){if(!_0x7175d4){_0x55b62d[_0x25c1('0x8')][_0x5d631e]={};logger[_0x25c1('0x1f')](_0x25c1('0x25'),_0x4638f0,_0x55b62d[_0x25c1('0x6')][_0x1a08b5][_0x25c1('0x26')],_0x5d631e,_0x1a08b5);_0x55b62d['timers'][_0x5d631e][_0x25c1('0x27')]=setTimeout(_0x55b62d[_0x25c1('0x28')][_0x25c1('0xa')](_0x55b62d,_0x5d631e),_0x55b62d[_0x25c1('0x6')][_0x1a08b5][_0x25c1('0x26')]*0x3e8);_0x55b62d[_0x25c1('0x8')][_0x5d631e]['lastPauseAt']=moment()[_0x25c1('0x29')]('YYYY-MM-DD\x20HH:mm:ss');_0x55b62d[_0x25c1('0x8')][_0x5d631e][_0x25c1('0x2a')]=_0x4638f0;_0x55b62d[_0x25c1('0x8')][_0x5d631e][_0x25c1('0x2b')]=_0x1a08b5;_0x55b62d[_0x25c1('0x8')][_0x5d631e][_0x25c1('0x2c')]=function(){var _0x1fd4e3=getDiff(_0x55b62d[_0x25c1('0x8')][_0x5d631e][_0x25c1('0x2d')]);clearTimeout(_0x55b62d['timers'][_0x5d631e][_0x25c1('0x27')]);_0x55b62d['timers'][_0x5d631e]['timer']=![];RpcVoiceAgentReport[_0x25c1('0x2e')]({'acwtime':_0x1fd4e3},_0x55b62d[_0x25c1('0x8')][_0x5d631e]['uniqueid'],_0x5d631e)[_0x25c1('0x1c')](function(_0x5a5a32){logger[_0x25c1('0x1f')]('[%s][UPDATE][ACWTIME:%s]',_0x4638f0,_0x1fd4e3,_0x5a5a32);})[_0x25c1('0x2f')](function(_0x7f1e7a){logger[_0x25c1('0x30')](_0x25c1('0x31'),_0x4638f0,_0x7f1e7a);});delete _0x55b62d[_0x25c1('0x8')][_0x5d631e];};}});}else{logger[_0x25c1('0x1f')](_0x25c1('0x32'),_0x4638f0,_0x5d631e,_0x1a08b5);}});}})[_0x25c1('0x2f')](function(_0x578713){logger[_0x25c1('0x30')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x4638f0,_0x55b62d[_0x25c1('0x6')][_0x1a08b5]['acwTimeout'],_0x5d631e,_0x1a08b5);})[_0x25c1('0x33')](function(){delete _0x55b62d[_0x25c1('0x21')][_0x4638f0];});}catch(_0x18f10c){logger[_0x25c1('0x30')](_0x25c1('0x34'),_0x18f10c[_0x25c1('0x35')]);}};Acw[_0x25c1('0x17')][_0x25c1('0x28')]=function(_0x3fced1){try{var _0x2d060c=this;if(_0x2d060c[_0x25c1('0x8')][_0x3fced1]){_0x2d060c[_0x25c1('0x8')][_0x3fced1][_0x25c1('0x27')]=![];var _0x1b6e92=_0x2d060c[_0x25c1('0x8')][_0x3fced1][_0x25c1('0x2a')];var _0x349aef=_0x2d060c[_0x25c1('0x8')][_0x3fced1][_0x25c1('0x2b')];var _0x357385=_0x2d060c['voiceQueues'][_0x349aef][_0x25c1('0x26')];logger[_0x25c1('0x1f')]('[TIMER][STOP][AGENT:%s]',_0x3fced1);RpcUser[_0x25c1('0x36')](this['agents'][_0x3fced1]);RpcVoiceAgentReport[_0x25c1('0x2e')]({'acwtime':_0x357385,'agentacw':!![]},_0x1b6e92,_0x3fced1)['then'](function(_0x4326fb){logger[_0x25c1('0x1f')](_0x25c1('0x37'),_0x1b6e92,_0x357385,_0x4326fb);})[_0x25c1('0x2f')](function(_0xbc20a3){logger['error'](_0x25c1('0x31'),_0x1b6e92,_0xbc20a3);});}else{logger['error'](_0x25c1('0x38'),_0x3fced1);if(_0x2d060c[_0x25c1('0x8')]){logger[_0x25c1('0x1f')](_0x25c1('0x39'),JSON['stringify'](_0x2d060c['timers']));}}}catch(_0x58b8f3){logger[_0x25c1('0x30')](_0x25c1('0x3a'),_0x58b8f3['message']);}};Acw[_0x25c1('0x17')]['syncAgentConnect']=function(_0x3d5172){try{if(this[_0x25c1('0x6')][_0x3d5172[_0x25c1('0x2b')]]&&(this['voiceQueues'][_0x3d5172['queue']]['acw']||this[_0x25c1('0x6')][_0x3d5172[_0x25c1('0x2b')]]['mandatoryDisposition'])){if(this[_0x25c1('0x7')][_0x3d5172[_0x25c1('0x18')]]){this[_0x25c1('0x21')][_0x3d5172['uniqueid']]={'queue':_0x3d5172['queue'],'interface':_0x3d5172['interface'],'destlinkedid':_0x3d5172['destlinkedid']};}}}catch(_0x669152){logger[_0x25c1('0x30')]('[ACW][syncAgentConnect]\x20%s',_0x669152[_0x25c1('0x35')]);}};Acw[_0x25c1('0x17')][_0x25c1('0x13')]=function(_0x2dbe23){try{if(this[_0x25c1('0x6')][_0x2dbe23[_0x25c1('0x2b')]]&&(this[_0x25c1('0x6')][_0x2dbe23['queue']]['acw']||this[_0x25c1('0x6')][_0x2dbe23[_0x25c1('0x2b')]][_0x25c1('0x3b')])){if(this['agents'][_0x2dbe23[_0x25c1('0x18')]]){this[_0x25c1('0x21')][_0x2dbe23[_0x25c1('0x2a')]]={'queue':_0x2dbe23[_0x25c1('0x2b')],'interface':_0x2dbe23['interface']};}}}catch(_0xb87cf1){logger[_0x25c1('0x30')](_0x25c1('0x3c'),_0xb87cf1[_0x25c1('0x35')]);}};Acw['prototype']['syncHangupRequest']=function(_0x13ac06){try{if(this[_0x25c1('0x21')][_0x13ac06[_0x25c1('0x2a')]]&&_[_0x25c1('0x3d')](this['channels'][_0x13ac06[_0x25c1('0x2a')]][_0x25c1('0x22')])){logger['info'](_0x25c1('0x3e'),_0x13ac06[_0x25c1('0x2a')]);this[_0x25c1('0x3f')](_0x13ac06[_0x25c1('0x2a')]);}else if(this['channels'][_0x13ac06['linkedid']]&&_[_0x25c1('0x3d')](this[_0x25c1('0x21')][_0x13ac06[_0x25c1('0x40')]]['attended'])){logger[_0x25c1('0x1f')](_0x25c1('0x41'),_0x13ac06['linkedid']);this[_0x25c1('0x3f')](_0x13ac06[_0x25c1('0x40')]);}}catch(_0x2b58a3){logger[_0x25c1('0x30')](_0x25c1('0x42'),_0x2b58a3[_0x25c1('0x35')]);}};Acw[_0x25c1('0x17')]['syncHangup']=function(_0x5344da){try{if(this['channels'][_0x5344da[_0x25c1('0x2a')]]&&this['channels'][_0x5344da[_0x25c1('0x2a')]][_0x25c1('0x22')]){logger[_0x25c1('0x1f')](_0x25c1('0x43'),_0x5344da[_0x25c1('0x2a')]);this[_0x25c1('0x3f')](_0x5344da['uniqueid']);}else if(this[_0x25c1('0x21')][_0x5344da[_0x25c1('0x40')]]&&this[_0x25c1('0x21')][_0x5344da[_0x25c1('0x40')]][_0x25c1('0x22')]){logger[_0x25c1('0x1f')]('[%s][HANGUPATTENDEDTRANSFER:LINKEDID]',_0x5344da[_0x25c1('0x40')]);this[_0x25c1('0x3f')](_0x5344da[_0x25c1('0x40')]);}}catch(_0xbff8ad){logger[_0x25c1('0x30')]('[ACW][syncHangup]\x20%s',_0xbff8ad[_0x25c1('0x35')]);}};Acw[_0x25c1('0x17')]['syncAttendedTransfer']=function(_0x1341d2){try{if(!_[_0x25c1('0x44')](this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x45')]])){this[_0x25c1('0x3f')](_0x1341d2[_0x25c1('0x45')]);if(this['channels'][_0x1341d2[_0x25c1('0x46')]]){this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x46')]][_0x25c1('0x22')]=!![];this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x47')]]=this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x46')]];delete this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x46')]];}}else if(!_[_0x25c1('0x44')](this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x47')]])){this[_0x25c1('0x3f')](_0x1341d2['transfertargetuniqueid']);if(this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x48')]]){this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x48')]][_0x25c1('0x22')]=!![];this[_0x25c1('0x21')][_0x1341d2[_0x25c1('0x45')]]=this['channels'][_0x1341d2[_0x25c1('0x48')]];delete this['channels'][_0x1341d2[_0x25c1('0x48')]];}}}catch(_0x24568c){logger[_0x25c1('0x30')](_0x25c1('0x49'),_0x24568c[_0x25c1('0x35')]);}};Acw[_0x25c1('0x17')][_0x25c1('0x11')]=function(_0x19df83){try{if(this['channels'][_0x19df83[_0x25c1('0x4a')]]){logger[_0x25c1('0x1f')](_0x25c1('0x4b'),JSON[_0x25c1('0x4c')](_0x19df83[_0x25c1('0x4a')]));this[_0x25c1('0x3f')](_0x19df83[_0x25c1('0x4a')]);}else if(this['channels'][_0x19df83[_0x25c1('0x4d')]]){logger['info']('[%s][BLINDTRANSFER:LINKEDID]',JSON['stringify'](_0x19df83[_0x25c1('0x4d')]));this[_0x25c1('0x3f')](_0x19df83[_0x25c1('0x4d')]);}}catch(_0x15cd6d){logger[_0x25c1('0x30')]('[ACW][syncBlindTransfer]\x20%s',_0x15cd6d[_0x25c1('0x35')]);}};Acw['prototype'][_0x25c1('0xf')]=function(_0x36aa98){try{if(this[_0x25c1('0x6')][_0x36aa98[_0x25c1('0x2b')]]&&this[_0x25c1('0x6')][_0x36aa98[_0x25c1('0x2b')]][_0x25c1('0x4e')]==='all'){if(this[_0x25c1('0x7')][_0x36aa98[_0x25c1('0x18')]]){logger[_0x25c1('0x1f')](_0x25c1('0x4f'),_0x36aa98[_0x25c1('0x2a')],_0x36aa98[_0x25c1('0x18')],_0x36aa98['queue']);return RpcUser[_0x25c1('0x24')](this['agents'][_0x36aa98[_0x25c1('0x18')]],'Auto-Pause',_0x36aa98['uniqueid']);}}}catch(_0x1c66d6){logger['error']('[ACW][syncAgentRingNoAnswer]\x20%s',_0x1c66d6['message']);}};module['exports']=Acw;