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