Built motion from commit (unavailable).|2.5.4
[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 _0x008c=['[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','acwTimeout','format','YYYY-MM-DD\x20HH:mm:ss','uniqueid','queue','lastPauseAt','timer','update','[%s][UPDATE][ACWTIME:%s]','error','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','catch','[ACW][START]\x20%s','message','stopAcw','[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','syncAgentConnect','acw','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','syncHangupRequest','attended','[%s][HANGUP:UNIQUEID]','startAcw','linkedid','isUndefined','syncHangup','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','[ACW][syncBlindTransfer]\x20%s','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','[ACW][syncAgentRingNoAnswer]\x20%s','exports','util','lodash','moment','../ami','../../../config/logger','../rpc/user','../rpc/voiceAgentReport','voiceQueues','agents','timers','agentconnect','bind','hangup','syncAgentRingNoAnswer','syncAttendedTransfer','blindtransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','seconds','prototype','channels','interface','mandatoryDisposition','Action','then','voicePause','info','[%s][START][AGENT:%s][QUEUE:%s]','destlinkedid','savePause'];(function(_0xb7496d,_0x1cfdb8){var _0x33b87a=function(_0x4e1143){while(--_0x4e1143){_0xb7496d['push'](_0xb7496d['shift']());}};_0x33b87a(++_0x1cfdb8);}(_0x008c,0x188));var _0xc008=function(_0x22a8c4,_0x51c09a){_0x22a8c4=_0x22a8c4-0x0;var _0x104c6d=_0x008c[_0x22a8c4];return _0x104c6d;};'use strict';var util=require(_0xc008('0x0'));var _=require(_0xc008('0x1'));var moment=require(_0xc008('0x2'));var ami=require(_0xc008('0x3'));var logger=require(_0xc008('0x4'))('acw');var RpcUser=require(_0xc008('0x5'));var RpcVoiceAgentReport=require(_0xc008('0x6'));function Acw(_0x10b33c){this[_0xc008('0x7')]=_0x10b33c[_0xc008('0x7')];this[_0xc008('0x8')]=_0x10b33c[_0xc008('0x8')];this[_0xc008('0x9')]=_0x10b33c[_0xc008('0x9')];this['channels']={};ami['on'](_0xc008('0xa'),this['syncAgentConnect'][_0xc008('0xb')](this));ami['on']('hanguprequest',this['syncHangupRequest'][_0xc008('0xb')](this));ami['on'](_0xc008('0xc'),this['syncHangup']['bind'](this));ami['on']('agentringnoanswer',this[_0xc008('0xd')][_0xc008('0xb')](this));ami['on']('attendedtransfer',this[_0xc008('0xe')][_0xc008('0xb')](this));ami['on'](_0xc008('0xf'),this[_0xc008('0x10')][_0xc008('0xb')](this));ami['on'](_0xc008('0x11'),this[_0xc008('0x12')]['bind'](this));}function getDiff(_0x560e28){var _0x33f44c=moment()['milliseconds'](0x0);var _0x25e13f=moment(_0x560e28)[_0xc008('0x13')](0x0);return _0x33f44c[_0xc008('0x14')](_0x25e13f,_0xc008('0x15'));}Acw[_0xc008('0x16')]['startAcw']=function(_0x5e894e){try{var _0x4bd0f4=this;var _0x11ef38=this[_0xc008('0x17')][_0x5e894e][_0xc008('0x18')];var _0x3eb12a=this['channels'][_0x5e894e]['queue'];var _0x540e45=this['voiceQueues'][_0x3eb12a];var _0x46042b=![];var _0x462af5='ACW';if(_0x540e45[_0xc008('0x19')]){if(_0x540e45['mandatoryDispositionPause']['name']){_0x46042b=!![];_0x462af5=_0x540e45['mandatoryDispositionPause']['name'];}}ami[_0xc008('0x1a')]({'action':'QueuePause','interface':_0x11ef38,'paused':!![],'reason':_0x462af5})['then'](function(_0x590a71){if(_0x4bd0f4['agents'][_0x11ef38]){return RpcUser['getAgent'](_0x4bd0f4[_0xc008('0x8')][_0x11ef38]['id'])[_0xc008('0x1b')](function(_0x251db2){if(_0x251db2&&!_0x251db2[_0xc008('0x1c')]){logger[_0xc008('0x1d')](_0xc008('0x1e'),_0x5e894e,_0x11ef38,_0x3eb12a);var _0x4f43e2=_0x4bd0f4[_0xc008('0x17')][_0x5e894e]['attended']&&_0x4bd0f4['channels'][_0x5e894e][_0xc008('0x1f')]?_0x4bd0f4[_0xc008('0x17')][_0x5e894e][_0xc008('0x1f')]:_0x5e894e;return RpcUser[_0xc008('0x20')](_0x4bd0f4['agents'][_0x11ef38],_0x462af5,_0x4f43e2)['then'](function(_0x5de1e9){if(!_0x46042b){_0x4bd0f4[_0xc008('0x9')][_0x11ef38]={};logger[_0xc008('0x1d')](_0xc008('0x21'),_0x5e894e,_0x4bd0f4[_0xc008('0x7')][_0x3eb12a]['acwTimeout'],_0x11ef38,_0x3eb12a);_0x4bd0f4['timers'][_0x11ef38]['timer']=setTimeout(_0x4bd0f4['stopAcw']['bind'](_0x4bd0f4,_0x11ef38),_0x4bd0f4[_0xc008('0x7')][_0x3eb12a][_0xc008('0x22')]*0x3e8);_0x4bd0f4[_0xc008('0x9')][_0x11ef38]['lastPauseAt']=moment()[_0xc008('0x23')](_0xc008('0x24'));_0x4bd0f4[_0xc008('0x9')][_0x11ef38][_0xc008('0x25')]=_0x5e894e;_0x4bd0f4['timers'][_0x11ef38][_0xc008('0x26')]=_0x3eb12a;_0x4bd0f4[_0xc008('0x9')][_0x11ef38]['updateAcw']=function(){var _0x58db82=getDiff(_0x4bd0f4['timers'][_0x11ef38][_0xc008('0x27')]);clearTimeout(_0x4bd0f4[_0xc008('0x9')][_0x11ef38][_0xc008('0x28')]);_0x4bd0f4[_0xc008('0x9')][_0x11ef38][_0xc008('0x28')]=![];RpcVoiceAgentReport[_0xc008('0x29')]({'acwtime':_0x58db82},_0x4bd0f4[_0xc008('0x9')][_0x11ef38][_0xc008('0x25')],_0x11ef38)[_0xc008('0x1b')](function(_0x2b862d){logger[_0xc008('0x1d')](_0xc008('0x2a'),_0x5e894e,_0x58db82,_0x2b862d);})['catch'](function(_0x334a09){logger[_0xc008('0x2b')]('[%s][UPDATE][ERRORS:%s]',_0x5e894e,_0x334a09);});delete _0x4bd0f4[_0xc008('0x9')][_0x11ef38];};}});}else{logger[_0xc008('0x1d')](_0xc008('0x2c'),_0x5e894e,_0x11ef38,_0x3eb12a);}});}})[_0xc008('0x2d')](function(_0xd0e05a){logger[_0xc008('0x2b')](_0xc008('0x21'),_0x5e894e,_0x4bd0f4[_0xc008('0x7')][_0x3eb12a][_0xc008('0x22')],_0x11ef38,_0x3eb12a);})['finally'](function(){delete _0x4bd0f4[_0xc008('0x17')][_0x5e894e];});}catch(_0x389a40){logger[_0xc008('0x2b')](_0xc008('0x2e'),_0x389a40[_0xc008('0x2f')]);}};Acw[_0xc008('0x16')][_0xc008('0x30')]=function(_0x5d0e06){try{var _0x35f360=this;if(_0x35f360[_0xc008('0x9')][_0x5d0e06]){_0x35f360['timers'][_0x5d0e06][_0xc008('0x28')]=![];var _0x15453c=_0x35f360['timers'][_0x5d0e06][_0xc008('0x25')];var _0x2e4ae1=_0x35f360[_0xc008('0x9')][_0x5d0e06]['queue'];var _0x53b353=_0x35f360['voiceQueues'][_0x2e4ae1][_0xc008('0x22')];logger['info'](_0xc008('0x31'),_0x5d0e06);RpcUser[_0xc008('0x32')](this[_0xc008('0x8')][_0x5d0e06]);RpcVoiceAgentReport[_0xc008('0x29')]({'acwtime':_0x53b353,'agentacw':!![]},_0x15453c,_0x5d0e06)[_0xc008('0x1b')](function(_0xa381d1){logger[_0xc008('0x1d')](_0xc008('0x2a'),_0x15453c,_0x53b353,_0xa381d1);})[_0xc008('0x2d')](function(_0x387dfd){logger[_0xc008('0x2b')](_0xc008('0x33'),_0x15453c,_0x387dfd);});}else{logger[_0xc008('0x2b')](_0xc008('0x34'),_0x5d0e06);if(_0x35f360['timers']){logger[_0xc008('0x1d')](_0xc008('0x35'),JSON[_0xc008('0x36')](_0x35f360[_0xc008('0x9')]));}}}catch(_0x49a16d){logger[_0xc008('0x2b')](_0xc008('0x37'),_0x49a16d[_0xc008('0x2f')]);}};Acw[_0xc008('0x16')][_0xc008('0x38')]=function(_0x5706bb){try{if(this[_0xc008('0x7')][_0x5706bb[_0xc008('0x26')]]&&(this[_0xc008('0x7')][_0x5706bb[_0xc008('0x26')]][_0xc008('0x39')]||this['voiceQueues'][_0x5706bb[_0xc008('0x26')]][_0xc008('0x19')])){if(this[_0xc008('0x8')][_0x5706bb[_0xc008('0x18')]]){this['channels'][_0x5706bb[_0xc008('0x25')]]={'queue':_0x5706bb[_0xc008('0x26')],'interface':_0x5706bb[_0xc008('0x18')],'destlinkedid':_0x5706bb['destlinkedid']};}}}catch(_0x1f9af7){logger['error'](_0xc008('0x3a'),_0x1f9af7['message']);}};Acw[_0xc008('0x16')][_0xc008('0x12')]=function(_0x5a5d85){try{if(this[_0xc008('0x7')][_0x5a5d85[_0xc008('0x26')]]&&(this[_0xc008('0x7')][_0x5a5d85['queue']][_0xc008('0x39')]||this[_0xc008('0x7')][_0x5a5d85[_0xc008('0x26')]][_0xc008('0x19')])){if(this[_0xc008('0x8')][_0x5a5d85[_0xc008('0x18')]]){this['channels'][_0x5a5d85['uniqueid']]={'queue':_0x5a5d85['queue'],'interface':_0x5a5d85[_0xc008('0x18')]};}}}catch(_0x36417a){logger[_0xc008('0x2b')](_0xc008('0x3b'),_0x36417a[_0xc008('0x2f')]);}};Acw[_0xc008('0x16')][_0xc008('0x3c')]=function(_0x33be4f){try{if(this['channels'][_0x33be4f['uniqueid']]&&_['isUndefined'](this[_0xc008('0x17')][_0x33be4f[_0xc008('0x25')]][_0xc008('0x3d')])){logger['info'](_0xc008('0x3e'),_0x33be4f[_0xc008('0x25')]);this[_0xc008('0x3f')](_0x33be4f[_0xc008('0x25')]);}else if(this[_0xc008('0x17')][_0x33be4f[_0xc008('0x40')]]&&_[_0xc008('0x41')](this[_0xc008('0x17')][_0x33be4f[_0xc008('0x40')]][_0xc008('0x3d')])){logger['info']('[%s][HANGUP:LINKEDID]',_0x33be4f[_0xc008('0x40')]);this['startAcw'](_0x33be4f[_0xc008('0x40')]);}}catch(_0x36e6f8){logger[_0xc008('0x2b')]('[ACW][syncHangupRequest]\x20%s',_0x36e6f8[_0xc008('0x2f')]);}};Acw[_0xc008('0x16')][_0xc008('0x42')]=function(_0x8b9775){try{if(this[_0xc008('0x17')][_0x8b9775['uniqueid']]&&this[_0xc008('0x17')][_0x8b9775[_0xc008('0x25')]]['attended']){logger[_0xc008('0x1d')](_0xc008('0x43'),_0x8b9775['uniqueid']);this['startAcw'](_0x8b9775[_0xc008('0x25')]);}else if(this[_0xc008('0x17')][_0x8b9775[_0xc008('0x40')]]&&this[_0xc008('0x17')][_0x8b9775[_0xc008('0x40')]]['attended']){logger['info'](_0xc008('0x44'),_0x8b9775['linkedid']);this[_0xc008('0x3f')](_0x8b9775[_0xc008('0x40')]);}}catch(_0xf94fcb){logger[_0xc008('0x2b')](_0xc008('0x45'),_0xf94fcb[_0xc008('0x2f')]);}};Acw['prototype'][_0xc008('0xe')]=function(_0xbd7422){try{if(!_[_0xc008('0x46')](this[_0xc008('0x17')][_0xbd7422[_0xc008('0x47')]])){this['startAcw'](_0xbd7422[_0xc008('0x47')]);if(this['channels'][_0xbd7422['secondtransfereruniqueid']]){this['channels'][_0xbd7422[_0xc008('0x48')]][_0xc008('0x3d')]=!![];this[_0xc008('0x17')][_0xbd7422['transfertargetuniqueid']]=this[_0xc008('0x17')][_0xbd7422[_0xc008('0x48')]];delete this[_0xc008('0x17')][_0xbd7422['secondtransfereruniqueid']];}}else if(!_[_0xc008('0x46')](this[_0xc008('0x17')][_0xbd7422[_0xc008('0x49')]])){this[_0xc008('0x3f')](_0xbd7422['transfertargetuniqueid']);if(this[_0xc008('0x17')][_0xbd7422['origtransfereruniqueid']]){this[_0xc008('0x17')][_0xbd7422[_0xc008('0x4a')]][_0xc008('0x3d')]=!![];this[_0xc008('0x17')][_0xbd7422[_0xc008('0x47')]]=this[_0xc008('0x17')][_0xbd7422['origtransfereruniqueid']];delete this[_0xc008('0x17')][_0xbd7422['origtransfereruniqueid']];}}}catch(_0x5bf4a9){logger[_0xc008('0x2b')](_0xc008('0x4b'),_0x5bf4a9['message']);}};Acw[_0xc008('0x16')][_0xc008('0x10')]=function(_0x3e373e){try{if(this[_0xc008('0x17')][_0x3e373e[_0xc008('0x4c')]]){logger[_0xc008('0x1d')](_0xc008('0x4d'),JSON['stringify'](_0x3e373e[_0xc008('0x4c')]));this[_0xc008('0x3f')](_0x3e373e[_0xc008('0x4c')]);}else if(this[_0xc008('0x17')][_0x3e373e[_0xc008('0x4e')]]){logger[_0xc008('0x1d')](_0xc008('0x4f'),JSON[_0xc008('0x36')](_0x3e373e[_0xc008('0x4e')]));this[_0xc008('0x3f')](_0x3e373e[_0xc008('0x4e')]);}}catch(_0x2b5eb6){logger[_0xc008('0x2b')](_0xc008('0x50'),_0x2b5eb6['message']);}};Acw[_0xc008('0x16')][_0xc008('0xd')]=function(_0x3d3a7e){try{if(this['voiceQueues'][_0x3d3a7e[_0xc008('0x26')]]&&this[_0xc008('0x7')][_0x3d3a7e['queue']]['autopause']===_0xc008('0x51')){if(this[_0xc008('0x8')][_0x3d3a7e[_0xc008('0x18')]]){logger[_0xc008('0x1d')](_0xc008('0x52'),_0x3d3a7e[_0xc008('0x25')],_0x3d3a7e[_0xc008('0x18')],_0x3d3a7e[_0xc008('0x26')]);return RpcUser[_0xc008('0x20')](this[_0xc008('0x8')][_0x3d3a7e[_0xc008('0x18')]],'Auto-Pause',_0x3d3a7e[_0xc008('0x25')]);}}}catch(_0x25a52b){logger[_0xc008('0x2b')](_0xc008('0x53'),_0x25a52b['message']);}};module[_0xc008('0x54')]=Acw;