Built motion from commit (unavailable).|2.4.18
[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 _0x0a9a=['acw','../rpc/user','voiceQueues','agents','timers','agentconnect','bind','hanguprequest','syncHangupRequest','syncHangup','attendedtransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','seconds','prototype','startAcw','interface','channels','queue','ACW','mandatoryDisposition','mandatoryDispositionPause','name','then','info','[%s][START][AGENT:%s][QUEUE:%s]','destlinkedid','savePause','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','acwTimeout','timer','lastPauseAt','format','YYYY-MM-DD\x20HH:mm:ss','uniqueid','update','[%s][UPDATE][ACWTIME:%s]','catch','error','finally','[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','syncAgentConnect','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','isUndefined','attended','linkedid','[%s][HANGUP:LINKEDID]','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','[%s][BLINDTRANSFER:UNIQUEID]','transfererlinkedid','[ACW][syncBlindTransfer]\x20%s','syncAgentRingNoAnswer','autopause','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s','lodash','../ami','../../../config/logger'];(function(_0x57aa63,_0x3b575f){var _0x9d258a=function(_0x3c5b1b){while(--_0x3c5b1b){_0x57aa63['push'](_0x57aa63['shift']());}};_0x9d258a(++_0x3b575f);}(_0x0a9a,0x183));var _0xa0a9=function(_0x254959,_0x32e0b0){_0x254959=_0x254959-0x0;var _0xb23270=_0x0a9a[_0x254959];return _0xb23270;};'use strict';var util=require('util');var _=require(_0xa0a9('0x0'));var moment=require('moment');var ami=require(_0xa0a9('0x1'));var logger=require(_0xa0a9('0x2'))(_0xa0a9('0x3'));var RpcUser=require(_0xa0a9('0x4'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x317a94){this[_0xa0a9('0x5')]=_0x317a94['voiceQueues'];this[_0xa0a9('0x6')]=_0x317a94[_0xa0a9('0x6')];this[_0xa0a9('0x7')]=_0x317a94[_0xa0a9('0x7')];this['channels']={};ami['on'](_0xa0a9('0x8'),this['syncAgentConnect'][_0xa0a9('0x9')](this));ami['on'](_0xa0a9('0xa'),this[_0xa0a9('0xb')][_0xa0a9('0x9')](this));ami['on']('hangup',this[_0xa0a9('0xc')][_0xa0a9('0x9')](this));ami['on']('agentringnoanswer',this['syncAgentRingNoAnswer'][_0xa0a9('0x9')](this));ami['on'](_0xa0a9('0xd'),this['syncAttendedTransfer'][_0xa0a9('0x9')](this));ami['on']('blindtransfer',this[_0xa0a9('0xe')]['bind'](this));ami['on'](_0xa0a9('0xf'),this[_0xa0a9('0x10')][_0xa0a9('0x9')](this));}function getDiff(_0x35e7cd){var _0x13833c=moment()['milliseconds'](0x0);var _0x1f3f23=moment(_0x35e7cd)[_0xa0a9('0x11')](0x0);return _0x13833c[_0xa0a9('0x12')](_0x1f3f23,_0xa0a9('0x13'));}Acw[_0xa0a9('0x14')][_0xa0a9('0x15')]=function(_0x5a6693){try{var _0x176faa=this;var _0x48c315=this['channels'][_0x5a6693][_0xa0a9('0x16')];var _0x9f5abd=this[_0xa0a9('0x17')][_0x5a6693][_0xa0a9('0x18')];var _0x568409=this[_0xa0a9('0x5')][_0x9f5abd];var _0x126401=![];var _0x33eb8f=_0xa0a9('0x19');if(_0x568409[_0xa0a9('0x1a')]){if(_0x568409[_0xa0a9('0x1b')]['name']){_0x126401=!![];_0x33eb8f=_0x568409[_0xa0a9('0x1b')][_0xa0a9('0x1c')];}}ami['Action']({'action':'QueuePause','interface':_0x48c315,'paused':!![],'reason':_0x33eb8f})[_0xa0a9('0x1d')](function(_0x1f6955){if(_0x176faa[_0xa0a9('0x6')][_0x48c315]){return RpcUser['getAgent'](_0x176faa[_0xa0a9('0x6')][_0x48c315]['id'])['then'](function(_0x1fb36b){if(_0x1fb36b&&!_0x1fb36b['voicePause']){logger[_0xa0a9('0x1e')](_0xa0a9('0x1f'),_0x5a6693,_0x48c315,_0x9f5abd);var _0x2f0b14=_0x176faa[_0xa0a9('0x17')][_0x5a6693]['attended']&&_0x176faa[_0xa0a9('0x17')][_0x5a6693]['destlinkedid']?_0x176faa[_0xa0a9('0x17')][_0x5a6693][_0xa0a9('0x20')]:_0x5a6693;return RpcUser[_0xa0a9('0x21')](_0x176faa[_0xa0a9('0x6')][_0x48c315],_0x33eb8f,_0x2f0b14)['then'](function(_0x7c1502){if(!_0x126401){_0x176faa[_0xa0a9('0x7')][_0x48c315]={};logger[_0xa0a9('0x1e')](_0xa0a9('0x22'),_0x5a6693,_0x176faa['voiceQueues'][_0x9f5abd][_0xa0a9('0x23')],_0x48c315,_0x9f5abd);_0x176faa[_0xa0a9('0x7')][_0x48c315][_0xa0a9('0x24')]=setTimeout(_0x176faa['stopAcw']['bind'](_0x176faa,_0x48c315),_0x176faa[_0xa0a9('0x5')][_0x9f5abd][_0xa0a9('0x23')]*0x3e8);_0x176faa[_0xa0a9('0x7')][_0x48c315][_0xa0a9('0x25')]=moment()[_0xa0a9('0x26')](_0xa0a9('0x27'));_0x176faa[_0xa0a9('0x7')][_0x48c315][_0xa0a9('0x28')]=_0x5a6693;_0x176faa[_0xa0a9('0x7')][_0x48c315][_0xa0a9('0x18')]=_0x9f5abd;_0x176faa[_0xa0a9('0x7')][_0x48c315]['updateAcw']=function(){var _0x1f6178=getDiff(_0x176faa[_0xa0a9('0x7')][_0x48c315]['lastPauseAt']);clearTimeout(_0x176faa[_0xa0a9('0x7')][_0x48c315][_0xa0a9('0x24')]);_0x176faa['timers'][_0x48c315]['timer']=![];RpcVoiceAgentReport[_0xa0a9('0x29')]({'acwtime':_0x1f6178},_0x176faa['timers'][_0x48c315]['uniqueid'],_0x48c315)[_0xa0a9('0x1d')](function(_0x104936){logger[_0xa0a9('0x1e')](_0xa0a9('0x2a'),_0x5a6693,_0x1f6178,_0x104936);})[_0xa0a9('0x2b')](function(_0x12bdcc){logger[_0xa0a9('0x2c')]('[%s][UPDATE][ERRORS:%s]',_0x5a6693,_0x12bdcc);});delete _0x176faa[_0xa0a9('0x7')][_0x48c315];};}});}else{logger[_0xa0a9('0x1e')]('[%s][INPAUSE][AGENT:%s][QUEUE:%s]',_0x5a6693,_0x48c315,_0x9f5abd);}});}})[_0xa0a9('0x2b')](function(_0x2f98f6){logger[_0xa0a9('0x2c')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x5a6693,_0x176faa['voiceQueues'][_0x9f5abd][_0xa0a9('0x23')],_0x48c315,_0x9f5abd);})[_0xa0a9('0x2d')](function(){delete _0x176faa[_0xa0a9('0x17')][_0x5a6693];});}catch(_0x42fd7a){logger['error'](_0xa0a9('0x2e'),_0x42fd7a[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')]['stopAcw']=function(_0x2a4587){try{var _0x3c74ea=this;if(_0x3c74ea[_0xa0a9('0x7')][_0x2a4587]){_0x3c74ea['timers'][_0x2a4587][_0xa0a9('0x24')]=![];var _0x2ed673=_0x3c74ea[_0xa0a9('0x7')][_0x2a4587][_0xa0a9('0x28')];var _0x2e11dc=_0x3c74ea[_0xa0a9('0x7')][_0x2a4587][_0xa0a9('0x18')];var _0xcf2461=_0x3c74ea[_0xa0a9('0x5')][_0x2e11dc][_0xa0a9('0x23')];logger[_0xa0a9('0x1e')](_0xa0a9('0x30'),_0x2a4587);RpcUser[_0xa0a9('0x31')](this[_0xa0a9('0x6')][_0x2a4587]);RpcVoiceAgentReport[_0xa0a9('0x29')]({'acwtime':_0xcf2461,'agentacw':!![]},_0x2ed673,_0x2a4587)[_0xa0a9('0x1d')](function(_0x868447){logger['info'](_0xa0a9('0x2a'),_0x2ed673,_0xcf2461,_0x868447);})[_0xa0a9('0x2b')](function(_0x3d3769){logger['error'](_0xa0a9('0x32'),_0x2ed673,_0x3d3769);});}else{logger[_0xa0a9('0x2c')](_0xa0a9('0x33'),_0x2a4587);if(_0x3c74ea[_0xa0a9('0x7')]){logger['info'](_0xa0a9('0x34'),JSON[_0xa0a9('0x35')](_0x3c74ea[_0xa0a9('0x7')]));}}}catch(_0x17c40b){logger[_0xa0a9('0x2c')]('[ACW][STOP]\x20%s',_0x17c40b[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')][_0xa0a9('0x36')]=function(_0x32d926){try{if(this[_0xa0a9('0x5')][_0x32d926['queue']]&&(this[_0xa0a9('0x5')][_0x32d926[_0xa0a9('0x18')]][_0xa0a9('0x3')]||this[_0xa0a9('0x5')][_0x32d926[_0xa0a9('0x18')]]['mandatoryDisposition'])){if(this[_0xa0a9('0x6')][_0x32d926[_0xa0a9('0x16')]]){this['channels'][_0x32d926['uniqueid']]={'queue':_0x32d926[_0xa0a9('0x18')],'interface':_0x32d926[_0xa0a9('0x16')],'destlinkedid':_0x32d926[_0xa0a9('0x20')]};}}}catch(_0x1db92b){logger['error'](_0xa0a9('0x37'),_0x1db92b[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')][_0xa0a9('0x10')]=function(_0x3e1d61){try{if(this[_0xa0a9('0x5')][_0x3e1d61[_0xa0a9('0x18')]]&&(this[_0xa0a9('0x5')][_0x3e1d61[_0xa0a9('0x18')]][_0xa0a9('0x3')]||this[_0xa0a9('0x5')][_0x3e1d61[_0xa0a9('0x18')]][_0xa0a9('0x1a')])){if(this[_0xa0a9('0x6')][_0x3e1d61[_0xa0a9('0x16')]]){this[_0xa0a9('0x17')][_0x3e1d61[_0xa0a9('0x28')]]={'queue':_0x3e1d61['queue'],'interface':_0x3e1d61[_0xa0a9('0x16')]};}}}catch(_0x4906c6){logger[_0xa0a9('0x2c')](_0xa0a9('0x38'),_0x4906c6[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')][_0xa0a9('0xb')]=function(_0x1bf5c8){try{if(this[_0xa0a9('0x17')][_0x1bf5c8[_0xa0a9('0x28')]]&&_[_0xa0a9('0x39')](this['channels'][_0x1bf5c8[_0xa0a9('0x28')]][_0xa0a9('0x3a')])){logger[_0xa0a9('0x1e')]('[%s][HANGUP:UNIQUEID]',_0x1bf5c8[_0xa0a9('0x28')]);this[_0xa0a9('0x15')](_0x1bf5c8[_0xa0a9('0x28')]);}else if(this['channels'][_0x1bf5c8[_0xa0a9('0x3b')]]&&_[_0xa0a9('0x39')](this[_0xa0a9('0x17')][_0x1bf5c8[_0xa0a9('0x3b')]]['attended'])){logger[_0xa0a9('0x1e')](_0xa0a9('0x3c'),_0x1bf5c8[_0xa0a9('0x3b')]);this[_0xa0a9('0x15')](_0x1bf5c8[_0xa0a9('0x3b')]);}}catch(_0x41128b){logger[_0xa0a9('0x2c')]('[ACW][syncHangupRequest]\x20%s',_0x41128b[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')]['syncHangup']=function(_0x2cbd5e){try{if(this[_0xa0a9('0x17')][_0x2cbd5e[_0xa0a9('0x28')]]&&this['channels'][_0x2cbd5e['uniqueid']][_0xa0a9('0x3a')]){logger[_0xa0a9('0x1e')](_0xa0a9('0x3d'),_0x2cbd5e[_0xa0a9('0x28')]);this['startAcw'](_0x2cbd5e['uniqueid']);}else if(this[_0xa0a9('0x17')][_0x2cbd5e[_0xa0a9('0x3b')]]&&this['channels'][_0x2cbd5e['linkedid']][_0xa0a9('0x3a')]){logger[_0xa0a9('0x1e')](_0xa0a9('0x3e'),_0x2cbd5e[_0xa0a9('0x3b')]);this[_0xa0a9('0x15')](_0x2cbd5e[_0xa0a9('0x3b')]);}}catch(_0x24af09){logger[_0xa0a9('0x2c')](_0xa0a9('0x3f'),_0x24af09[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')]['syncAttendedTransfer']=function(_0x39070f){try{if(!_[_0xa0a9('0x40')](this[_0xa0a9('0x17')][_0x39070f['transfereeuniqueid']])){this[_0xa0a9('0x15')](_0x39070f[_0xa0a9('0x41')]);if(this[_0xa0a9('0x17')][_0x39070f['secondtransfereruniqueid']]){this[_0xa0a9('0x17')][_0x39070f[_0xa0a9('0x42')]][_0xa0a9('0x3a')]=!![];this[_0xa0a9('0x17')][_0x39070f[_0xa0a9('0x43')]]=this[_0xa0a9('0x17')][_0x39070f[_0xa0a9('0x42')]];delete this['channels'][_0x39070f[_0xa0a9('0x42')]];}}else if(!_[_0xa0a9('0x40')](this[_0xa0a9('0x17')][_0x39070f[_0xa0a9('0x43')]])){this[_0xa0a9('0x15')](_0x39070f[_0xa0a9('0x43')]);if(this[_0xa0a9('0x17')][_0x39070f['origtransfereruniqueid']]){this['channels'][_0x39070f['origtransfereruniqueid']][_0xa0a9('0x3a')]=!![];this['channels'][_0x39070f[_0xa0a9('0x41')]]=this['channels'][_0x39070f[_0xa0a9('0x44')]];delete this[_0xa0a9('0x17')][_0x39070f[_0xa0a9('0x44')]];}}}catch(_0x2f7ab4){logger[_0xa0a9('0x2c')](_0xa0a9('0x45'),_0x2f7ab4[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')]['syncBlindTransfer']=function(_0x5968ce){try{if(this[_0xa0a9('0x17')][_0x5968ce['transfereruniqueid']]){logger[_0xa0a9('0x1e')](_0xa0a9('0x46'),JSON[_0xa0a9('0x35')](_0x5968ce['transfereruniqueid']));this[_0xa0a9('0x15')](_0x5968ce['transfereruniqueid']);}else if(this[_0xa0a9('0x17')][_0x5968ce[_0xa0a9('0x47')]]){logger[_0xa0a9('0x1e')]('[%s][BLINDTRANSFER:LINKEDID]',JSON[_0xa0a9('0x35')](_0x5968ce['transfererlinkedid']));this[_0xa0a9('0x15')](_0x5968ce['transfererlinkedid']);}}catch(_0x2f253d){logger['error'](_0xa0a9('0x48'),_0x2f253d[_0xa0a9('0x2f')]);}};Acw[_0xa0a9('0x14')][_0xa0a9('0x49')]=function(_0x9dba0b){try{if(this[_0xa0a9('0x5')][_0x9dba0b['queue']]&&this[_0xa0a9('0x5')][_0x9dba0b[_0xa0a9('0x18')]][_0xa0a9('0x4a')]==='all'){if(this[_0xa0a9('0x6')][_0x9dba0b[_0xa0a9('0x16')]]){logger[_0xa0a9('0x1e')](_0xa0a9('0x4b'),_0x9dba0b[_0xa0a9('0x28')],_0x9dba0b['interface'],_0x9dba0b[_0xa0a9('0x18')]);return RpcUser[_0xa0a9('0x21')](this[_0xa0a9('0x6')][_0x9dba0b[_0xa0a9('0x16')]],_0xa0a9('0x4c'),_0x9dba0b[_0xa0a9('0x28')]);}}}catch(_0x3139b3){logger[_0xa0a9('0x2c')](_0xa0a9('0x4d'),_0x3139b3[_0xa0a9('0x2f')]);}};module['exports']=Acw;