Built motion from commit 3a7e82ea.|2.6.29
[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 _0x59c3=['../ami','acw','../rpc/user','voiceQueues','agents','timers','channels','agentconnect','syncAgentConnect','bind','hanguprequest','syncHangupRequest','hangup','syncHangup','agentringnoanswer','attendedtransfer','syncAttendedTransfer','blindtransfer','custom:agentConnectPreview','syncAgentConnectPreview','diff','seconds','prototype','timer','update','then','info','[%s][UPDATE][ACWTIME:%s]','catch','error','[%s][UPDATE][ERRORS:%s]','interface','ACW','mandatoryDispositionPause','name','Action','getAgent','[%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','stopAcw','lastPauseAt','format','YYYY-MM-DD\x20HH:mm:ss','queue','updateAcw','finally','[ACW][START]\x20%s','uniqueid','[%s][TIMER][STOP][AGENT:%s]','saveUnpause','[ACW][TIMERS]','[ACW][STOP]\x20%s','message','mandatoryDisposition','isUndefined','startAcw','linkedid','[%s][HANGUPATTENDEDTRANSFER:UNIQUEID]','[%s][HANGUPATTENDEDTRANSFER:LINKEDID]','[ACW][syncHangup]\x20%s','isNil','transfereeuniqueid','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','[ACW][syncAttendedTransfer]\x20%s','syncBlindTransfer','transfereruniqueid','[%s][BLINDTRANSFER:UNIQUEID]','stringify','transfererlinkedid','[%s][BLINDTRANSFER:LINKEDID]','[ACW][syncBlindTransfer]\x20%s','all','[%s][AUTOPAUSE][AGENT:%s][QUEUE:%]','Auto-Pause','[ACW][syncAgentRingNoAnswer]\x20%s'];(function(_0x53d729,_0x1a2198){var _0x568f90=function(_0x48bd5b){while(--_0x48bd5b){_0x53d729['push'](_0x53d729['shift']());}};_0x568f90(++_0x1a2198);}(_0x59c3,0x150));var _0x359c=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0x59c3[_0x2dafbe];return _0x58a45a;};'use strict';var _=require('lodash');var moment=require('moment');var ami=require(_0x359c('0x0'));var logger=require('../../../config/logger')(_0x359c('0x1'));var RpcUser=require(_0x359c('0x2'));var RpcVoiceAgentReport=require('../rpc/voiceAgentReport');function Acw(_0x6237e4){this[_0x359c('0x3')]=_0x6237e4[_0x359c('0x3')];this[_0x359c('0x4')]=_0x6237e4[_0x359c('0x4')];this[_0x359c('0x5')]=_0x6237e4['timers'];this[_0x359c('0x6')]={};ami['on'](_0x359c('0x7'),this[_0x359c('0x8')][_0x359c('0x9')](this));ami['on'](_0x359c('0xa'),this[_0x359c('0xb')][_0x359c('0x9')](this));ami['on'](_0x359c('0xc'),this[_0x359c('0xd')][_0x359c('0x9')](this));ami['on'](_0x359c('0xe'),this['syncAgentRingNoAnswer'][_0x359c('0x9')](this));ami['on'](_0x359c('0xf'),this[_0x359c('0x10')]['bind'](this));ami['on'](_0x359c('0x11'),this['syncBlindTransfer'][_0x359c('0x9')](this));ami['on'](_0x359c('0x12'),this[_0x359c('0x13')][_0x359c('0x9')](this));}function getDiff(_0x18d1fc){var _0x10508a=moment()['milliseconds'](0x0);var _0x1f7d52=moment(_0x18d1fc)['milliseconds'](0x0);return _0x10508a[_0x359c('0x14')](_0x1f7d52,_0x359c('0x15'));}Acw[_0x359c('0x16')]['updateAcw']=function(_0x1d7f12,_0x44bd37){var _0x59daa6=this;var _0x225a36=getDiff(_0x59daa6[_0x359c('0x5')][_0x1d7f12]['lastPauseAt']);clearTimeout(_0x59daa6[_0x359c('0x5')][_0x1d7f12][_0x359c('0x17')]);_0x59daa6[_0x359c('0x5')][_0x1d7f12]['timer']=![];return RpcVoiceAgentReport[_0x359c('0x18')]({'acwtime':_0x225a36},_0x59daa6[_0x359c('0x5')][_0x1d7f12]['uniqueid'],_0x1d7f12)[_0x359c('0x19')](function(_0x53236a){logger[_0x359c('0x1a')](_0x359c('0x1b'),_0x44bd37,_0x225a36,_0x53236a);})[_0x359c('0x1c')](function(_0x519476){logger[_0x359c('0x1d')](_0x359c('0x1e'),_0x44bd37,_0x519476);})['finally'](function(){delete _0x59daa6[_0x359c('0x5')][_0x1d7f12];});};Acw[_0x359c('0x16')]['startAcw']=function(_0x148f43){try{var _0x1a4a76=this;var _0x5af924=this[_0x359c('0x6')][_0x148f43][_0x359c('0x1f')];var _0x514e19=this[_0x359c('0x6')][_0x148f43]['queue'];var _0x58961e=this[_0x359c('0x3')][_0x514e19];var _0x47311d=![];var _0x4f3f8c=_0x359c('0x20');if(_0x58961e['mandatoryDisposition']&&_0x58961e[_0x359c('0x21')]['name']){_0x47311d=!![];_0x4f3f8c=_0x58961e[_0x359c('0x21')][_0x359c('0x22')];}return ami[_0x359c('0x23')]({'action':'QueuePause','interface':_0x5af924,'paused':!![],'reason':_0x4f3f8c})[_0x359c('0x19')](function(){if(_0x1a4a76['agents'][_0x5af924]){return RpcUser[_0x359c('0x24')](_0x1a4a76[_0x359c('0x4')][_0x5af924]['id'])[_0x359c('0x19')](function(_0x3e11d3){if(!_0x3e11d3||_0x3e11d3['voicePause']){logger[_0x359c('0x1a')](_0x359c('0x25'),_0x148f43,_0x5af924,_0x514e19);return;}logger[_0x359c('0x1a')](_0x359c('0x26'),_0x148f43,_0x5af924,_0x514e19);var _0x386933=_0x1a4a76[_0x359c('0x6')][_0x148f43][_0x359c('0x27')]&&_0x1a4a76[_0x359c('0x6')][_0x148f43][_0x359c('0x28')]?_0x1a4a76['channels'][_0x148f43]['destlinkedid']:_0x148f43;return RpcUser[_0x359c('0x29')](_0x1a4a76[_0x359c('0x4')][_0x5af924],_0x4f3f8c,_0x386933)[_0x359c('0x19')](function(_0x35a7c0){_0x1a4a76[_0x359c('0x3')][_0x514e19][_0x359c('0x2a')]-=0x1;_0x1a4a76['voiceQueues'][_0x514e19][_0x359c('0x2b')]+=0x1;return _0x35a7c0;});})['then'](function(_0x4e6153){if(_0x47311d||!_0x4e6153){return;}_0x1a4a76[_0x359c('0x5')][_0x5af924]={};logger[_0x359c('0x1a')](_0x359c('0x2c'),_0x148f43,_0x1a4a76['voiceQueues'][_0x514e19][_0x359c('0x2d')],_0x5af924,_0x514e19);_0x1a4a76[_0x359c('0x5')][_0x5af924][_0x359c('0x17')]=setTimeout(_0x1a4a76[_0x359c('0x2e')]['bind'](_0x1a4a76,_0x5af924),_0x1a4a76['voiceQueues'][_0x514e19][_0x359c('0x2d')]*0x3e8);_0x1a4a76['timers'][_0x5af924][_0x359c('0x2f')]=moment()[_0x359c('0x30')](_0x359c('0x31'));_0x1a4a76[_0x359c('0x5')][_0x5af924]['uniqueid']=_0x148f43;_0x1a4a76[_0x359c('0x5')][_0x5af924][_0x359c('0x32')]=_0x514e19;_0x1a4a76[_0x359c('0x5')][_0x5af924]['updateAcw']=_0x1a4a76[_0x359c('0x33')][_0x359c('0x9')](_0x1a4a76,_0x5af924,_0x148f43);});}})['catch'](function(){logger[_0x359c('0x1d')]('[%s][TIMER:%s][AGENT:%s][QUEUE:%s]',_0x148f43,_0x1a4a76[_0x359c('0x3')][_0x514e19]['acwTimeout'],_0x5af924,_0x514e19);})[_0x359c('0x34')](function(){delete _0x1a4a76[_0x359c('0x6')][_0x148f43];});}catch(_0x3dc4fa){logger[_0x359c('0x1d')](_0x359c('0x35'),_0x3dc4fa['message']);}};Acw[_0x359c('0x16')][_0x359c('0x2e')]=function(_0x19f259){try{var _0x16daa5=this;if(_0x16daa5[_0x359c('0x5')][_0x19f259]){_0x16daa5[_0x359c('0x5')][_0x19f259][_0x359c('0x17')]=![];var _0x311ba9=_0x16daa5[_0x359c('0x5')][_0x19f259][_0x359c('0x36')];var _0x536375=_0x16daa5[_0x359c('0x5')][_0x19f259][_0x359c('0x32')];var _0x19a61c=_0x16daa5[_0x359c('0x3')][_0x536375][_0x359c('0x2d')];logger[_0x359c('0x1a')](_0x359c('0x37'),_0x311ba9,_0x19f259);RpcUser[_0x359c('0x24')](this[_0x359c('0x4')][_0x19f259]['id'])[_0x359c('0x19')](function(_0xce0948){if(_0xce0948['pauseType']===_0x359c('0x20')){return RpcUser[_0x359c('0x38')](_0x16daa5['agents'][_0x19f259]);}});RpcVoiceAgentReport[_0x359c('0x18')]({'acwtime':_0x19a61c,'agentacw':!![]},_0x311ba9,_0x19f259)[_0x359c('0x19')](function(_0x1b07b2){logger[_0x359c('0x1a')](_0x359c('0x1b'),_0x311ba9,_0x19a61c,_0x1b07b2);})[_0x359c('0x1c')](function(_0x311e4d){logger[_0x359c('0x1d')](_0x359c('0x1e'),_0x311ba9,_0x311e4d);});}else{logger['error']('[ACW][STOP]\x20Interface\x20%s\x20doesn\x27t\x20have\x20timer',_0x19f259);if(_0x16daa5[_0x359c('0x5')]){logger[_0x359c('0x1a')](_0x359c('0x39'),JSON['stringify'](_0x16daa5[_0x359c('0x5')]));}}}catch(_0x1abeae){logger[_0x359c('0x1d')](_0x359c('0x3a'),_0x1abeae[_0x359c('0x3b')]);}};Acw[_0x359c('0x16')][_0x359c('0x8')]=function(_0x3e5105){try{if(this[_0x359c('0x3')][_0x3e5105[_0x359c('0x32')]]&&(this[_0x359c('0x3')][_0x3e5105[_0x359c('0x32')]][_0x359c('0x1')]||this['voiceQueues'][_0x3e5105[_0x359c('0x32')]][_0x359c('0x3c')])){if(this[_0x359c('0x4')][_0x3e5105[_0x359c('0x1f')]]){this['channels'][_0x3e5105[_0x359c('0x36')]]={'queue':_0x3e5105[_0x359c('0x32')],'interface':_0x3e5105[_0x359c('0x1f')],'destlinkedid':_0x3e5105['destlinkedid']};}}}catch(_0x4bc404){logger[_0x359c('0x1d')]('[ACW][syncAgentConnect]\x20%s',_0x4bc404['message']);}};Acw[_0x359c('0x16')][_0x359c('0x13')]=function(_0x410246){try{if(this[_0x359c('0x3')][_0x410246[_0x359c('0x32')]]&&(this[_0x359c('0x3')][_0x410246[_0x359c('0x32')]][_0x359c('0x1')]||this['voiceQueues'][_0x410246[_0x359c('0x32')]]['mandatoryDisposition'])){if(this['agents'][_0x410246[_0x359c('0x1f')]]){this[_0x359c('0x6')][_0x410246['uniqueid']]={'queue':_0x410246[_0x359c('0x32')],'interface':_0x410246['interface']};}}}catch(_0x3fa065){logger[_0x359c('0x1d')]('[ACW][syncAgentConnectPreview]\x20%s',_0x3fa065[_0x359c('0x3b')]);}};Acw['prototype'][_0x359c('0xb')]=function(_0x5dba4d){try{if(this[_0x359c('0x6')][_0x5dba4d['uniqueid']]&&_[_0x359c('0x3d')](this[_0x359c('0x6')][_0x5dba4d[_0x359c('0x36')]][_0x359c('0x27')])){logger[_0x359c('0x1a')]('[%s][HANGUP:UNIQUEID]',_0x5dba4d['uniqueid']);this[_0x359c('0x3e')](_0x5dba4d[_0x359c('0x36')]);}else if(this[_0x359c('0x6')][_0x5dba4d['linkedid']]&&_[_0x359c('0x3d')](this['channels'][_0x5dba4d['linkedid']][_0x359c('0x27')])){logger[_0x359c('0x1a')]('[%s][HANGUP:LINKEDID]',_0x5dba4d[_0x359c('0x3f')]);this[_0x359c('0x3e')](_0x5dba4d[_0x359c('0x3f')]);}}catch(_0x1a4e9b){logger[_0x359c('0x1d')]('[ACW][syncHangupRequest]\x20%s',_0x1a4e9b[_0x359c('0x3b')]);}};Acw[_0x359c('0x16')][_0x359c('0xd')]=function(_0x20afb8){try{if(this['channels'][_0x20afb8['uniqueid']]&&this[_0x359c('0x6')][_0x20afb8[_0x359c('0x36')]][_0x359c('0x27')]){logger['info'](_0x359c('0x40'),_0x20afb8['uniqueid']);this['startAcw'](_0x20afb8[_0x359c('0x36')]);}else if(this[_0x359c('0x6')][_0x20afb8[_0x359c('0x3f')]]&&this[_0x359c('0x6')][_0x20afb8[_0x359c('0x3f')]]['attended']){logger[_0x359c('0x1a')](_0x359c('0x41'),_0x20afb8['linkedid']);this[_0x359c('0x3e')](_0x20afb8[_0x359c('0x3f')]);}}catch(_0x591af6){logger['error'](_0x359c('0x42'),_0x591af6['message']);}};Acw[_0x359c('0x16')]['syncAttendedTransfer']=function(_0x376bb7){try{if(!_[_0x359c('0x43')](this[_0x359c('0x6')][_0x376bb7['transfereeuniqueid']])){this[_0x359c('0x3e')](_0x376bb7[_0x359c('0x44')]);if(this[_0x359c('0x6')][_0x376bb7[_0x359c('0x45')]]){this[_0x359c('0x6')][_0x376bb7[_0x359c('0x45')]][_0x359c('0x27')]=!![];this[_0x359c('0x6')][_0x376bb7[_0x359c('0x46')]]=this['channels'][_0x376bb7['secondtransfereruniqueid']];delete this[_0x359c('0x6')][_0x376bb7[_0x359c('0x45')]];}}else if(!_[_0x359c('0x43')](this[_0x359c('0x6')][_0x376bb7['transfertargetuniqueid']])){this[_0x359c('0x3e')](_0x376bb7[_0x359c('0x46')]);if(this[_0x359c('0x6')][_0x376bb7[_0x359c('0x47')]]){this[_0x359c('0x6')][_0x376bb7[_0x359c('0x47')]][_0x359c('0x27')]=!![];this[_0x359c('0x6')][_0x376bb7[_0x359c('0x44')]]=this[_0x359c('0x6')][_0x376bb7[_0x359c('0x47')]];delete this[_0x359c('0x6')][_0x376bb7[_0x359c('0x47')]];}}}catch(_0x507aba){logger[_0x359c('0x1d')](_0x359c('0x48'),_0x507aba[_0x359c('0x3b')]);}};Acw['prototype'][_0x359c('0x49')]=function(_0x5b0707){try{if(this['channels'][_0x5b0707[_0x359c('0x4a')]]){logger[_0x359c('0x1a')](_0x359c('0x4b'),JSON[_0x359c('0x4c')](_0x5b0707[_0x359c('0x4a')]));this[_0x359c('0x3e')](_0x5b0707[_0x359c('0x4a')]);}else if(this[_0x359c('0x6')][_0x5b0707[_0x359c('0x4d')]]){logger[_0x359c('0x1a')](_0x359c('0x4e'),JSON['stringify'](_0x5b0707[_0x359c('0x4d')]));this[_0x359c('0x3e')](_0x5b0707['transfererlinkedid']);}}catch(_0x209e1f){logger[_0x359c('0x1d')](_0x359c('0x4f'),_0x209e1f['message']);}};Acw[_0x359c('0x16')]['syncAgentRingNoAnswer']=function(_0x8d6c42){try{if(this['voiceQueues'][_0x8d6c42['queue']]&&this[_0x359c('0x3')][_0x8d6c42[_0x359c('0x32')]]['autopause']===_0x359c('0x50')){if(this[_0x359c('0x4')][_0x8d6c42[_0x359c('0x1f')]]){logger[_0x359c('0x1a')](_0x359c('0x51'),_0x8d6c42[_0x359c('0x36')],_0x8d6c42[_0x359c('0x1f')],_0x8d6c42['queue']);return RpcUser[_0x359c('0x29')](this['agents'][_0x8d6c42[_0x359c('0x1f')]],_0x359c('0x52'),_0x8d6c42[_0x359c('0x36')]);}}}catch(_0x4fffd7){logger['error'](_0x359c('0x53'),_0x4fffd7[_0x359c('0x3b')]);}};module['exports']=Acw;