2e2b97e32393bf72ed347e748508b824c66250f9
[motion2.git] / server / services / ami / report / voiceCallReport.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 _0x04de=['sipcallid','[%s][voiceCallReport][varset]\x20variable:sipcallid\x20value:%s','sipcalluniqueid','parse','sipcalllinkedid','[%s][voiceCallReport][varset]','[%s][voiceCallReport][hangup]\x20event:','[%s][voiceCallReport][hangup]\x20reason:%s','cause-txt','endtime','billableseconds','answertime','from-sip','[%s][voiceCallReport][hangup]\x20sending\x20user:agentcomplete\x20event:','accountcode','user:agentcomplete','resolve','then','transferType','isEmpty','getSettings','stopRecordingOnTransfer','Action','StopMixMonitor','catch','finally','webbar:stopmonitors','event','outbound','[%s][voiceCallReport][hangup]\x20sending\x20hangup\x20event:','custom:voiceCallReport','[%s][voiceCallReport][attendedtransfer]\x20transfercalleridnum:%s\x20transferconnectedlinenum:%s','transfertargetcalleridnum','[%s][voiceCallReport][attendedtransfer]\x20event:','transfereeuniqueid','transfercalleridnum','origtransferercalleridnum','transferconnectedlinenum','secondtransfereruniqueid','transfertargetuniqueid','origtransfereruniqueid','origtransfererlinkedid','some','routeid','ATTENDED','[%s][voiceCallReport][attendedtransfer]','syncBlindTransfer','[%s][voiceCallReport][blindtransfer]\x20transfercalleridnum:%s\x20transferconnectedlinenum:%s','transfereecalleridnum','extension','BLIND','transfererchannel','transfereruniqueid','[%s][voiceCallReport][blindtransfer]','[%s][voiceCallReport][musiconholdstart]\x20event:','[%s][voiceCallReport][musiconholdstart]\x20mohstarttime:%s','[%s][voiceCallReport][musiconholdstart]','[%s][voiceCallReport][musiconholdstop]\x20event:','mohstarttime','mohtime','milliseconds','[%s][voiceCallReport][musiconholdstop]\x20mohtime:%s','[%s][voiceCallReport][musiconholdstop]','exports','bluebird','lodash','moment','util','path','ioredis','../../../config/environment','../../../config/logger','ami','../ami','../model/channel','busy','invalid','unavailable','ringing','ringinuse','onhold','set','queue','dial','playback','voicemail','NO\x20ANSWER','FAILED','BUSY','redis','defaults','localhost','socket.io-emitter','channels','agents','blindTransfers','syncNewExten','bind','newexten','newchannel','syncNewChannel','newstate','varset','syncVarSet','hangup','syncHangup','newcallerid','syncNewCallerId','musiconholdstart','syncMusicOnHoldStop','info','[voiceCallReport][coreshowchannels]\x20started','actionCoreShowChannels','error','inspect','prototype','isNotNull','emit','uniqueid','calleridname','calleridnum','[%s][voiceCallReport][newcallerid]\x20event:','isUndefined','merge','pick','keys','debug','[%s][voiceCallReport][newchannel]\x20event:','channel','[%s][voiceCallReport][newchannel]\x20context:%s\x20exten:%s','context','exten','format','disposition','toNumber','channelstate','split','destconnectedlinenum','[%s][voiceCallReport][newchannel]\x20sending\x20user:agentconnect\x20event:','user:%s','name','user:agentconnect','[%s][voiceCallReport][newexten]\x20event:','linkedid','OutgoingSpoolFailed','application','toLowerCase','applicationdata','appdata','[%s][voiceCallReport][newexten]\x20application:%s\x20appdata:%s','starttime','duration','YYYY-MM-DD\x20HH:mm:ss','includes','lastapplication','cdr(','match','syncNewState','[%s][voiceCallReport][newstate]\x20linkedid:%s\x20calleridname:%s\x20calleridnum:%s','answered','holdtime','diff','seconds','xcally-motion-preview','connectedlinenum','connectedlinename','destinationchannel','membername','UserId','[%s][voiceCallReport][newstate]','endsWith','replace','.WAV','isNil','monitors','push','rec','[%s][voiceCallReport][varset]\x20event:','variable','mixmonitor_filename','[%s][voiceCallReport][varset]\x20variable:mixmonitor_filename\x20value:%s','value','syncMixMonitorFilename','xmd-phone','[%s][voiceCallReport][varset]\x20variable:xmd-phone\x20value:%s','xmd-cdrtype','type','xmd-queue','[%s][voiceCallReport][varset]\x20variable:xmd-queue\x20value:%s','[%s][voiceCallReport][varset]\x20variable:xmd-originatecalleridnum\x20value:%s','originatecalleridnum','xmd-destination','[%s][voiceCallReport][varset]\x20variable:xmd-destination\x20value:%s','destination','xmd-callerid-preview','[%s][voiceCallReport][varset]\x20variable:xmd-callerid-preview\x20value:%s','calleridpreview','xmcs-queue','[%s][voiceCallReport][varset]\x20variable:xmcs-queue\x20value:%s'];(function(_0x5cf3f6,_0x3da78d){var _0x3809b7=function(_0x20cd7f){while(--_0x20cd7f){_0x5cf3f6['push'](_0x5cf3f6['shift']());}};_0x3809b7(++_0x3da78d);}(_0x04de,0x107));var _0xe04d=function(_0x257604,_0x2c632b){_0x257604=_0x257604-0x0;var _0xf377b9=_0x04de[_0x257604];return _0xf377b9;};'use strict';var BPromise=require(_0xe04d('0x0'));var _=require(_0xe04d('0x1'));var moment=require(_0xe04d('0x2'));var util=require(_0xe04d('0x3'));var path=require(_0xe04d('0x4'));var Redis=require(_0xe04d('0x5'));var config=require(_0xe04d('0x6'));var logger=require(_0xe04d('0x7'))(_0xe04d('0x8'));var ami=require(_0xe04d('0x9'));var Channel=require(_0xe04d('0xa'));var RpcSetting=require('../rpc/setting');var statusDesc=['unknown','not_inuse','inuse',_0xe04d('0xb'),_0xe04d('0xc'),_0xe04d('0xd'),_0xe04d('0xe'),_0xe04d('0xf'),_0xe04d('0x10')];var applications=[_0xe04d('0x11'),_0xe04d('0x12'),'agi',_0xe04d('0x13'),_0xe04d('0x14'),_0xe04d('0x15')];var dispositions=[_0xe04d('0x16'),_0xe04d('0x17'),_0xe04d('0x17'),_0xe04d('0x16'),_0xe04d('0x16'),_0xe04d('0x16'),'ANSWERED',_0xe04d('0x18'),_0xe04d('0x17'),_0xe04d('0x17'),_0xe04d('0x17')];var actions={};config[_0xe04d('0x19')]=_[_0xe04d('0x1a')](config[_0xe04d('0x19')],{'host':_0xe04d('0x1b'),'port':0x18eb});var io=require(_0xe04d('0x1c'))(new Redis(config[_0xe04d('0x19')]));function VoiceCallReport(_0xbc5cc7){this[_0xe04d('0x1d')]=_0xbc5cc7['channels'];this[_0xe04d('0x1e')]=_0xbc5cc7['agents'];this[_0xe04d('0x1f')]={};ami['on']('coreshowchannel',this[_0xe04d('0x20')][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x22'),this[_0xe04d('0x20')][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x23'),this[_0xe04d('0x24')][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x25'),this['syncNewState'][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x26'),this[_0xe04d('0x27')][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x28'),this[_0xe04d('0x29')]['bind'](this));ami['on'](_0xe04d('0x2a'),this[_0xe04d('0x2b')]['bind'](this));ami['on']('attendedtransfer',this['syncAttendedTransfer'][_0xe04d('0x21')](this));ami['on']('blindtransfer',this['syncBlindTransfer'][_0xe04d('0x21')](this));ami['on'](_0xe04d('0x2c'),this['syncMusicOnHoldStart'][_0xe04d('0x21')](this));ami['on']('musiconholdstop',this[_0xe04d('0x2d')]['bind'](this));try{logger[_0xe04d('0x2e')](_0xe04d('0x2f'));ami[_0xe04d('0x30')]();}catch(_0x29ad33){logger[_0xe04d('0x31')]('[voiceCallReport][coreshowchannels]',util[_0xe04d('0x32')](_0x29ad33,{'showHidden':![],'depth':null}));}}VoiceCallReport[_0xe04d('0x33')][_0xe04d('0x34')]=function(_0x870de3){return _0x870de3!==null&&!_['isUndefined'](_0x870de3);};VoiceCallReport[_0xe04d('0x33')][_0xe04d('0x35')]=function(_0x19ad13,_0x4824e8,_0x187c29){io['to'](_0x19ad13)['emit'](_0x4824e8,_0x187c29);};VoiceCallReport['prototype']['syncNewCallerId']=function(_0x25299b){try{if(this[_0xe04d('0x34')](_0x25299b)){logger['info']('[%s][voiceCallReport][newcallerid]\x20calleridname:%s\x20calleridnum:%s',_0x25299b[_0xe04d('0x36')],_0x25299b[_0xe04d('0x37')],_0x25299b[_0xe04d('0x38')]);logger['debug'](_0xe04d('0x39'),_0x25299b[_0xe04d('0x36')],util['inspect'](_0x25299b,{'showHidden':![],'depth':null}));if(_0x25299b[_0xe04d('0x36')]===_0x25299b['linkedid']){if(!_[_0xe04d('0x3a')](this[_0xe04d('0x1d')][_0x25299b['uniqueid']])){_[_0xe04d('0x3b')](this['channels'][_0x25299b[_0xe04d('0x36')]],_[_0xe04d('0x3c')](_0x25299b,_[_0xe04d('0x3d')](this[_0xe04d('0x1d')][_0x25299b[_0xe04d('0x36')]])));}}}}catch(_0x2bbaec){logger[_0xe04d('0x31')]('[%s][voiceCallReport][newcallerid]',_0x25299b[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x2bbaec,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')][_0xe04d('0x24')]=function(_0x13085f){try{if(this[_0xe04d('0x34')](_0x13085f)){logger[_0xe04d('0x3e')](_0xe04d('0x3f'),_0x13085f[_0xe04d('0x36')],util['inspect'](_0x13085f,{'showHidden':![],'depth':null}));if(_0x13085f[_0xe04d('0x36')]===_0x13085f['linkedid']&&_0x13085f[_0xe04d('0x40')]!='OutgoingSpoolFailed'){if(_['isUndefined'](this[_0xe04d('0x1d')][_0x13085f[_0xe04d('0x36')]])){logger[_0xe04d('0x2e')](_0xe04d('0x41'),_0x13085f['uniqueid'],_0x13085f[_0xe04d('0x42')],_0x13085f[_0xe04d('0x43')]);this[_0xe04d('0x1d')][_0x13085f[_0xe04d('0x36')]]=new Channel();this[_0xe04d('0x1d')][_0x13085f['uniqueid']]['starttime']=moment()[_0xe04d('0x44')]('YYYY-MM-DD\x20HH:mm:ss');this['channels'][_0x13085f[_0xe04d('0x36')]][_0xe04d('0x45')]=dispositions[_[_0xe04d('0x46')](_0x13085f[_0xe04d('0x47')])];_['merge'](this['channels'][_0x13085f[_0xe04d('0x36')]],_[_0xe04d('0x3c')](_0x13085f,_[_0xe04d('0x3d')](this[_0xe04d('0x1d')][_0x13085f[_0xe04d('0x36')]])));if(_0x13085f[_0xe04d('0x42')]==='from-sip'){if(this[_0xe04d('0x1e')][_0x13085f['channel'][_0xe04d('0x48')]('-')[0x0]]){this[_0xe04d('0x1e')][_0x13085f[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]][_0xe04d('0x49')]=_0x13085f[_0xe04d('0x43')];logger[_0xe04d('0x3e')](_0xe04d('0x4a'),_0x13085f['uniqueid'],util[_0xe04d('0x32')]({'destaccountcode':this[_0xe04d('0x1e')][_0x13085f['channel'][_0xe04d('0x48')]('-')[0x0]]['accountcode'],'destconnectedlinenum':_0x13085f[_0xe04d('0x43')]},{'showHidden':![],'depth':null}));this[_0xe04d('0x35')](util['format'](_0xe04d('0x4b'),this[_0xe04d('0x1e')][_0x13085f[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]][_0xe04d('0x4c')]),_0xe04d('0x4d'),{'destaccountcode':this[_0xe04d('0x1e')][_0x13085f[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]]['accountcode'],'destconnectedlinenum':_0x13085f['exten']});}}}}}}catch(_0x50e4a5){logger[_0xe04d('0x31')]('[%s][voiceCallReport][newchannel]',_0x13085f[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x50e4a5,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')][_0xe04d('0x20')]=function(_0x49c5c5){try{if(this[_0xe04d('0x34')](_0x49c5c5)){logger['debug'](_0xe04d('0x4e'),_0x49c5c5[_0xe04d('0x36')],util['inspect'](_0x49c5c5,{'showHidden':![],'depth':null}));if(_0x49c5c5['uniqueid']===_0x49c5c5[_0xe04d('0x4f')]&&_0x49c5c5[_0xe04d('0x43')]!='h'&&_0x49c5c5['channel']!=_0xe04d('0x50')){_0x49c5c5['application']=_0x49c5c5[_0xe04d('0x51')][_0xe04d('0x52')]();_0x49c5c5[_0xe04d('0x53')]=(_0x49c5c5[_0xe04d('0x54')]||_0x49c5c5[_0xe04d('0x53')])[_0xe04d('0x52')]();logger[_0xe04d('0x2e')](_0xe04d('0x55'),_0x49c5c5[_0xe04d('0x36')],_0x49c5c5[_0xe04d('0x51')],_0x49c5c5['applicationdata']);if(_['isUndefined'](this[_0xe04d('0x1d')][_0x49c5c5['uniqueid']])){this['channels'][_0x49c5c5['uniqueid']]=new Channel();this[_0xe04d('0x1d')][_0x49c5c5[_0xe04d('0x36')]][_0xe04d('0x56')]=_0x49c5c5['duration']?moment()['subtract'](moment[_0xe04d('0x57')](_0x49c5c5[_0xe04d('0x57')])['seconds'](),'seconds')[_0xe04d('0x44')]('YYYY-MM-DD\x20HH:mm:ss'):moment()[_0xe04d('0x44')](_0xe04d('0x58'));this[_0xe04d('0x1d')][_0x49c5c5[_0xe04d('0x36')]][_0xe04d('0x45')]=_0xe04d('0x16');}_[_0xe04d('0x3b')](this[_0xe04d('0x1d')][_0x49c5c5['uniqueid']],_['pick'](_0x49c5c5,_[_0xe04d('0x3d')](this[_0xe04d('0x1d')][_0x49c5c5[_0xe04d('0x36')]])));if(_[_0xe04d('0x59')](applications,_0x49c5c5[_0xe04d('0x51')])){this['channels'][_0x49c5c5['uniqueid']][_0xe04d('0x5a')]=_0x49c5c5['application'];this['channels'][_0x49c5c5[_0xe04d('0x36')]]['lastdata']=_0x49c5c5[_0xe04d('0x53')];if(_0x49c5c5['application']===_0xe04d('0x11')&&_['startsWith'](_0x49c5c5['applicationdata'],_0xe04d('0x5b'))){var _0x4205f9=_0x49c5c5[_0xe04d('0x53')][_0xe04d('0x48')]('=');var _0x3b0a35=_0x4205f9[0x0][_0xe04d('0x5c')](/cdr\((.*)\)/);if(_0x3b0a35){this[_0xe04d('0x1d')][_0x49c5c5[_0xe04d('0x36')]][_0x3b0a35[0x1]]=_0x4205f9[0x1];}}else if(_0x49c5c5[_0xe04d('0x51')]===_0xe04d('0x12')){this[_0xe04d('0x1d')][_0x49c5c5['uniqueid']][_0xe04d('0x12')]=_0x49c5c5[_0xe04d('0x53')][_0xe04d('0x48')](',')[0x0];}}}}}catch(_0x522242){logger[_0xe04d('0x31')]('[%s][voiceCallReport][newexten]',_0x49c5c5[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x522242,{'showHidden':![],'depth':null}));}};VoiceCallReport['prototype'][_0xe04d('0x5d')]=function(_0x42f7a1){try{if(this[_0xe04d('0x34')](_0x42f7a1)){logger['info'](_0xe04d('0x5e'),_0x42f7a1['uniqueid'],_0x42f7a1[_0xe04d('0x4f')],_0x42f7a1[_0xe04d('0x37')],_0x42f7a1[_0xe04d('0x38')]);logger[_0xe04d('0x3e')]('[%s][voiceCallReport][newstate]\x20event:',_0x42f7a1[_0xe04d('0x36')],util['inspect'](_0x42f7a1,{'showHidden':![],'depth':null}));if(_0x42f7a1[_0xe04d('0x36')]!==_0x42f7a1['linkedid']){if(this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]]){if(_0x42f7a1[_0xe04d('0x47')]==='6'){if(!this[_0xe04d('0x1d')][_0x42f7a1['linkedid']][_0xe04d('0x5f')]){var _0x486eb4=moment();this['channels'][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x5f')]=!![];this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]]['answertime']=_0x486eb4['format']('YYYY-MM-DD\x20HH:mm:ss');if(this['channels'][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x56')]){this['channels'][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x60')]=_0x486eb4[_0xe04d('0x61')](this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]]['starttime'],_0xe04d('0x62'));}}this['channels'][_0x42f7a1[_0xe04d('0x4f')]]['linkedid']=_0x42f7a1[_0xe04d('0x36')];if(_0x42f7a1[_0xe04d('0x38')]!==_0xe04d('0x63')){this['channels'][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x64')]=_0x42f7a1[_0xe04d('0x38')];}this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x65')]=_0x42f7a1[_0xe04d('0x37')];this['channels'][_0x42f7a1['linkedid']][_0xe04d('0x66')]=_0x42f7a1[_0xe04d('0x40')];this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]]['disposition']=dispositions[_[_0xe04d('0x46')](_0x42f7a1[_0xe04d('0x47')])];if(this[_0xe04d('0x1e')][_0x42f7a1[_0xe04d('0x40')]['split']('-')[0x0]]){this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x4f')]]['UserId']=this[_0xe04d('0x1e')][_0x42f7a1[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]]['id'];this['channels'][_0x42f7a1[_0xe04d('0x4f')]][_0xe04d('0x67')]=this[_0xe04d('0x1e')][_0x42f7a1[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]][_0xe04d('0x4c')];}}}}else{if(this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x36')]]){if(_0x42f7a1[_0xe04d('0x47')]==='6'){if(this['agents'][_0x42f7a1[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]]){this[_0xe04d('0x1d')][_0x42f7a1[_0xe04d('0x36')]][_0xe04d('0x68')]=this[_0xe04d('0x1e')][_0x42f7a1[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]]['id'];this[_0xe04d('0x1d')][_0x42f7a1['uniqueid']][_0xe04d('0x67')]=this[_0xe04d('0x1e')][_0x42f7a1['channel'][_0xe04d('0x48')]('-')[0x0]]['name'];}}}}}}catch(_0x4ca60a){logger[_0xe04d('0x31')](_0xe04d('0x69'),_0x42f7a1[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x4ca60a,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')]['syncMixMonitorFilename']=function(_0xb4b3c8,_0x38e22e){try{if(this['channels'][_0xb4b3c8]){logger[_0xe04d('0x2e')]('[%s][voiceCallReport][mixMonitorFilename]\x20monitorFilename:%s',_0xb4b3c8,_0x38e22e);this['channels'][_0xb4b3c8]['monitor']=!![];if(_[_0xe04d('0x6a')](_0x38e22e,'.wav49')){_0x38e22e=_0x38e22e[_0xe04d('0x6b')]('.wav49',_0xe04d('0x6c'));}this[_0xe04d('0x1d')][_0xb4b3c8]['monitorFilename']=_0x38e22e;var _0x31b465=_['find'](this[_0xe04d('0x1d')][_0xb4b3c8]['monitors'],{'filename':_0x38e22e});if(_[_0xe04d('0x6d')](_0x31b465)){this[_0xe04d('0x1d')][_0xb4b3c8][_0xe04d('0x6e')][_0xe04d('0x6f')]({'filename':_0x38e22e,'createdAt':moment()[_0xe04d('0x44')](_0xe04d('0x58')),'mixmonitorid':'','status':_0xe04d('0x70')});}}}catch(_0x4be3bd){logger[_0xe04d('0x31')]('[%s][voiceCallReport][mixMonitorFilename]',_0xb4b3c8,util[_0xe04d('0x32')](_0x4be3bd,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')]['syncVarSet']=function(_0x27ba30){try{if(this[_0xe04d('0x34')](_0x27ba30)){logger[_0xe04d('0x3e')](_0xe04d('0x71'),_0x27ba30['uniqueid'],util[_0xe04d('0x32')](_0x27ba30,{'showHidden':![],'depth':null}));if(this['channels'][_0x27ba30['uniqueid']]&&_0x27ba30[_0xe04d('0x40')]!=_0xe04d('0x50')){if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')])){if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x73')])){logger['info'](_0xe04d('0x74'),_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]);this[_0xe04d('0x76')](_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]);}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x77')])){logger[_0xe04d('0x2e')](_0xe04d('0x78'),_0x27ba30['uniqueid'],_0x27ba30[_0xe04d('0x75')]);this['channels'][_0x27ba30[_0xe04d('0x36')]][_0xe04d('0x38')]=_0x27ba30[_0xe04d('0x75')];}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')]['xmd-callerid'])){logger['info']('[%s][voiceCallReport][varset]\x20variable:xmd-callerid\x20value:%s',_0x27ba30['uniqueid'],_0x27ba30[_0xe04d('0x75')]);this['channels'][_0x27ba30[_0xe04d('0x36')]]['callerid']=_0x27ba30[_0xe04d('0x75')];}else if(this[_0xe04d('0x34')](_0x27ba30['variable'][_0xe04d('0x79')])){logger[_0xe04d('0x2e')]('[%s][voiceCallReport][varset]\x20variable:xmd-cdrtype\x20value:%s',_0x27ba30['uniqueid'],_0x27ba30['value']);this['channels'][_0x27ba30[_0xe04d('0x36')]][_0xe04d('0x7a')]=_0x27ba30['value'];}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x7b')])){logger[_0xe04d('0x2e')](_0xe04d('0x7c'),_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]['split'](',')[0x0]);this[_0xe04d('0x1d')][_0x27ba30['uniqueid']]['queue']=_0x27ba30[_0xe04d('0x75')][_0xe04d('0x48')](',')[0x0];}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')]['xmd-originatecalleridnum'])){logger[_0xe04d('0x2e')](_0xe04d('0x7d'),_0x27ba30[_0xe04d('0x36')],_0x27ba30['value']);this['channels'][_0x27ba30[_0xe04d('0x36')]][_0xe04d('0x7e')]=_0x27ba30[_0xe04d('0x75')];}else if(this['isNotNull'](_0x27ba30['variable'][_0xe04d('0x7f')])){logger[_0xe04d('0x2e')](_0xe04d('0x80'),_0x27ba30['uniqueid'],_0x27ba30['value']);this['channels'][_0x27ba30['uniqueid']][_0xe04d('0x81')]=_0x27ba30[_0xe04d('0x75')];}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x82')])){logger[_0xe04d('0x2e')](_0xe04d('0x83'),_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]);this['channels'][_0x27ba30[_0xe04d('0x36')]][_0xe04d('0x84')]=_0x27ba30[_0xe04d('0x75')];}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x85')])){logger[_0xe04d('0x2e')](_0xe04d('0x86'),_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]);this[_0xe04d('0x1d')][_0x27ba30[_0xe04d('0x36')]]['queue']=_0x27ba30[_0xe04d('0x75')];}else if(this['isNotNull'](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x87')])){logger[_0xe04d('0x2e')](_0xe04d('0x88'),_0x27ba30[_0xe04d('0x36')],_0x27ba30[_0xe04d('0x75')]);this[_0xe04d('0x1d')][_0x27ba30[_0xe04d('0x36')]][_0xe04d('0x89')]=_0x27ba30[_0xe04d('0x75')];}}}else if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x73')])){if(_0x27ba30[_0xe04d('0x75')]){var _0x54b90b=path[_0xe04d('0x8a')](_0x27ba30['value'])['name'];logger['info'](_0xe04d('0x74'),_0x54b90b,_0x27ba30[_0xe04d('0x75')]);this[_0xe04d('0x76')](_0x54b90b,_0x27ba30[_0xe04d('0x75')]);}}else if(this[_0xe04d('0x1d')][_0x27ba30[_0xe04d('0x4f')]]){if(this[_0xe04d('0x34')](_0x27ba30[_0xe04d('0x72')])){if(this['isNotNull'](_0x27ba30[_0xe04d('0x72')][_0xe04d('0x87')])){logger[_0xe04d('0x2e')](_0xe04d('0x88'),_0x27ba30[_0xe04d('0x4f')],_0x27ba30[_0xe04d('0x75')]);this[_0xe04d('0x1d')][_0x27ba30[_0xe04d('0x4f')]][_0xe04d('0x8b')]=_0x27ba30[_0xe04d('0x75')];}}}}}catch(_0x30d74e){logger[_0xe04d('0x31')](_0xe04d('0x8c'),_0x27ba30[_0xe04d('0x36')],util['inspect'](_0x30d74e,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')][_0xe04d('0x29')]=function(_0x40ba96){try{if(this[_0xe04d('0x34')](_0x40ba96)){logger[_0xe04d('0x3e')](_0xe04d('0x8d'),_0x40ba96[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x40ba96,{'showHidden':![],'depth':null}));if(this['channels'][_0x40ba96[_0xe04d('0x36')]]){logger[_0xe04d('0x2e')](_0xe04d('0x8e'),_0x40ba96['uniqueid'],_0x40ba96[_0xe04d('0x8f')]);var _0x3ac707=moment();this[_0xe04d('0x1d')][_0x40ba96['uniqueid']][_0xe04d('0x90')]=_0x3ac707[_0xe04d('0x44')]('YYYY-MM-DD\x20HH:mm:ss');this['channels'][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x57')]=_0x3ac707['diff'](this[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x56')],_0xe04d('0x62'));if(this[_0xe04d('0x1d')][_0x40ba96['uniqueid']][_0xe04d('0x5f')]){this[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x91')]=_0x3ac707[_0xe04d('0x61')](this[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x92')],_0xe04d('0x62'));this[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x60')]=this['channels'][_0x40ba96['uniqueid']][_0xe04d('0x57')]-this[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]]['billableseconds'];}if(_0x40ba96[_0xe04d('0x42')]===_0xe04d('0x93')){if(this['agents'][_0x40ba96[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]]){this['agents'][_0x40ba96[_0xe04d('0x40')]['split']('-')[0x0]]=_['omit'](this[_0xe04d('0x1e')][_0x40ba96[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]],[_0xe04d('0x49')]);logger[_0xe04d('0x3e')](_0xe04d('0x94'),_0x40ba96['uniqueid'],util['inspect']({'destaccountcode':this[_0xe04d('0x1e')][_0x40ba96['channel'][_0xe04d('0x48')]('-')[0x0]][_0xe04d('0x95')]},{'showHidden':![],'depth':null}));this[_0xe04d('0x35')](util[_0xe04d('0x44')](_0xe04d('0x4b'),this[_0xe04d('0x1e')][_0x40ba96['channel']['split']('-')[0x0]][_0xe04d('0x4c')]),_0xe04d('0x96'),{'destaccountcode':this[_0xe04d('0x1e')][_0x40ba96[_0xe04d('0x40')][_0xe04d('0x48')]('-')[0x0]][_0xe04d('0x95')]});}}var _0x3f4018=this;Promise[_0xe04d('0x97')]()[_0xe04d('0x98')](function(){var _0x5f36ad=_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]];if(typeof _0x5f36ad[_0xe04d('0x99')]==='undefined')return;if(_[_0xe04d('0x9a')](_0x5f36ad[_0xe04d('0x6e')]))return;return RpcSetting[_0xe04d('0x9b')]()[_0xe04d('0x98')](function(_0x59d4a3){if(!_0x59d4a3[_0xe04d('0x9c')])return;return Promise[_0xe04d('0x97')]()[_0xe04d('0x98')](function(){return ami[_0xe04d('0x9d')]({'action':_0xe04d('0x9e'),'channel':_0x5f36ad[_0xe04d('0x40')]})[_0xe04d('0x9f')](function(){});})[_0xe04d('0x98')](function(){return ami[_0xe04d('0x9d')]({'action':_0xe04d('0x9e'),'channel':_0x5f36ad[_0xe04d('0x66')]})[_0xe04d('0x9f')](function(){})[_0xe04d('0xa0')](function(){var _0x1c10b1=_0x3f4018['agents'][_0x5f36ad[_0xe04d('0x66')][_0xe04d('0x48')]('-')[0x0]];if(!_0x1c10b1)return;io[_0xe04d('0x35')](_0xe04d('0xa1'),{'agentId':_0x1c10b1['id'],'uniqueid':_0x5f36ad['uniqueid']});});});});})[_0xe04d('0x98')](function(){if(_0x40ba96[_0xe04d('0xa2')]==='BlindTransfer'){_0x3f4018['blindTransfers'][_0x40ba96[_0xe04d('0x36')]]=_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]];}else{if(_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x7a')]===_0xe04d('0xa3')&&_0x3f4018[_0xe04d('0x1f')][_0x40ba96['uniqueid']]){_0x3f4018['channels'][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x36')]=[_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]]['linkedid'],_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x4f')]=_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]][_0xe04d('0x36')]][0x0];delete _0x3f4018[_0xe04d('0x1f')][_0x40ba96['uniqueid']];}}logger[_0xe04d('0x3e')](_0xe04d('0xa4'),_0x40ba96[_0xe04d('0x36')],util['inspect'](_0x3f4018['channels'][_0x40ba96['uniqueid']],{'showHidden':![],'depth':null}));ami['emit'](_0xe04d('0xa5'),_0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]]);delete _0x3f4018[_0xe04d('0x1d')][_0x40ba96[_0xe04d('0x36')]];});}}}catch(_0x12be35){logger[_0xe04d('0x31')]('[%s][voiceCallReport][hangup]',_0x40ba96[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x12be35,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')]['syncAttendedTransfer']=function(_0x5d6240){try{if(this['isNotNull'](_0x5d6240)){logger[_0xe04d('0x2e')](_0xe04d('0xa6'),_0x5d6240[_0xe04d('0x36')],_0x5d6240['origtransferercalleridnum'],_0x5d6240[_0xe04d('0xa7')]);logger[_0xe04d('0x3e')](_0xe04d('0xa8'),_0x5d6240[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x5d6240,{'showHidden':![],'depth':null}));if(this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xa9')]]){this[_0xe04d('0x1d')][_0x5d6240['transfereeuniqueid']][_0xe04d('0xaa')]=_0x5d6240[_0xe04d('0xab')];this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xa9')]][_0xe04d('0xac')]=_0x5d6240[_0xe04d('0xa7')];if(this[_0xe04d('0x1d')][_0x5d6240['secondtransfereruniqueid']]){var _0x344546=this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xad')]];this[_0xe04d('0x1d')][_0x5d6240['secondtransfereruniqueid']]=this[_0xe04d('0x1d')][_0x5d6240['transfereeuniqueid']];this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xa9')]]=_0x344546;}}else if(this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xae')]]){this['channels'][_0x5d6240[_0xe04d('0xae')]][_0xe04d('0xaa')]=_0x5d6240[_0xe04d('0xab')];this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xae')]][_0xe04d('0xac')]=_0x5d6240[_0xe04d('0xa7')];if(this[_0xe04d('0x1d')][_0x5d6240['origtransfereruniqueid']]){var _0x344546=this[_0xe04d('0x1d')][_0x5d6240['origtransfereruniqueid']];this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xaf')]]=this['channels'][_0x5d6240['transfertargetuniqueid']];this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xae')]]=_0x344546;}}if((this['channels'][_0x5d6240[_0xe04d('0xaf')]]||this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xb0')]])&&this[_0xe04d('0x1d')][_0x5d6240['secondtransfereruniqueid']]){var _0x4a8022=_[_0xe04d('0xb1')]([this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xaf')]],this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xb0')]],this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xad')]]],function(_0x51c6e0){return _0x51c6e0&&_0x51c6e0['type']===_0xe04d('0xa3')&&_0x51c6e0[_0xe04d('0xb2')];});if(_0x4a8022){if(this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xaf')]])this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xaf')]][_0xe04d('0x99')]=_0xe04d('0xb3');if(this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xb0')]])this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xb0')]]['transferType']=_0xe04d('0xb3');this[_0xe04d('0x1d')][_0x5d6240[_0xe04d('0xad')]][_0xe04d('0x99')]='ATTENDED';}}}}catch(_0x39bb84){logger[_0xe04d('0x31')](_0xe04d('0xb4'),_0x5d6240['uniqueid'],util['inspect'](_0x39bb84,{'showHidden':![],'depth':null}));}};VoiceCallReport['prototype'][_0xe04d('0xb5')]=function(_0xf19fc7){try{if(this[_0xe04d('0x34')](_0xf19fc7)){logger['info'](_0xe04d('0xb6'),_0xf19fc7[_0xe04d('0x36')],_0xf19fc7[_0xe04d('0xb7')],_0xf19fc7['extension']);logger[_0xe04d('0x3e')]('[%s][voiceCallReport][blindtransfer]\x20event:',_0xf19fc7[_0xe04d('0x36')],util[_0xe04d('0x32')](_0xf19fc7,{'showHidden':![],'depth':null}));if(this[_0xe04d('0x1d')][_0xf19fc7[_0xe04d('0xa9')]]){this[_0xe04d('0x1d')][_0xf19fc7[_0xe04d('0xa9')]]['transfercalleridnum']=_0xf19fc7['transfereecalleridnum'];this[_0xe04d('0x1d')][_0xf19fc7[_0xe04d('0xa9')]][_0xe04d('0xac')]=_0xf19fc7[_0xe04d('0xb8')];this[_0xe04d('0x1d')][_0xf19fc7[_0xe04d('0xa9')]][_0xe04d('0x99')]=_0xe04d('0xb9');this[_0xe04d('0x29')]({'event':'BlindTransfer','uniqueid':_0xf19fc7[_0xe04d('0xa9')],'context':_0xf19fc7[_0xe04d('0x42')],'channel':_0xf19fc7[_0xe04d('0xba')]});}else{this[_0xe04d('0x1d')][_0xf19fc7[_0xe04d('0xbb')]][_0xe04d('0x99')]='BLIND';}}}catch(_0x218f1b){logger[_0xe04d('0x31')](_0xe04d('0xbc'),_0xf19fc7['uniqueid'],util[_0xe04d('0x32')](_0x218f1b,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')]['syncMusicOnHoldStart']=function(_0x33007d){try{if(this[_0xe04d('0x34')](_0x33007d)){logger[_0xe04d('0x3e')](_0xe04d('0xbd'),_0x33007d[_0xe04d('0x36')],util['inspect'](_0x33007d,{'showHidden':![],'depth':null}));if(this[_0xe04d('0x1d')][_0x33007d['uniqueid']]){if(!_[_0xe04d('0x6d')](this[_0xe04d('0x1d')][_0x33007d[_0xe04d('0x36')]]['answertime'])){this[_0xe04d('0x1d')][_0x33007d[_0xe04d('0x36')]]['mohstarttime']=moment()['format'](_0xe04d('0x58'));logger['info'](_0xe04d('0xbe'),_0x33007d[_0xe04d('0x36')],this[_0xe04d('0x1d')][_0x33007d['uniqueid']]['mohstarttime']);}}}}catch(_0x1df27e){logger[_0xe04d('0x31')](_0xe04d('0xbf'),_0x33007d[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x1df27e,{'showHidden':![],'depth':null}));}};VoiceCallReport[_0xe04d('0x33')]['syncMusicOnHoldStop']=function(_0x229237){try{if(this[_0xe04d('0x34')](_0x229237)){logger['debug'](_0xe04d('0xc0'),_0x229237[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x229237,{'showHidden':![],'depth':null}));if(this[_0xe04d('0x1d')][_0x229237[_0xe04d('0x36')]]){if(!_[_0xe04d('0x6d')](this[_0xe04d('0x1d')][_0x229237['uniqueid']][_0xe04d('0xc1')])){this[_0xe04d('0x1d')][_0x229237[_0xe04d('0x36')]][_0xe04d('0xc2')]+=moment()[_0xe04d('0xc3')](0x0)[_0xe04d('0x61')](this[_0xe04d('0x1d')][_0x229237[_0xe04d('0x36')]][_0xe04d('0xc1')],_0xe04d('0x62'));logger[_0xe04d('0x2e')](_0xe04d('0xc4'),_0x229237[_0xe04d('0x36')],this[_0xe04d('0x1d')][_0x229237['uniqueid']]['mohtime']);delete this['channels'][_0x229237[_0xe04d('0x36')]][_0xe04d('0xc1')];}}}}catch(_0x5556ce){logger['error'](_0xe04d('0xc5'),_0x229237[_0xe04d('0x36')],util[_0xe04d('0x32')](_0x5556ce,{'showHidden':![],'depth':null}));}};module[_0xe04d('0xc6')]=VoiceCallReport;