0fa01ee9126829cfe024e50f7d35eeb4ac427d5b
[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 _0x82a6=['syncAgentRingNoAnswer','syncAttendedTransfer','blindtransfer','syncBlindTransfer','custom:agentConnectPreview','syncAgentConnectPreview','milliseconds','diff','prototype','lastPauseAt','timer','update','uniqueid','catch','error','[%s][UPDATE][ERRORS:%s]','finally','startAcw','queue','ACW','mandatoryDisposition','name','mandatoryDispositionPause','Action','then','getAgent','voicePause','info','[%s][INPAUSE][AGENT:%s][QUEUE:%s]','[%s][START][AGENT:%s][QUEUE:%s]','attended','destlinkedid','savePause','available','paused','[%s][TIMER:%s][AGENT:%s][QUEUE:%s]','acwTimeout','format','updateAcw','[ACW][START]\x20%s','message','stopAcw','[%s][TIMER][STOP][AGENT:%s]','pauseType','saveUnpause','[%s][UPDATE][ACWTIME:%s]','[ACW][TIMERS]','stringify','[ACW][STOP]\x20%s','syncAgentConnect','interface','[ACW][syncAgentConnect]\x20%s','[ACW][syncAgentConnectPreview]\x20%s','isUndefined','[%s][HANGUP:UNIQUEID]','linkedid','[ACW][syncHangupRequest]\x20%s','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','transfereeuniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','[%s][BLINDTRANSFER:LINKEDID]','[ACW][syncBlindTransfer]\x20%s','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s','lodash','moment','../ami','../../../config/logger','acw','../rpc/user','voiceQueues','agents','timers','channels','hanguprequest','syncHangupRequest','bind','hangup','syncHangup','agentringnoanswer'];(function(_0x5727a6,_0x57a97f){var _0x3ca94f=function(_0x3438ec){while(--_0x3438ec){_0x5727a6['push'](_0x5727a6['shift']());}};_0x3ca94f(++_0x57a97f);}(_0x82a6,0x19e));var _0x682a=function(_0x1c3e98,_0x489c1c){_0x1c3e98=_0x1c3e98-0x0;var _0x46f20e=_0x82a6[_0x1c3e98];return _0x46f20e;};'use strict';var _=require(_0x682a('0x0'));var moment=require(_0x682a('0x1'));var ami=require(_0x682a('0x2'));var logger=require(_0x682a('0x3'))(_0x682a('0x4'));var RpcUser=require(_0x682a('0x5'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x547e68){this[_0x682a('0x6')]=_0x547e68[_0x682a('0x6')];this['agents']=_0x547e68[_0x682a('0x7')];this[_0x682a('0x8')]=_0x547e68['timers'];this[_0x682a('0x9')]={};ami['on']('agentconnect',this['syncAgentConnect']['bind'](this));ami['on'](_0x682a('0xa'),this[_0x682a('0xb')][_0x682a('0xc')](this));ami['on'](_0x682a('0xd'),this[_0x682a('0xe')]['bind'](this));ami['on'](_0x682a('0xf'),this[_0x682a('0x10')]['bind'](this));ami['on']('attendedtransfer',this[_0x682a('0x11')][_0x682a('0xc')](this));ami['on'](_0x682a('0x12'),this[_0x682a('0x13')][_0x682a('0xc')](this));ami['on'](_0x682a('0x14'),this[_0x682a('0x15')][_0x682a('0xc')](this));}function getDiff(_0x5d95ec){var _0x41cf35=moment()[_0x682a('0x16')](0x0);var _0x52e490=moment(_0x5d95ec)[_0x682a('0x16')](0x0);return _0x41cf35[_0x682a('0x17')](_0x52e490,'seconds');}Acw[_0x682a('0x18')]['updateAcw']=function(_0x298cf1,_0xe3ff70){var _0x2e1ac7=this;var _0x4f1f48=getDiff(_0x2e1ac7[_0x682a('0x8')][_0x298cf1][_0x682a('0x19')]);clearTimeout(_0x2e1ac7[_0x682a('0x8')][_0x298cf1][_0x682a('0x1a')]);_0x2e1ac7[_0x682a('0x8')][_0x298cf1][_0x682a('0x1a')]=![];return RpcVoiceAgentReport[_0x682a('0x1b')]({'acwtime':_0x4f1f48},_0x2e1ac7[_0x682a('0x8')][_0x298cf1][_0x682a('0x1c')],_0x298cf1)['then'](function(_0x6a112a){logger['info']('[%s][UPDATE][ACWTIME:%s]',_0xe3ff70,_0x4f1f48,_0x6a112a);})[_0x682a('0x1d')](function(_0x553b55){logger[_0x682a('0x1e')](_0x682a('0x1f'),_0xe3ff70,_0x553b55);})[_0x682a('0x20')](function(){delete _0x2e1ac7['timers'][_0x298cf1];});};Acw[_0x682a('0x18')][_0x682a('0x21')]=function(_0x1835aa){try{var _0x4bf4b5=this;var _0x212ef4=this['channels'][_0x1835aa]['interface'];var _0xe59653=this[_0x682a('0x9')][_0x1835aa][_0x682a('0x22')];var _0x2a0ffa=this[_0x682a('0x6')][_0xe59653];var _0x1012a3=![];var _0x3dd62a=_0x682a('0x23');if(_0x2a0ffa[_0x682a('0x24')]&&_0x2a0ffa['mandatoryDispositionPause'][_0x682a('0x25')]){_0x1012a3=!![];_0x3dd62a=_0x2a0ffa[_0x682a('0x26')][_0x682a('0x25')];}return ami[_0x682a('0x27')]({'action':'QueuePause','interface':_0x212ef4,'paused':!![],'reason':_0x3dd62a})[_0x682a('0x28')](function(){if(_0x4bf4b5['agents'][_0x212ef4]){return RpcUser[_0x682a('0x29')](_0x4bf4b5[_0x682a('0x7')][_0x212ef4]['id'])[_0x682a('0x28')](function(_0xc4e15e){if(!_0xc4e15e||_0xc4e15e[_0x682a('0x2a')]){logger[_0x682a('0x2b')](_0x682a('0x2c'),_0x1835aa,_0x212ef4,_0xe59653);return;}logger[_0x682a('0x2b')](_0x682a('0x2d'),_0x1835aa,_0x212ef4,_0xe59653);var _0x59dcf6=_0x4bf4b5[_0x682a('0x9')][_0x1835aa][_0x682a('0x2e')]&&_0x4bf4b5[_0x682a('0x9')][_0x1835aa][_0x682a('0x2f')]?_0x4bf4b5['channels'][_0x1835aa][_0x682a('0x2f')]:_0x1835aa;return RpcUser[_0x682a('0x30')](_0x4bf4b5[_0x682a('0x7')][_0x212ef4],_0x3dd62a,_0x59dcf6)[_0x682a('0x28')](function(_0x19e95e){_0x4bf4b5[_0x682a('0x6')][_0xe59653][_0x682a('0x31')]-=0x1;_0x4bf4b5[_0x682a('0x6')][_0xe59653][_0x682a('0x32')]+=0x1;return _0x19e95e;});})['then'](function(_0x1647b6){if(_0x1012a3||!_0x1647b6){return;}_0x4bf4b5['timers'][_0x212ef4]={};logger[_0x682a('0x2b')](_0x682a('0x33'),_0x1835aa,_0x4bf4b5[_0x682a('0x6')][_0xe59653][_0x682a('0x34')],_0x212ef4,_0xe59653);_0x4bf4b5[_0x682a('0x8')][_0x212ef4]['timer']=setTimeout(_0x4bf4b5['stopAcw'][_0x682a('0xc')](_0x4bf4b5,_0x212ef4),_0x4bf4b5[_0x682a('0x6')][_0xe59653][_0x682a('0x34')]*0x3e8);_0x4bf4b5['timers'][_0x212ef4]['lastPauseAt']=moment()[_0x682a('0x35')]('YYYY-MM-DD\x20HH:mm:ss');_0x4bf4b5[_0x682a('0x8')][_0x212ef4]['uniqueid']=_0x1835aa;_0x4bf4b5[_0x682a('0x8')][_0x212ef4][_0x682a('0x22')]=_0xe59653;_0x4bf4b5[_0x682a('0x8')][_0x212ef4][_0x682a('0x36')]=_0x4bf4b5[_0x682a('0x36')]['bind'](_0x4bf4b5,_0x212ef4,_0x1835aa);});}})[_0x682a('0x1d')](function(){logger[_0x682a('0x1e')](_0x682a('0x33'),_0x1835aa,_0x4bf4b5[_0x682a('0x6')][_0xe59653][_0x682a('0x34')],_0x212ef4,_0xe59653);})[_0x682a('0x20')](function(){delete _0x4bf4b5[_0x682a('0x9')][_0x1835aa];});}catch(_0x59cdef){logger[_0x682a('0x1e')](_0x682a('0x37'),_0x59cdef[_0x682a('0x38')]);}};Acw['prototype'][_0x682a('0x39')]=function(_0x43eaf7){try{var _0x4cf4f7=this;if(_0x4cf4f7['timers'][_0x43eaf7]){_0x4cf4f7[_0x682a('0x8')][_0x43eaf7][_0x682a('0x1a')]=![];var _0x56c384=_0x4cf4f7[_0x682a('0x8')][_0x43eaf7][_0x682a('0x1c')];var _0x642089=_0x4cf4f7[_0x682a('0x8')][_0x43eaf7][_0x682a('0x22')];var _0x8b1029=_0x4cf4f7['voiceQueues'][_0x642089][_0x682a('0x34')];logger[_0x682a('0x2b')](_0x682a('0x3a'),_0x56c384,_0x43eaf7);RpcUser[_0x682a('0x29')](this[_0x682a('0x7')][_0x43eaf7]['id'])[_0x682a('0x28')](function(_0x38fd30){if(_0x38fd30[_0x682a('0x3b')]===_0x682a('0x23')){return RpcUser[_0x682a('0x3c')](_0x4cf4f7[_0x682a('0x7')][_0x43eaf7]);}});RpcVoiceAgentReport[_0x682a('0x1b')]({'acwtime':_0x8b1029,'agentacw':!![]},_0x56c384,_0x43eaf7)[_0x682a('0x28')](function(_0xa99b2){logger[_0x682a('0x2b')](_0x682a('0x3d'),_0x56c384,_0x8b1029,_0xa99b2);})[_0x682a('0x1d')](function(_0x43e9bf){logger[_0x682a('0x1e')]('[%s][UPDATE][ERRORS:%s]',_0x56c384,_0x43e9bf);});}else{logger[_0x682a('0x1e')]('[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer',_0x43eaf7);if(_0x4cf4f7[_0x682a('0x8')]){logger['info'](_0x682a('0x3e'),JSON[_0x682a('0x3f')](_0x4cf4f7['timers']));}}}catch(_0x47b4b2){logger[_0x682a('0x1e')](_0x682a('0x40'),_0x47b4b2[_0x682a('0x38')]);}};Acw[_0x682a('0x18')][_0x682a('0x41')]=function(_0x54f683){try{if(this[_0x682a('0x6')][_0x54f683[_0x682a('0x22')]]&&(this[_0x682a('0x6')][_0x54f683[_0x682a('0x22')]]['acw']||this['voiceQueues'][_0x54f683[_0x682a('0x22')]][_0x682a('0x24')])){if(this['agents'][_0x54f683[_0x682a('0x42')]]){this[_0x682a('0x9')][_0x54f683[_0x682a('0x1c')]]={'queue':_0x54f683[_0x682a('0x22')],'interface':_0x54f683['interface'],'destlinkedid':_0x54f683[_0x682a('0x2f')]};}}}catch(_0x385597){logger[_0x682a('0x1e')](_0x682a('0x43'),_0x385597[_0x682a('0x38')]);}};Acw[_0x682a('0x18')][_0x682a('0x15')]=function(_0x4475fe){try{if(this[_0x682a('0x6')][_0x4475fe[_0x682a('0x22')]]&&(this[_0x682a('0x6')][_0x4475fe[_0x682a('0x22')]][_0x682a('0x4')]||this[_0x682a('0x6')][_0x4475fe['queue']][_0x682a('0x24')])){if(this[_0x682a('0x7')][_0x4475fe[_0x682a('0x42')]]){this['channels'][_0x4475fe['uniqueid']]={'queue':_0x4475fe[_0x682a('0x22')],'interface':_0x4475fe[_0x682a('0x42')]};}}}catch(_0x5dbf1d){logger[_0x682a('0x1e')](_0x682a('0x44'),_0x5dbf1d[_0x682a('0x38')]);}};Acw[_0x682a('0x18')][_0x682a('0xb')]=function(_0x394a89){try{if(this[_0x682a('0x9')][_0x394a89[_0x682a('0x1c')]]&&_[_0x682a('0x45')](this[_0x682a('0x9')][_0x394a89[_0x682a('0x1c')]][_0x682a('0x2e')])){logger[_0x682a('0x2b')](_0x682a('0x46'),_0x394a89[_0x682a('0x1c')]);this[_0x682a('0x21')](_0x394a89['uniqueid']);}else if(this['channels'][_0x394a89['linkedid']]&&_[_0x682a('0x45')](this[_0x682a('0x9')][_0x394a89['linkedid']][_0x682a('0x2e')])){logger['info']('[%s][HANGUP:LINKEDID]',_0x394a89[_0x682a('0x47')]);this[_0x682a('0x21')](_0x394a89['linkedid']);}}catch(_0x1f4df5){logger['error'](_0x682a('0x48'),_0x1f4df5['message']);}};Acw[_0x682a('0x18')][_0x682a('0xe')]=function(_0x22f914){try{if(this['channels'][_0x22f914['uniqueid']]&&this[_0x682a('0x9')][_0x22f914[_0x682a('0x1c')]][_0x682a('0x2e')]){logger[_0x682a('0x2b')]('[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]',_0x22f914[_0x682a('0x1c')]);this['startAcw'](_0x22f914[_0x682a('0x1c')]);}else if(this[_0x682a('0x9')][_0x22f914[_0x682a('0x47')]]&&this[_0x682a('0x9')][_0x22f914[_0x682a('0x47')]]['attended']){logger[_0x682a('0x2b')](_0x682a('0x49'),_0x22f914[_0x682a('0x47')]);this['startAcw'](_0x22f914[_0x682a('0x47')]);}}catch(_0x1e0c6){logger[_0x682a('0x1e')](_0x682a('0x4a'),_0x1e0c6[_0x682a('0x38')]);}};Acw[_0x682a('0x18')][_0x682a('0x11')]=function(_0x2c56e4){try{if(!_['isNil'](this[_0x682a('0x9')][_0x2c56e4['transfereeuniqueid']])){this[_0x682a('0x21')](_0x2c56e4[_0x682a('0x4b')]);if(this[_0x682a('0x9')][_0x2c56e4['secondtransfereruniqueid']]){this[_0x682a('0x9')][_0x2c56e4['secondtransfereruniqueid']]['attended']=!![];this[_0x682a('0x9')][_0x2c56e4[_0x682a('0x4c')]]=this['channels'][_0x2c56e4['secondtransfereruniqueid']];delete this[_0x682a('0x9')][_0x2c56e4['secondtransfereruniqueid']];}}else if(!_['isNil'](this[_0x682a('0x9')][_0x2c56e4['transfertargetuniqueid']])){this[_0x682a('0x21')](_0x2c56e4[_0x682a('0x4c')]);if(this[_0x682a('0x9')][_0x2c56e4[_0x682a('0x4d')]]){this[_0x682a('0x9')][_0x2c56e4['origtransfereruniqueid']][_0x682a('0x2e')]=!![];this[_0x682a('0x9')][_0x2c56e4[_0x682a('0x4b')]]=this['channels'][_0x2c56e4[_0x682a('0x4d')]];delete this[_0x682a('0x9')][_0x2c56e4['origtransfereruniqueid']];}}}catch(_0x35ef5e){logger[_0x682a('0x1e')](_0x682a('0x4e'),_0x35ef5e['message']);}};Acw[_0x682a('0x18')]['syncBlindTransfer']=function(_0x1f63a2){try{if(this[_0x682a('0x9')][_0x1f63a2[_0x682a('0x4f')]]){logger[_0x682a('0x2b')](_0x682a('0x50'),JSON[_0x682a('0x3f')](_0x1f63a2[_0x682a('0x4f')]));this['startAcw'](_0x1f63a2[_0x682a('0x4f')]);}else if(this[_0x682a('0x9')][_0x1f63a2['transfererlinkedid']]){logger[_0x682a('0x2b')](_0x682a('0x51'),JSON[_0x682a('0x3f')](_0x1f63a2['transfererlinkedid']));this[_0x682a('0x21')](_0x1f63a2['transfererlinkedid']);}}catch(_0x61d8ed){logger['error'](_0x682a('0x52'),_0x61d8ed['message']);}};Acw[_0x682a('0x18')]['syncAgentRingNoAnswer']=function(_0x1daf43){try{if(this[_0x682a('0x6')][_0x1daf43[_0x682a('0x22')]]&&this['voiceQueues'][_0x1daf43[_0x682a('0x22')]]['autopause']==='all'){if(this[_0x682a('0x7')][_0x1daf43[_0x682a('0x42')]]){logger[_0x682a('0x2b')](_0x682a('0x53'),_0x1daf43['uniqueid'],_0x1daf43['interface'],_0x1daf43['queue']);return RpcUser[_0x682a('0x30')](this[_0x682a('0x7')][_0x1daf43['interface']],_0x682a('0x54'),_0x1daf43[_0x682a('0x1c')]);}}}catch(_0x3104c8){logger[_0x682a('0x1e')](_0x682a('0x55'),_0x3104c8[_0x682a('0x38')]);}};module['exports']=Acw;