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