Built motion from commit (unavailable).|2.5.31
[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 _0x1510=['[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','duration','starttime','complete','answered','holdtime','diff','seconds','billableseconds','sumBillable','sumDuration','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','custom:dialend','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','voice_outbound:save','[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:','voice_outbound_channel:remove','linkedid','exports','lodash','moment','util','../../../config/environment','../../../config/logger','ami','../ami','redis','defaults','socket.io-emitter','channels','outboundChannels','outbound','variables','dialbegin','syncDialBegin','bind','dialend','syncDialEnd','varset','syncVarSet','syncHangup','prototype','isNotNull','isUndefined','emit','[%s][voiceDialReport][dialbegin]\x20event:','inspect','uniqueid','merge','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','event','privilege','info','membername','interface','debug','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','voice:outbound','[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:','[%s][voiceDialReport][dialbegin]','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','lastevent','connect','[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:','error','[%s][voiceDialReport][varset]\x20event:','addVariable','keys','value','variable','outboundrouteid','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','voice_outbound_channel:save','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid','sipuri','bridgepvtcallid','memberdynamic','memberinterface','memberlastcall','memberpenalty'];(function(_0x3e8643,_0x2fbfce){var _0x65da1f=function(_0x49d06d){while(--_0x49d06d){_0x3e8643['push'](_0x3e8643['shift']());}};_0x65da1f(++_0x2fbfce);}(_0x1510,0x7f));var _0x0151=function(_0x541c22,_0x5bc4ec){_0x541c22=_0x541c22-0x0;var _0x5be254=_0x1510[_0x541c22];return _0x5be254;};'use strict';var _=require(_0x0151('0x0'));var moment=require(_0x0151('0x1'));var util=require(_0x0151('0x2'));var Redis=require('ioredis');var config=require(_0x0151('0x3'));var logger=require(_0x0151('0x4'))(_0x0151('0x5'));var ami=require(_0x0151('0x6'));config[_0x0151('0x7')]=_[_0x0151('0x8')](config[_0x0151('0x7')],{'host':'localhost','port':0x18eb});var io=require(_0x0151('0x9'))(new Redis(config[_0x0151('0x7')]));function VoiceDialReport(_0x4cae13){this[_0x0151('0xa')]=_0x4cae13[_0x0151('0xb')];this[_0x0151('0xc')]=_0x4cae13[_0x0151('0xc')];this[_0x0151('0xd')]={};ami['on'](_0x0151('0xe'),this[_0x0151('0xf')][_0x0151('0x10')](this));ami['on'](_0x0151('0x11'),this[_0x0151('0x12')]['bind'](this));ami['on'](_0x0151('0x13'),this[_0x0151('0x14')][_0x0151('0x10')](this));ami['on']('hangup',this[_0x0151('0x15')]['bind'](this));}VoiceDialReport[_0x0151('0x16')][_0x0151('0x17')]=function(_0x5756c6){return _0x5756c6!==null&&!_[_0x0151('0x18')](_0x5756c6);};VoiceDialReport[_0x0151('0x16')][_0x0151('0x19')]=function(_0x24a192,_0x4b58d9,_0x3b7058){io['to'](_0x24a192)['emit'](_0x4b58d9,_0x3b7058);};VoiceDialReport[_0x0151('0x16')][_0x0151('0xf')]=function(_0x2b52bf){try{if(this[_0x0151('0x17')](_0x2b52bf)){logger['debug'](_0x0151('0x1a'),_0x2b52bf['uniqueid'],util[_0x0151('0x1b')](_0x2b52bf,{'showHidden':![],'depth':null}));if(this[_0x0151('0xa')][_0x2b52bf[_0x0151('0x1c')]]){_[_0x0151('0x1d')](this[_0x0151('0xa')][_0x2b52bf[_0x0151('0x1c')]],{'starttime':moment()[_0x0151('0x1e')](_0x0151('0x1f')),'lastevent':_0x0151('0x20'),'interface':_0x2b52bf[_0x0151('0x21')][_0x0151('0x22')](0x0,_0x2b52bf[_0x0151('0x21')][_0x0151('0x23')]('-')),'membername':_0x2b52bf[_0x0151('0x21')][_0x0151('0x22')](_0x2b52bf[_0x0151('0x21')]['lastIndexOf']('/')+0x1,_0x2b52bf['channel'][_0x0151('0x23')]('-'))},_['omit'](_0x2b52bf,[_0x0151('0x24'),_0x0151('0x25')]));logger[_0x0151('0x26')]('[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called',_0x2b52bf['uniqueid'],this[_0x0151('0xa')][_0x2b52bf['uniqueid']][_0x0151('0x27')],this[_0x0151('0xa')][_0x2b52bf[_0x0151('0x1c')]][_0x0151('0x28')]);logger[_0x0151('0x29')](_0x0151('0x2a'),_0x2b52bf[_0x0151('0x1c')],util[_0x0151('0x1b')](this['channels'][_0x2b52bf[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));this[_0x0151('0x19')](_0x0151('0x2b'),'voice_outbound_channel:save',this[_0x0151('0xa')][_0x2b52bf[_0x0151('0x1c')]]);logger[_0x0151('0x29')](_0x0151('0x2c'),_0x2b52bf[_0x0151('0x1c')],util['inspect'](this['channels'][_0x2b52bf[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x0151('0x19')]('custom:dialbegin',this[_0x0151('0xa')][_0x2b52bf[_0x0151('0x1c')]]);}}}catch(_0x216fe3){logger['error'](_0x0151('0x2d'),_0x2b52bf[_0x0151('0x1c')],util[_0x0151('0x1b')](_0x216fe3,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x0151('0x16')]['syncDialEnd']=function(_0x4f00f0){try{if(this['isNotNull'](_0x4f00f0)){logger[_0x0151('0x29')]('[%s][voiceDialReport][dialend]\x20event:',_0x4f00f0[_0x0151('0x1c')],util[_0x0151('0x1b')](_0x4f00f0,{'showHidden':![],'depth':null}));if(this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]]){this['channels'][_0x4f00f0[_0x0151('0x1c')]][_0x0151('0x2e')]=_0x4f00f0[_0x0151('0x2e')];if(_0x4f00f0['dialstatus']===_0x0151('0x2f')){this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]][_0x0151('0x30')]=_0x4f00f0[_0x0151('0x30')];this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]]['connectedlinename']=_0x4f00f0[_0x0151('0x31')];this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]][_0x0151('0x32')]=moment()[_0x0151('0x1e')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]][_0x0151('0x33')]=_0x0151('0x34');logger[_0x0151('0x26')](_0x0151('0x35'),_0x4f00f0[_0x0151('0x1c')],_0x4f00f0[_0x0151('0x21')]['substring'](_0x4f00f0[_0x0151('0x21')][_0x0151('0x23')]('/')+0x1,_0x4f00f0[_0x0151('0x21')][_0x0151('0x23')]('-')));logger[_0x0151('0x29')](_0x0151('0x36'),_0x4f00f0[_0x0151('0x1c')],util[_0x0151('0x1b')](this['channels'][_0x4f00f0['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x0151('0x19')]('custom:dialconnect',this[_0x0151('0xa')][_0x4f00f0[_0x0151('0x1c')]]);}logger[_0x0151('0x29')](_0x0151('0x37'),_0x4f00f0[_0x0151('0x1c')],util['inspect'](this['channels'][_0x4f00f0[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));this[_0x0151('0x19')](_0x0151('0x2b'),'voice_outbound_channel:save',this[_0x0151('0xa')][_0x4f00f0['uniqueid']]);}}}catch(_0x568f8a){logger[_0x0151('0x38')]('[%s][voiceDialReport][dialend]',_0x4f00f0[_0x0151('0x1c')],util[_0x0151('0x1b')](_0x568f8a,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x0151('0x16')][_0x0151('0x14')]=function(_0x3d6726){try{if(this[_0x0151('0x17')](_0x3d6726)){logger[_0x0151('0x29')](_0x0151('0x39'),_0x3d6726['uniqueid'],util[_0x0151('0x1b')](_0x3d6726,{'showHidden':![],'depth':null}));this[_0x0151('0x3a')](_0x3d6726[_0x0151('0x1c')],_[_0x0151('0x3b')](_0x3d6726['variable'])[0x0],_0x3d6726[_0x0151('0x3c')]);if(this['isNotNull'](_0x3d6726['variable'])&&this['isNotNull'](_0x3d6726[_0x0151('0x3d')][_0x0151('0x3e')])){if(_['isUndefined'](this[_0x0151('0xa')][_0x3d6726[_0x0151('0x1c')]])){this[_0x0151('0xa')][_0x3d6726[_0x0151('0x1c')]]={'routeId':_0x3d6726['value'],'variables':this[_0x0151('0xd')][_0x3d6726['uniqueid']]};logger[_0x0151('0x26')](_0x0151('0x3f'),_0x3d6726[_0x0151('0x1c')],_0x3d6726[_0x0151('0x3d')][_0x0151('0x3e')],_['keys'](_0x3d6726[_0x0151('0x3d')])[0x0],_0x3d6726[_0x0151('0x3c')]);logger[_0x0151('0x29')](_0x0151('0x40'),_0x3d6726['uniqueid'],util['inspect'](this[_0x0151('0xa')][_0x3d6726['uniqueid']],{'showHidden':![],'depth':null}));this['emit'](_0x0151('0x2b'),_0x0151('0x41'),this[_0x0151('0xa')][_0x3d6726[_0x0151('0x1c')]]);}}}}catch(_0x28bc3c){logger[_0x0151('0x38')](_0x0151('0x42'),_0x3d6726['uniqueid'],util[_0x0151('0x1b')](_0x28bc3c,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x0151('0x16')][_0x0151('0x3a')]=function(_0x40bd83,_0x5d8986,_0x4260df){var _0x468fe5=[_0x0151('0x43'),'rtpaudioqosbridged',_0x0151('0x44'),_0x0151('0x45'),_0x0151('0x46'),_0x0151('0x47'),_0x0151('0x48'),_0x0151('0x49'),_0x0151('0x4a'),_0x0151('0x4b'),'bridgepeer',_0x0151('0x4c'),'membercalls',_0x0151('0x4d'),_0x0151('0x4e'),_0x0151('0x4f'),_0x0151('0x27'),_0x0151('0x50'),'memberrealtime'];if(!_['isNil'](_0x5d8986)&&!_['includes'](_0x468fe5,_0x5d8986)){if(_[_0x0151('0x18')](this['variables'][_0x40bd83])){this['variables'][_0x40bd83]={};}this['variables'][_0x40bd83][_0x5d8986]=_0x4260df;}};VoiceDialReport[_0x0151('0x16')][_0x0151('0x15')]=function(_0x56da1e){try{if(this[_0x0151('0x17')](_0x56da1e)){logger[_0x0151('0x29')](_0x0151('0x51'),_0x56da1e['uniqueid'],util[_0x0151('0x1b')](_0x56da1e,{'showHidden':![],'depth':null}));if(this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]]){logger['info'](_0x0151('0x52'),_0x56da1e['uniqueid'],_0x56da1e[_0x0151('0x53')]);this[_0x0151('0xa')][_0x56da1e['uniqueid']][_0x0151('0x54')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x55')]=moment(this['channels'][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x54')])['diff'](this['channels'][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x56')],'seconds');this['channels'][_0x56da1e[_0x0151('0x1c')]]['lastevent']=_0x0151('0x57');this[_0x0151('0xc')]['total']+=0x1;if(this[_0x0151('0xa')][_0x56da1e['uniqueid']][_0x0151('0x32')]){this[_0x0151('0xc')][_0x0151('0x58')]+=0x1;this['channels'][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x59')]=moment(this[_0x0151('0xa')][_0x56da1e['uniqueid']][_0x0151('0x32')])[_0x0151('0x5a')](this[_0x0151('0xa')][_0x56da1e['uniqueid']]['starttime'],_0x0151('0x5b'));this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x5c')]=moment(this['channels'][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x54')])['diff'](this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]]['answertime'],'seconds');this[_0x0151('0xc')]['sumHoldTime']+=this[_0x0151('0xa')][_0x56da1e['uniqueid']]['holdtime']||0x0;this[_0x0151('0xc')][_0x0151('0x5d')]+=this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x5c')];}this[_0x0151('0xc')][_0x0151('0x5e')]+=this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]][_0x0151('0x55')];logger[_0x0151('0x29')](_0x0151('0x5f'),_0x56da1e['uniqueid'],util[_0x0151('0x1b')](this[_0x0151('0xa')][_0x56da1e['uniqueid']],{'showHidden':![],'depth':null}));ami['emit']('custom:voiceDialReport',this['channels'][_0x56da1e['uniqueid']]);logger[_0x0151('0x29')]('[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:',_0x56da1e[_0x0151('0x1c')],util[_0x0151('0x1b')](this['channels'][_0x56da1e[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x0151('0x19')](_0x0151('0x60'),this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]]);logger[_0x0151('0x29')](_0x0151('0x61'),_0x56da1e[_0x0151('0x1c')],util[_0x0151('0x1b')](this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));this[_0x0151('0x19')](_0x0151('0x2b'),_0x0151('0x62'),this['outbound']);logger[_0x0151('0x26')](_0x0151('0x63'),JSON['stringify'](this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]]));logger[_0x0151('0x29')](_0x0151('0x64'),_0x56da1e[_0x0151('0x1c')],util[_0x0151('0x1b')](this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]],{'showHidden':![],'depth':null}));this[_0x0151('0x19')]('voice:outbound',_0x0151('0x65'),this[_0x0151('0xa')][_0x56da1e[_0x0151('0x1c')]]);delete this[_0x0151('0xa')][_0x56da1e['uniqueid']];}else if(this['channels'][_0x56da1e[_0x0151('0x66')]]){this[_0x0151('0xa')][_0x56da1e[_0x0151('0x66')]]['uniqueid']=this['channels'][_0x56da1e[_0x0151('0x66')]]['destuniqueid'];}if(this[_0x0151('0xd')][_0x56da1e[_0x0151('0x1c')]]){delete this[_0x0151('0xd')][_0x56da1e[_0x0151('0x1c')]];}}}catch(_0x3f8939){logger[_0x0151('0x38')]('[%s][voiceDialReport][hangup]',_0x56da1e[_0x0151('0x1c')],util[_0x0151('0x1b')](_0x3f8939,{'showHidden':![],'depth':null}));}};module[_0x0151('0x67')]=VoiceDialReport;