fe0dd48f4e1945cdf3740d512c94bf04794b1c54
[motion2.git] / server / services / ami / report / voiceDialReport.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 _0xb138=['emit','syncDialBegin','[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','inspect','merge','called','channel','substring','lastIndexOf','event','privilege','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','membername','interface','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','voice_outbound_channel:save','debug','[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:','custom:dialbegin','error','[%s][voiceDialReport][dialbegin]','[%s][voiceDialReport][dialend]\x20event:','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','format','YYYY-MM-DD\x20HH:mm:ss','connect','info','[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect','[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:','voice:outbound','syncVarSet','[%s][voiceDialReport][varset]\x20event:','keys','variable','value','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','outboundrouteid','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','addVariable','rtpaudioqos','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid','sipuri','bridgepeer','bridgepvtcallid','membercalls','memberdynamic','memberinterface','memberlastcall','memberpenalty','memberrealtime','includes','isUndefined','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','duration','endtime','diff','starttime','lastevent','complete','total','answered','holdtime','seconds','billableseconds','sumHoldTime','sumBillable','sumDuration','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:','custom:dialend','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','stringify','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:','voice_outbound_channel:remove','linkedid','destuniqueid','[%s][voiceDialReport][hangup]','syncNewExten','[%s][voiceDialReport][newexten]\x20event:','application','set','applicationdata','appdata','toLowerCase','startsWith','cdr(','split','match','[%s][voiceDialReport][newexten]','exports','lodash','moment','util','ioredis','../../../config/environment','../../../config/logger','ami','redis','defaults','socket.io-emitter','channels','outboundChannels','outbound','applications','variables','bind','dialend','syncDialEnd','varset','hangup','syncHangup','prototype','isNotNull'];(function(_0x376e34,_0x4ee6c5){var _0x3cf604=function(_0x457fe3){while(--_0x457fe3){_0x376e34['push'](_0x376e34['shift']());}};_0x3cf604(++_0x4ee6c5);}(_0xb138,0x1dd));var _0x8b13=function(_0x271e3f,_0x57e6ed){_0x271e3f=_0x271e3f-0x0;var _0x2157eb=_0xb138[_0x271e3f];return _0x2157eb;};'use strict';var _=require(_0x8b13('0x0'));var moment=require(_0x8b13('0x1'));var util=require(_0x8b13('0x2'));var Redis=require(_0x8b13('0x3'));var config=require(_0x8b13('0x4'));var logger=require(_0x8b13('0x5'))(_0x8b13('0x6'));var ami=require('../ami');config[_0x8b13('0x7')]=_[_0x8b13('0x8')](config[_0x8b13('0x7')],{'host':'localhost','port':0x18eb});var io=require(_0x8b13('0x9'))(new Redis(config[_0x8b13('0x7')]));function VoiceDialReport(_0x5d51b1){this[_0x8b13('0xa')]=_0x5d51b1[_0x8b13('0xb')];this[_0x8b13('0xc')]=_0x5d51b1['outbound'];this[_0x8b13('0xd')]={};this[_0x8b13('0xe')]={};ami['on']('dialbegin',this['syncDialBegin'][_0x8b13('0xf')](this));ami['on'](_0x8b13('0x10'),this[_0x8b13('0x11')][_0x8b13('0xf')](this));ami['on'](_0x8b13('0x12'),this['syncVarSet'][_0x8b13('0xf')](this));ami['on'](_0x8b13('0x13'),this[_0x8b13('0x14')][_0x8b13('0xf')](this));}VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x16')]=function(_0x58f97e){return _0x58f97e!==null&&!_['isUndefined'](_0x58f97e);};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x17')]=function(_0x5f12b5,_0x51a935,_0x479773){io['to'](_0x5f12b5)[_0x8b13('0x17')](_0x51a935,_0x479773);};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x18')]=function(_0x2c615a){try{if(this[_0x8b13('0x16')](_0x2c615a)){logger['debug'](_0x8b13('0x19'),_0x2c615a[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x2c615a,{'showHidden':![],'depth':null}));if(this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]]){_[_0x8b13('0x1c')](this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]],{'starttime':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'lastevent':_0x8b13('0x1d'),'interface':_0x2c615a[_0x8b13('0x1e')][_0x8b13('0x1f')](0x0,_0x2c615a[_0x8b13('0x1e')][_0x8b13('0x20')]('-')),'membername':_0x2c615a[_0x8b13('0x1e')]['substring'](_0x2c615a[_0x8b13('0x1e')][_0x8b13('0x20')]('/')+0x1,_0x2c615a[_0x8b13('0x1e')]['lastIndexOf']('-'))},_['omit'](_0x2c615a,[_0x8b13('0x21'),_0x8b13('0x22')]));logger['info'](_0x8b13('0x23'),_0x2c615a[_0x8b13('0x1a')],this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]][_0x8b13('0x24')],this['channels'][_0x2c615a[_0x8b13('0x1a')]][_0x8b13('0x25')]);logger['debug'](_0x8b13('0x26'),_0x2c615a['uniqueid'],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x2c615a['uniqueid']],{'showHidden':![],'depth':null}));if(this[_0x8b13('0xd')][_0x2c615a[_0x8b13('0x1a')]])_['merge'](this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]],this[_0x8b13('0xd')][_0x2c615a[_0x8b13('0x1a')]]);this[_0x8b13('0x17')]('voice:outbound',_0x8b13('0x27'),this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]]);logger[_0x8b13('0x28')](_0x8b13('0x29'),_0x2c615a[_0x8b13('0x1a')],util['inspect'](this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));ami[_0x8b13('0x17')](_0x8b13('0x2a'),this[_0x8b13('0xa')][_0x2c615a[_0x8b13('0x1a')]]);}}}catch(_0x3304bd){logger[_0x8b13('0x2b')](_0x8b13('0x2c'),_0x2c615a['uniqueid'],util[_0x8b13('0x1b')](_0x3304bd,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x11')]=function(_0x2878a6){try{if(this['isNotNull'](_0x2878a6)){logger['debug'](_0x8b13('0x2d'),_0x2878a6['uniqueid'],util['inspect'](_0x2878a6,{'showHidden':![],'depth':null}));if(this[_0x8b13('0xa')][_0x2878a6['uniqueid']]){this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]][_0x8b13('0x2e')]=_0x2878a6[_0x8b13('0x2e')];if(_0x2878a6[_0x8b13('0x2e')]===_0x8b13('0x2f')){this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]][_0x8b13('0x30')]=_0x2878a6[_0x8b13('0x30')];this['channels'][_0x2878a6[_0x8b13('0x1a')]][_0x8b13('0x31')]=_0x2878a6[_0x8b13('0x31')];this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]][_0x8b13('0x32')]=moment()[_0x8b13('0x33')](_0x8b13('0x34'));this['channels'][_0x2878a6[_0x8b13('0x1a')]]['lastevent']=_0x8b13('0x35');logger[_0x8b13('0x36')](_0x8b13('0x37'),_0x2878a6[_0x8b13('0x1a')],_0x2878a6[_0x8b13('0x1e')][_0x8b13('0x1f')](_0x2878a6['channel']['lastIndexOf']('/')+0x1,_0x2878a6[_0x8b13('0x1e')]['lastIndexOf']('-')));logger[_0x8b13('0x28')]('[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:',_0x2878a6[_0x8b13('0x1a')],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));ami[_0x8b13('0x17')]('custom:dialconnect',this['channels'][_0x2878a6[_0x8b13('0x1a')]]);}logger['debug'](_0x8b13('0x38'),_0x2878a6[_0x8b13('0x1a')],util['inspect'](this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));this[_0x8b13('0x17')](_0x8b13('0x39'),_0x8b13('0x27'),this[_0x8b13('0xa')][_0x2878a6[_0x8b13('0x1a')]]);}}}catch(_0x516c70){logger['error']('[%s][voiceDialReport][dialend]',_0x2878a6[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x516c70,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x3a')]=function(_0x2e6e78){try{if(this[_0x8b13('0x16')](_0x2e6e78)){logger['debug'](_0x8b13('0x3b'),_0x2e6e78['uniqueid'],util[_0x8b13('0x1b')](_0x2e6e78,{'showHidden':![],'depth':null}));this['addVariable'](_0x2e6e78[_0x8b13('0x1a')],_[_0x8b13('0x3c')](_0x2e6e78[_0x8b13('0x3d')])[0x0],_0x2e6e78[_0x8b13('0x3e')]);if(this[_0x8b13('0x16')](_0x2e6e78[_0x8b13('0x3d')])&&this[_0x8b13('0x16')](_0x2e6e78['variable']['outboundrouteid'])){if(_['isUndefined'](this[_0x8b13('0xa')][_0x2e6e78[_0x8b13('0x1a')]])){this[_0x8b13('0xa')][_0x2e6e78[_0x8b13('0x1a')]]={'routeId':_0x2e6e78['value'],'variables':this['variables'][_0x2e6e78[_0x8b13('0x1a')]],'motionChannel':'voice'};logger[_0x8b13('0x36')](_0x8b13('0x3f'),_0x2e6e78[_0x8b13('0x1a')],_0x2e6e78[_0x8b13('0x3d')][_0x8b13('0x40')],_['keys'](_0x2e6e78[_0x8b13('0x3d')])[0x0],_0x2e6e78[_0x8b13('0x3e')]);logger[_0x8b13('0x28')](_0x8b13('0x41'),_0x2e6e78[_0x8b13('0x1a')],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x2e6e78[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));this[_0x8b13('0x17')]('voice:outbound',_0x8b13('0x27'),this['channels'][_0x2e6e78[_0x8b13('0x1a')]]);}}}}catch(_0x209dc4){logger[_0x8b13('0x2b')]('[%s][voiceDialReport][varset]',_0x2e6e78[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x209dc4,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x42')]=function(_0x2d1e98,_0x39f5aa,_0x453cd4){var _0x534636=[_0x8b13('0x43'),'rtpaudioqosbridged',_0x8b13('0x44'),_0x8b13('0x45'),_0x8b13('0x46'),_0x8b13('0x47'),_0x8b13('0x48'),_0x8b13('0x49'),_0x8b13('0x4a'),_0x8b13('0x4b'),_0x8b13('0x4c'),_0x8b13('0x4d'),_0x8b13('0x4e'),_0x8b13('0x4f'),_0x8b13('0x50'),_0x8b13('0x51'),_0x8b13('0x24'),_0x8b13('0x52'),_0x8b13('0x53')];if(!_['isNil'](_0x39f5aa)&&!_[_0x8b13('0x54')](_0x534636,_0x39f5aa)){if(_[_0x8b13('0x55')](this['variables'][_0x2d1e98])){this[_0x8b13('0xe')][_0x2d1e98]={};}this[_0x8b13('0xe')][_0x2d1e98][_0x39f5aa]=_0x453cd4;}};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x14')]=function(_0x25cb45){try{if(this[_0x8b13('0x16')](_0x25cb45)){logger[_0x8b13('0x28')](_0x8b13('0x56'),_0x25cb45[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x25cb45,{'showHidden':![],'depth':null}));if(this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]]){logger[_0x8b13('0x36')](_0x8b13('0x57'),_0x25cb45[_0x8b13('0x1a')],_0x25cb45['cause-txt']);this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]]['endtime']=moment()[_0x8b13('0x33')](_0x8b13('0x34'));this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x58')]=moment(this['channels'][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x59')])[_0x8b13('0x5a')](this['channels'][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x5b')],'seconds');this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x5c')]=_0x8b13('0x5d');this['outbound'][_0x8b13('0x5e')]+=0x1;if(this[_0x8b13('0xa')][_0x25cb45['uniqueid']][_0x8b13('0x32')]){this[_0x8b13('0xc')][_0x8b13('0x5f')]+=0x1;this[_0x8b13('0xa')][_0x25cb45['uniqueid']][_0x8b13('0x60')]=moment(this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x32')])[_0x8b13('0x5a')](this[_0x8b13('0xa')][_0x25cb45['uniqueid']][_0x8b13('0x5b')],_0x8b13('0x61'));this[_0x8b13('0xa')][_0x25cb45['uniqueid']][_0x8b13('0x62')]=moment(this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x59')])['diff'](this['channels'][_0x25cb45['uniqueid']]['answertime'],'seconds');this[_0x8b13('0xc')][_0x8b13('0x63')]+=this['channels'][_0x25cb45[_0x8b13('0x1a')]]['holdtime']||0x0;this[_0x8b13('0xc')][_0x8b13('0x64')]+=this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]][_0x8b13('0x62')];}this[_0x8b13('0xc')][_0x8b13('0x65')]+=this['channels'][_0x25cb45[_0x8b13('0x1a')]]['duration'];logger[_0x8b13('0x28')](_0x8b13('0x66'),_0x25cb45[_0x8b13('0x1a')],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));ami[_0x8b13('0x17')]('custom:voiceDialReport',this[_0x8b13('0xa')][_0x25cb45['uniqueid']]);logger[_0x8b13('0x28')](_0x8b13('0x67'),_0x25cb45[_0x8b13('0x1a')],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x25cb45['uniqueid']],{'showHidden':![],'depth':null}));ami['emit'](_0x8b13('0x68'),this[_0x8b13('0xa')][_0x25cb45['uniqueid']]);logger[_0x8b13('0x28')](_0x8b13('0x69'),_0x25cb45[_0x8b13('0x1a')],util['inspect'](this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));this[_0x8b13('0x17')](_0x8b13('0x39'),'voice_outbound:save',this[_0x8b13('0xc')]);logger[_0x8b13('0x36')]('[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event',JSON[_0x8b13('0x6a')](this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]]));logger[_0x8b13('0x28')](_0x8b13('0x6b'),_0x25cb45[_0x8b13('0x1a')],util[_0x8b13('0x1b')](this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]],{'showHidden':![],'depth':null}));this[_0x8b13('0x17')](_0x8b13('0x39'),_0x8b13('0x6c'),this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x1a')]]);delete this['channels'][_0x25cb45[_0x8b13('0x1a')]];}else if(this['channels'][_0x25cb45[_0x8b13('0x6d')]]){this[_0x8b13('0xa')][_0x25cb45[_0x8b13('0x6d')]][_0x8b13('0x1a')]=this['channels'][_0x25cb45['linkedid']][_0x8b13('0x6e')];}if(this[_0x8b13('0xe')][_0x25cb45['uniqueid']]){delete this[_0x8b13('0xe')][_0x25cb45[_0x8b13('0x1a')]];}}}catch(_0x3acd66){logger[_0x8b13('0x2b')](_0x8b13('0x6f'),_0x25cb45[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x3acd66,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8b13('0x15')][_0x8b13('0x70')]=function(_0x24211c){try{if(this['isNotNull'](_0x24211c)){logger[_0x8b13('0x28')](_0x8b13('0x71'),_0x24211c['uniqueid'],util[_0x8b13('0x1b')](_0x24211c,{'showHidden':![],'depth':null}));if(_0x24211c[_0x8b13('0x72')]['toLowerCase']()===_0x8b13('0x73')){_0x24211c[_0x8b13('0x74')]=(_0x24211c[_0x8b13('0x75')]||_0x24211c[_0x8b13('0x74')])[_0x8b13('0x76')]();if(_[_0x8b13('0x77')](_0x24211c[_0x8b13('0x74')],_0x8b13('0x78'))){if(_['isUndefined'](this[_0x8b13('0xd')][_0x24211c[_0x8b13('0x1a')]]))this[_0x8b13('0xd')][_0x24211c['uniqueid']]={};logger[_0x8b13('0x36')]('[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s',_0x24211c[_0x8b13('0x1a')],_0x24211c[_0x8b13('0x72')],_0x24211c[_0x8b13('0x74')]);var _0x40fefa=_0x24211c[_0x8b13('0x74')][_0x8b13('0x79')]('=');var _0x41cefe=_0x40fefa[0x0][_0x8b13('0x7a')](/cdr\((.*)\)/);if(_0x41cefe)this[_0x8b13('0xd')][_0x24211c[_0x8b13('0x1a')]][_0x41cefe[0x1]]=_0x40fefa[0x1];}}}}catch(_0x595f45){logger[_0x8b13('0x2b')](_0x8b13('0x7b'),_0x24211c[_0x8b13('0x1a')],util[_0x8b13('0x1b')](_0x595f45,{'showHidden':![],'depth':null}));}};module[_0x8b13('0x7c')]=VoiceDialReport;