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