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