Built motion from commit 4c579f6b.|2.5.32
[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 _0x6b31=['info','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','timer','stopAcw','acwTimeout','uniqueid','lastPauseAt','[%s][UPDATE][ACWTIME:%s]','catch','error','finally','[ACW][START]\x20%s','message','saveUnpause','update','[%s][UPDATE][ERRORS:%s]','[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer','[ACW][TIMERS]','stringify','[ACW][STOP]\x20%s','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','[%s][HANGUP:UNIQUEID]','isUndefined','linkedid','[%s][HANGUP:LINKEDID]','[ACW][syncHangupRequest]\x20%s','syncHangup','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[ACW][syncHangup]\x20%s','syncAttendedTransfer','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','transfererlinkedid','[ACW][syncBlindTransfer]\x20%s','autopause','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s','exports','util','lodash','moment','../ami','acw','../rpc/user','../rpc/voiceAgentReport','voiceQueues','agents','timers','agentconnect','syncAgentConnect','bind','hanguprequest','syncHangupRequest','hangup','agentringnoanswer','syncAgentRingNoAnswer','attendedtransfer','syncBlindTransfer','syncAgentConnectPreview','milliseconds','diff','prototype','startAcw','interface','queue','mandatoryDisposition','mandatoryDispositionPause','name','Action','getAgent','then','[%s][START][AGENT:%s][QUEUE:%s]','channels','attended','destlinkedid','savePause'];(function(_0x1272d7,_0x5245a1){var _0x59c93e=function(_0x27a22b){while(--_0x27a22b){_0x1272d7['push'](_0x1272d7['shift']());}};_0x59c93e(++_0x5245a1);}(_0x6b31,0x84));var _0x16b3=function(_0x4e0f67,_0x344276){_0x4e0f67=_0x4e0f67-0x0;var _0x211dca=_0x6b31[_0x4e0f67];return _0x211dca;};'use strict';var util=require(_0x16b3('0x0'));var _=require(_0x16b3('0x1'));var moment=require(_0x16b3('0x2'));var ami=require(_0x16b3('0x3'));var logger=require('../../../config/logger')(_0x16b3('0x4'));var RpcUser=require(_0x16b3('0x5'));var RpcVoiceAgentReport=require(_0x16b3('0x6'));function Acw(_0x3d54e8){this[_0x16b3('0x7')]=_0x3d54e8[_0x16b3('0x7')];this[_0x16b3('0x8')]=_0x3d54e8[_0x16b3('0x8')];this[_0x16b3('0x9')]=_0x3d54e8['timers'];this['channels']={};ami['on'](_0x16b3('0xa'),this[_0x16b3('0xb')][_0x16b3('0xc')](this));ami['on'](_0x16b3('0xd'),this[_0x16b3('0xe')]['bind'](this));ami['on'](_0x16b3('0xf'),this['syncHangup'][_0x16b3('0xc')](this));ami['on'](_0x16b3('0x10'),this[_0x16b3('0x11')][_0x16b3('0xc')](this));ami['on'](_0x16b3('0x12'),this['syncAttendedTransfer'][_0x16b3('0xc')](this));ami['on']('blindtransfer',this[_0x16b3('0x13')][_0x16b3('0xc')](this));ami['on']('custom:agentConnectPreview',this[_0x16b3('0x14')][_0x16b3('0xc')](this));}function getDiff(_0x2cf926){var _0x2b8398=moment()[_0x16b3('0x15')](0x0);var _0x16a642=moment(_0x2cf926)['milliseconds'](0x0);return _0x2b8398[_0x16b3('0x16')](_0x16a642,'seconds');}Acw[_0x16b3('0x17')][_0x16b3('0x18')]=function(_0x6f50e4){try{var _0x24551a=this;var _0x326e0b=this['channels'][_0x6f50e4][_0x16b3('0x19')];var _0x22a256=this['channels'][_0x6f50e4][_0x16b3('0x1a')];var _0x29832e=this[_0x16b3('0x7')][_0x22a256];var _0x4324de=![];var _0x18a332='ACW';if(_0x29832e[_0x16b3('0x1b')]){if(_0x29832e[_0x16b3('0x1c')][_0x16b3('0x1d')]){_0x4324de=!![];_0x18a332=_0x29832e[_0x16b3('0x1c')]['name'];}}ami[_0x16b3('0x1e')]({'action':'QueuePause','interface':_0x326e0b,'paused':!![],'reason':_0x18a332})['then'](function(_0x1b50b5){if(_0x24551a[_0x16b3('0x8')][_0x326e0b]){return RpcUser[_0x16b3('0x1f')](_0x24551a[_0x16b3('0x8')][_0x326e0b]['id'])[_0x16b3('0x20')](function(_0x336485){if(_0x336485&&!_0x336485['voicePause']){logger['info'](_0x16b3('0x21'),_0x6f50e4,_0x326e0b,_0x22a256);var _0xe76367=_0x24551a[_0x16b3('0x22')][_0x6f50e4][_0x16b3('0x23')]&&_0x24551a[_0x16b3('0x22')][_0x6f50e4][_0x16b3('0x24')]?_0x24551a[_0x16b3('0x22')][_0x6f50e4][_0x16b3('0x24')]:_0x6f50e4;return RpcUser[_0x16b3('0x25')](_0x24551a[_0x16b3('0x8')][_0x326e0b],_0x18a332,_0xe76367)['then'](function(_0xea6550){if(!_0x4324de){_0x24551a[_0x16b3('0x9')][_0x326e0b]={};logger[_0x16b3('0x26')](_0x16b3('0x27'),_0x6f50e4,_0x24551a[_0x16b3('0x7')][_0x22a256]['acwTimeout'],_0x326e0b,_0x22a256);_0x24551a[_0x16b3('0x9')][_0x326e0b][_0x16b3('0x28')]=setTimeout(_0x24551a[_0x16b3('0x29')]['bind'](_0x24551a,_0x326e0b),_0x24551a['voiceQueues'][_0x22a256][_0x16b3('0x2a')]*0x3e8);_0x24551a[_0x16b3('0x9')][_0x326e0b]['lastPauseAt']=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x24551a[_0x16b3('0x9')][_0x326e0b][_0x16b3('0x2b')]=_0x6f50e4;_0x24551a[_0x16b3('0x9')][_0x326e0b][_0x16b3('0x1a')]=_0x22a256;_0x24551a[_0x16b3('0x9')][_0x326e0b]['updateAcw']=function(){var _0x21dc40=getDiff(_0x24551a['timers'][_0x326e0b][_0x16b3('0x2c')]);clearTimeout(_0x24551a[_0x16b3('0x9')][_0x326e0b][_0x16b3('0x28')]);_0x24551a['timers'][_0x326e0b][_0x16b3('0x28')]=![];RpcVoiceAgentReport['update']({'acwtime':_0x21dc40},_0x24551a[_0x16b3('0x9')][_0x326e0b]['uniqueid'],_0x326e0b)[_0x16b3('0x20')](function(_0x5821a5){logger[_0x16b3('0x26')](_0x16b3('0x2d'),_0x6f50e4,_0x21dc40,_0x5821a5);})[_0x16b3('0x2e')](function(_0x57ab82){logger[_0x16b3('0x2f')]('[%s][UPDATE][ERRORS:%s]',_0x6f50e4,_0x57ab82);});delete _0x24551a[_0x16b3('0x9')][_0x326e0b];};}});}else{logger[_0x16b3('0x26')]('[%s][INPAUSE][AGENT:%s][QUEUE:%s]',_0x6f50e4,_0x326e0b,_0x22a256);}});}})['catch'](function(_0x2e5629){logger[_0x16b3('0x2f')](_0x16b3('0x27'),_0x6f50e4,_0x24551a['voiceQueues'][_0x22a256][_0x16b3('0x2a')],_0x326e0b,_0x22a256);})[_0x16b3('0x30')](function(){delete _0x24551a[_0x16b3('0x22')][_0x6f50e4];});}catch(_0x3cfcba){logger[_0x16b3('0x2f')](_0x16b3('0x31'),_0x3cfcba[_0x16b3('0x32')]);}};Acw[_0x16b3('0x17')][_0x16b3('0x29')]=function(_0x43afc2){try{var _0x3b3b1d=this;if(_0x3b3b1d[_0x16b3('0x9')][_0x43afc2]){_0x3b3b1d[_0x16b3('0x9')][_0x43afc2][_0x16b3('0x28')]=![];var _0xb6b21=_0x3b3b1d['timers'][_0x43afc2][_0x16b3('0x2b')];var _0x39b471=_0x3b3b1d['timers'][_0x43afc2][_0x16b3('0x1a')];var _0x6ca6dc=_0x3b3b1d[_0x16b3('0x7')][_0x39b471][_0x16b3('0x2a')];logger[_0x16b3('0x26')]('[%s][TIMER][STOP][AGENT:%s]',_0xb6b21,_0x43afc2);RpcUser[_0x16b3('0x33')](this[_0x16b3('0x8')][_0x43afc2]);RpcVoiceAgentReport[_0x16b3('0x34')]({'acwtime':_0x6ca6dc,'agentacw':!![]},_0xb6b21,_0x43afc2)[_0x16b3('0x20')](function(_0xce5cc7){logger['info'](_0x16b3('0x2d'),_0xb6b21,_0x6ca6dc,_0xce5cc7);})[_0x16b3('0x2e')](function(_0x9fcae5){logger[_0x16b3('0x2f')](_0x16b3('0x35'),_0xb6b21,_0x9fcae5);});}else{logger[_0x16b3('0x2f')](_0x16b3('0x36'),_0x43afc2);if(_0x3b3b1d[_0x16b3('0x9')]){logger[_0x16b3('0x26')](_0x16b3('0x37'),JSON[_0x16b3('0x38')](_0x3b3b1d[_0x16b3('0x9')]));}}}catch(_0x54ea5a){logger[_0x16b3('0x2f')](_0x16b3('0x39'),_0x54ea5a[_0x16b3('0x32')]);}};Acw[_0x16b3('0x17')][_0x16b3('0xb')]=function(_0x532123){try{if(this[_0x16b3('0x7')][_0x532123[_0x16b3('0x1a')]]&&(this[_0x16b3('0x7')][_0x532123[_0x16b3('0x1a')]][_0x16b3('0x4')]||this[_0x16b3('0x7')][_0x532123[_0x16b3('0x1a')]][_0x16b3('0x1b')])){if(this['agents'][_0x532123[_0x16b3('0x19')]]){this[_0x16b3('0x22')][_0x532123[_0x16b3('0x2b')]]={'queue':_0x532123[_0x16b3('0x1a')],'interface':_0x532123[_0x16b3('0x19')],'destlinkedid':_0x532123[_0x16b3('0x24')]};}}}catch(_0x1b7aff){logger[_0x16b3('0x2f')](_0x16b3('0x3a'),_0x1b7aff[_0x16b3('0x32')]);}};Acw['prototype']['syncAgentConnectPreview']=function(_0x57607a){try{if(this[_0x16b3('0x7')][_0x57607a[_0x16b3('0x1a')]]&&(this['voiceQueues'][_0x57607a[_0x16b3('0x1a')]][_0x16b3('0x4')]||this['voiceQueues'][_0x57607a[_0x16b3('0x1a')]][_0x16b3('0x1b')])){if(this[_0x16b3('0x8')][_0x57607a[_0x16b3('0x19')]]){this['channels'][_0x57607a[_0x16b3('0x2b')]]={'queue':_0x57607a[_0x16b3('0x1a')],'interface':_0x57607a[_0x16b3('0x19')]};}}}catch(_0x1e5403){logger[_0x16b3('0x2f')](_0x16b3('0x3b'),_0x1e5403['message']);}};Acw[_0x16b3('0x17')][_0x16b3('0xe')]=function(_0x2701c9){try{if(this[_0x16b3('0x22')][_0x2701c9[_0x16b3('0x2b')]]&&_['isUndefined'](this['channels'][_0x2701c9[_0x16b3('0x2b')]][_0x16b3('0x23')])){logger[_0x16b3('0x26')](_0x16b3('0x3c'),_0x2701c9[_0x16b3('0x2b')]);this['startAcw'](_0x2701c9[_0x16b3('0x2b')]);}else if(this[_0x16b3('0x22')][_0x2701c9['linkedid']]&&_[_0x16b3('0x3d')](this[_0x16b3('0x22')][_0x2701c9[_0x16b3('0x3e')]][_0x16b3('0x23')])){logger[_0x16b3('0x26')](_0x16b3('0x3f'),_0x2701c9[_0x16b3('0x3e')]);this['startAcw'](_0x2701c9[_0x16b3('0x3e')]);}}catch(_0x49c7d4){logger[_0x16b3('0x2f')](_0x16b3('0x40'),_0x49c7d4[_0x16b3('0x32')]);}};Acw[_0x16b3('0x17')][_0x16b3('0x41')]=function(_0x51a728){try{if(this[_0x16b3('0x22')][_0x51a728[_0x16b3('0x2b')]]&&this[_0x16b3('0x22')][_0x51a728[_0x16b3('0x2b')]][_0x16b3('0x23')]){logger[_0x16b3('0x26')](_0x16b3('0x42'),_0x51a728[_0x16b3('0x2b')]);this[_0x16b3('0x18')](_0x51a728[_0x16b3('0x2b')]);}else if(this['channels'][_0x51a728[_0x16b3('0x3e')]]&&this[_0x16b3('0x22')][_0x51a728[_0x16b3('0x3e')]]['attended']){logger[_0x16b3('0x26')]('[%s][HANGUPATTENDEDTRANSFER:LINKEDID]',_0x51a728[_0x16b3('0x3e')]);this[_0x16b3('0x18')](_0x51a728['linkedid']);}}catch(_0x1cff7c){logger[_0x16b3('0x2f')](_0x16b3('0x43'),_0x1cff7c['message']);}};Acw['prototype'][_0x16b3('0x44')]=function(_0x190116){try{if(!_[_0x16b3('0x45')](this[_0x16b3('0x22')][_0x190116[_0x16b3('0x46')]])){this[_0x16b3('0x18')](_0x190116['transfereeuniqueid']);if(this['channels'][_0x190116['secondtransfereruniqueid']]){this[_0x16b3('0x22')][_0x190116[_0x16b3('0x47')]][_0x16b3('0x23')]=!![];this[_0x16b3('0x22')][_0x190116[_0x16b3('0x48')]]=this[_0x16b3('0x22')][_0x190116['secondtransfereruniqueid']];delete this[_0x16b3('0x22')][_0x190116[_0x16b3('0x47')]];}}else if(!_[_0x16b3('0x45')](this[_0x16b3('0x22')][_0x190116[_0x16b3('0x48')]])){this[_0x16b3('0x18')](_0x190116[_0x16b3('0x48')]);if(this[_0x16b3('0x22')][_0x190116[_0x16b3('0x49')]]){this[_0x16b3('0x22')][_0x190116[_0x16b3('0x49')]]['attended']=!![];this['channels'][_0x190116[_0x16b3('0x46')]]=this[_0x16b3('0x22')][_0x190116['origtransfereruniqueid']];delete this['channels'][_0x190116[_0x16b3('0x49')]];}}}catch(_0x14f569){logger[_0x16b3('0x2f')](_0x16b3('0x4a'),_0x14f569[_0x16b3('0x32')]);}};Acw['prototype'][_0x16b3('0x13')]=function(_0x42e77d){try{if(this[_0x16b3('0x22')][_0x42e77d[_0x16b3('0x4b')]]){logger['info'](_0x16b3('0x4c'),JSON[_0x16b3('0x38')](_0x42e77d['transfereruniqueid']));this[_0x16b3('0x18')](_0x42e77d[_0x16b3('0x4b')]);}else if(this[_0x16b3('0x22')][_0x42e77d[_0x16b3('0x4d')]]){logger['info']('[%s][BLINDTRANSFER:LINKEDID]',JSON[_0x16b3('0x38')](_0x42e77d[_0x16b3('0x4d')]));this[_0x16b3('0x18')](_0x42e77d[_0x16b3('0x4d')]);}}catch(_0x14f8d6){logger[_0x16b3('0x2f')](_0x16b3('0x4e'),_0x14f8d6[_0x16b3('0x32')]);}};Acw[_0x16b3('0x17')]['syncAgentRingNoAnswer']=function(_0x42a2ed){try{if(this[_0x16b3('0x7')][_0x42a2ed['queue']]&&this[_0x16b3('0x7')][_0x42a2ed[_0x16b3('0x1a')]][_0x16b3('0x4f')]===_0x16b3('0x50')){if(this[_0x16b3('0x8')][_0x42a2ed[_0x16b3('0x19')]]){logger[_0x16b3('0x26')](_0x16b3('0x51'),_0x42a2ed[_0x16b3('0x2b')],_0x42a2ed[_0x16b3('0x19')],_0x42a2ed[_0x16b3('0x1a')]);return RpcUser[_0x16b3('0x25')](this[_0x16b3('0x8')][_0x42a2ed['interface']],_0x16b3('0x52'),_0x42a2ed[_0x16b3('0x2b')]);}}}catch(_0x361631){logger['error'](_0x16b3('0x53'),_0x361631[_0x16b3('0x32')]);}};module[_0x16b3('0x54')]=Acw;