9318475006a30d19c9fcb7e71bc12fa93b5f262b
[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 _0x26c1=['starttime','seconds','complete','total','answertime','holdtime','diff','sumHoldTime','billableseconds','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','custom:voiceDialReport','[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:','custom:dialend','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event','stringify','linkedid','destuniqueid','[%s][voiceDialReport][hangup]','syncNewExten','[%s][voiceDialReport][newexten]\x20event:','toLowerCase','set','appdata','startsWith','cdr(','[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s','application','applicationdata','split','match','[%s][voiceDialReport][newexten]','lodash','moment','util','ioredis','../../../config/logger','ami','redis','defaults','socket.io-emitter','channels','outboundChannels','outbound','applications','variables','dialbegin','syncDialBegin','bind','dialend','syncDialEnd','varset','syncVarSet','syncHangup','prototype','isUndefined','emit','isNotNull','debug','uniqueid','called','channel','substring','lastIndexOf','omit','event','privilege','info','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','membername','interface','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','inspect','merge','voice:outbound','voice_outbound_channel:save','custom:dialbegin','error','[%s][voiceDialReport][dialbegin]','dialstatus','ANSWER','connectedlinenum','connectedlinename','format','YYYY-MM-DD\x20HH:mm:ss','lastevent','connect','[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','[%s][voiceDialReport][dialend]','[%s][voiceDialReport][varset]\x20event:','keys','value','outboundrouteid','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','variable','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','addVariable','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','sipuri','bridgepeer','bridgepvtcallid','memberdynamic','memberinterface','memberlastcall','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','duration'];(function(_0x1ce895,_0x1040d2){var _0x4f2c4b=function(_0x30aa6e){while(--_0x30aa6e){_0x1ce895['push'](_0x1ce895['shift']());}};_0x4f2c4b(++_0x1040d2);}(_0x26c1,0x1e8));var _0x126c=function(_0x4429e0,_0xee6f1f){_0x4429e0=_0x4429e0-0x0;var _0x51a5b3=_0x26c1[_0x4429e0];return _0x51a5b3;};'use strict';var _=require(_0x126c('0x0'));var moment=require(_0x126c('0x1'));var util=require(_0x126c('0x2'));var Redis=require(_0x126c('0x3'));var config=require('../../../config/environment');var logger=require(_0x126c('0x4'))(_0x126c('0x5'));var ami=require('../ami');config[_0x126c('0x6')]=_[_0x126c('0x7')](config[_0x126c('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0x126c('0x8'))(new Redis(config[_0x126c('0x6')]));function VoiceDialReport(_0x1fd50c){this[_0x126c('0x9')]=_0x1fd50c[_0x126c('0xa')];this[_0x126c('0xb')]=_0x1fd50c[_0x126c('0xb')];this[_0x126c('0xc')]={};this[_0x126c('0xd')]={};ami['on'](_0x126c('0xe'),this[_0x126c('0xf')][_0x126c('0x10')](this));ami['on'](_0x126c('0x11'),this[_0x126c('0x12')][_0x126c('0x10')](this));ami['on'](_0x126c('0x13'),this[_0x126c('0x14')][_0x126c('0x10')](this));ami['on']('newexten',this['syncNewExten'][_0x126c('0x10')](this));ami['on']('hangup',this[_0x126c('0x15')][_0x126c('0x10')](this));}VoiceDialReport[_0x126c('0x16')]['isNotNull']=function(_0x230ef6){return _0x230ef6!==null&&!_[_0x126c('0x17')](_0x230ef6);};VoiceDialReport['prototype'][_0x126c('0x18')]=function(_0x46d023,_0x190901,_0x3fe4a8){io['to'](_0x46d023)[_0x126c('0x18')](_0x190901,_0x3fe4a8);};VoiceDialReport['prototype']['syncDialBegin']=function(_0x48d640){try{if(this[_0x126c('0x19')](_0x48d640)){logger[_0x126c('0x1a')]('[%s][voiceDialReport][dialbegin]\x20event:',_0x48d640[_0x126c('0x1b')],util['inspect'](_0x48d640,{'showHidden':![],'depth':null}));if(this[_0x126c('0x9')][_0x48d640[_0x126c('0x1b')]]){_['merge'](this['channels'][_0x48d640[_0x126c('0x1b')]],{'starttime':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'lastevent':_0x126c('0x1c'),'interface':_0x48d640[_0x126c('0x1d')][_0x126c('0x1e')](0x0,_0x48d640['channel']['lastIndexOf']('-')),'membername':_0x48d640['channel'][_0x126c('0x1e')](_0x48d640[_0x126c('0x1d')]['lastIndexOf']('/')+0x1,_0x48d640['channel'][_0x126c('0x1f')]('-'))},_[_0x126c('0x20')](_0x48d640,[_0x126c('0x21'),_0x126c('0x22')]));logger[_0x126c('0x23')](_0x126c('0x24'),_0x48d640[_0x126c('0x1b')],this[_0x126c('0x9')][_0x48d640[_0x126c('0x1b')]][_0x126c('0x25')],this[_0x126c('0x9')][_0x48d640[_0x126c('0x1b')]][_0x126c('0x26')]);logger[_0x126c('0x1a')](_0x126c('0x27'),_0x48d640['uniqueid'],util[_0x126c('0x28')](this['channels'][_0x48d640[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));if(this[_0x126c('0xc')][_0x48d640[_0x126c('0x1b')]])_[_0x126c('0x29')](this[_0x126c('0x9')][_0x48d640[_0x126c('0x1b')]],this['applications'][_0x48d640['uniqueid']]);this[_0x126c('0x18')](_0x126c('0x2a'),_0x126c('0x2b'),this['channels'][_0x48d640[_0x126c('0x1b')]]);logger[_0x126c('0x1a')]('[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:',_0x48d640['uniqueid'],util[_0x126c('0x28')](this[_0x126c('0x9')][_0x48d640['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x126c('0x18')](_0x126c('0x2c'),this['channels'][_0x48d640[_0x126c('0x1b')]]);}}}catch(_0x1bf2de){logger[_0x126c('0x2d')](_0x126c('0x2e'),_0x48d640[_0x126c('0x1b')],util[_0x126c('0x28')](_0x1bf2de,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x126c('0x12')]=function(_0x4eb92a){try{if(this[_0x126c('0x19')](_0x4eb92a)){logger[_0x126c('0x1a')]('[%s][voiceDialReport][dialend]\x20event:',_0x4eb92a[_0x126c('0x1b')],util[_0x126c('0x28')](_0x4eb92a,{'showHidden':![],'depth':null}));if(this['channels'][_0x4eb92a[_0x126c('0x1b')]]){this[_0x126c('0x9')][_0x4eb92a[_0x126c('0x1b')]][_0x126c('0x2f')]=_0x4eb92a[_0x126c('0x2f')];if(_0x4eb92a[_0x126c('0x2f')]===_0x126c('0x30')){this[_0x126c('0x9')][_0x4eb92a[_0x126c('0x1b')]]['connectedlinenum']=_0x4eb92a[_0x126c('0x31')];this[_0x126c('0x9')][_0x4eb92a['uniqueid']][_0x126c('0x32')]=_0x4eb92a[_0x126c('0x32')];this[_0x126c('0x9')][_0x4eb92a['uniqueid']]['answertime']=moment()[_0x126c('0x33')](_0x126c('0x34'));this[_0x126c('0x9')][_0x4eb92a[_0x126c('0x1b')]][_0x126c('0x35')]=_0x126c('0x36');logger[_0x126c('0x23')](_0x126c('0x37'),_0x4eb92a[_0x126c('0x1b')],_0x4eb92a[_0x126c('0x1d')]['substring'](_0x4eb92a['channel']['lastIndexOf']('/')+0x1,_0x4eb92a['channel']['lastIndexOf']('-')));logger['debug'](_0x126c('0x38'),_0x4eb92a[_0x126c('0x1b')],util[_0x126c('0x28')](this[_0x126c('0x9')][_0x4eb92a['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x126c('0x18')]('custom:dialconnect',this[_0x126c('0x9')][_0x4eb92a[_0x126c('0x1b')]]);}logger[_0x126c('0x1a')]('[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:',_0x4eb92a['uniqueid'],util[_0x126c('0x28')](this['channels'][_0x4eb92a[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));this[_0x126c('0x18')](_0x126c('0x2a'),_0x126c('0x2b'),this[_0x126c('0x9')][_0x4eb92a[_0x126c('0x1b')]]);}}}catch(_0x4b4c2c){logger['error'](_0x126c('0x39'),_0x4eb92a[_0x126c('0x1b')],util['inspect'](_0x4b4c2c,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x126c('0x16')][_0x126c('0x14')]=function(_0x1ff4bb){try{if(this['isNotNull'](_0x1ff4bb)){logger[_0x126c('0x1a')](_0x126c('0x3a'),_0x1ff4bb[_0x126c('0x1b')],util[_0x126c('0x28')](_0x1ff4bb,{'showHidden':![],'depth':null}));this['addVariable'](_0x1ff4bb[_0x126c('0x1b')],_[_0x126c('0x3b')](_0x1ff4bb['variable'])[0x0],_0x1ff4bb[_0x126c('0x3c')]);if(this[_0x126c('0x19')](_0x1ff4bb['variable'])&&this['isNotNull'](_0x1ff4bb['variable'][_0x126c('0x3d')])){if(_[_0x126c('0x17')](this[_0x126c('0x9')][_0x1ff4bb['uniqueid']])){this[_0x126c('0x9')][_0x1ff4bb[_0x126c('0x1b')]]={'routeId':_0x1ff4bb[_0x126c('0x3c')],'variables':this[_0x126c('0xd')][_0x1ff4bb[_0x126c('0x1b')]],'motionChannel':'voice'};logger[_0x126c('0x23')](_0x126c('0x3e'),_0x1ff4bb[_0x126c('0x1b')],_0x1ff4bb['variable']['outboundrouteid'],_[_0x126c('0x3b')](_0x1ff4bb[_0x126c('0x3f')])[0x0],_0x1ff4bb[_0x126c('0x3c')]);logger['debug'](_0x126c('0x40'),_0x1ff4bb['uniqueid'],util['inspect'](this[_0x126c('0x9')][_0x1ff4bb[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));this[_0x126c('0x18')](_0x126c('0x2a'),'voice_outbound_channel:save',this[_0x126c('0x9')][_0x1ff4bb['uniqueid']]);}}}}catch(_0x1fc48d){logger[_0x126c('0x2d')]('[%s][voiceDialReport][varset]',_0x1ff4bb[_0x126c('0x1b')],util[_0x126c('0x28')](_0x1fc48d,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x126c('0x16')][_0x126c('0x41')]=function(_0x33cc11,_0x5d9beb,_0x5d4f60){var _0x43b8ac=[_0x126c('0x42'),_0x126c('0x43'),_0x126c('0x44'),_0x126c('0x45'),_0x126c('0x46'),'rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid',_0x126c('0x47'),_0x126c('0x48'),_0x126c('0x49'),'membercalls',_0x126c('0x4a'),_0x126c('0x4b'),_0x126c('0x4c'),'membername','memberpenalty','memberrealtime'];if(!_['isNil'](_0x5d9beb)&&!_['includes'](_0x43b8ac,_0x5d9beb)){if(_[_0x126c('0x17')](this[_0x126c('0xd')][_0x33cc11])){this['variables'][_0x33cc11]={};}this[_0x126c('0xd')][_0x33cc11][_0x5d9beb]=_0x5d4f60;}};VoiceDialReport[_0x126c('0x16')][_0x126c('0x15')]=function(_0x29d66f){try{if(this[_0x126c('0x19')](_0x29d66f)){logger[_0x126c('0x1a')](_0x126c('0x4d'),_0x29d66f[_0x126c('0x1b')],util[_0x126c('0x28')](_0x29d66f,{'showHidden':![],'depth':null}));if(this[_0x126c('0x9')][_0x29d66f['uniqueid']]){logger[_0x126c('0x23')](_0x126c('0x4e'),_0x29d66f[_0x126c('0x1b')],_0x29d66f[_0x126c('0x4f')]);this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x50')]=moment()[_0x126c('0x33')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x126c('0x9')][_0x29d66f['uniqueid']][_0x126c('0x51')]=moment(this[_0x126c('0x9')][_0x29d66f['uniqueid']][_0x126c('0x50')])['diff'](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x52')],_0x126c('0x53'));this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x35')]=_0x126c('0x54');this[_0x126c('0xb')][_0x126c('0x55')]+=0x1;if(this['channels'][_0x29d66f['uniqueid']][_0x126c('0x56')]){this[_0x126c('0xb')]['answered']+=0x1;this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x57')]=moment(this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]]['answertime'])[_0x126c('0x58')](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x52')],_0x126c('0x53'));this[_0x126c('0x9')][_0x29d66f['uniqueid']]['billableseconds']=moment(this[_0x126c('0x9')][_0x29d66f['uniqueid']][_0x126c('0x50')])[_0x126c('0x58')](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x56')],_0x126c('0x53'));this[_0x126c('0xb')][_0x126c('0x59')]+=this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x57')]||0x0;this['outbound']['sumBillable']+=this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x5a')];}this[_0x126c('0xb')]['sumDuration']+=this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]][_0x126c('0x51')];logger[_0x126c('0x1a')](_0x126c('0x5b'),_0x29d66f['uniqueid'],util['inspect'](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));ami[_0x126c('0x18')](_0x126c('0x5c'),this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]]);logger[_0x126c('0x1a')](_0x126c('0x5d'),_0x29d66f['uniqueid'],util[_0x126c('0x28')](this['channels'][_0x29d66f[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));ami['emit'](_0x126c('0x5e'),this[_0x126c('0x9')][_0x29d66f['uniqueid']]);logger[_0x126c('0x1a')](_0x126c('0x5f'),_0x29d66f[_0x126c('0x1b')],util['inspect'](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));this[_0x126c('0x18')](_0x126c('0x2a'),'voice_outbound:save',this[_0x126c('0xb')]);logger[_0x126c('0x23')](_0x126c('0x60'),JSON[_0x126c('0x61')](this[_0x126c('0x9')][_0x29d66f['uniqueid']]));logger[_0x126c('0x1a')]('[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:',_0x29d66f[_0x126c('0x1b')],util[_0x126c('0x28')](this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]],{'showHidden':![],'depth':null}));this[_0x126c('0x18')](_0x126c('0x2a'),'voice_outbound_channel:remove',this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]]);delete this[_0x126c('0x9')][_0x29d66f[_0x126c('0x1b')]];}else if(this[_0x126c('0x9')][_0x29d66f[_0x126c('0x62')]]){this[_0x126c('0x9')][_0x29d66f[_0x126c('0x62')]]['uniqueid']=this[_0x126c('0x9')][_0x29d66f[_0x126c('0x62')]][_0x126c('0x63')];}if(this[_0x126c('0xd')][_0x29d66f[_0x126c('0x1b')]]){delete this[_0x126c('0xd')][_0x29d66f['uniqueid']];}}}catch(_0x1340c6){logger['error'](_0x126c('0x64'),_0x29d66f['uniqueid'],util[_0x126c('0x28')](_0x1340c6,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x126c('0x65')]=function(_0x57b59c){try{if(this[_0x126c('0x19')](_0x57b59c)){logger[_0x126c('0x1a')](_0x126c('0x66'),_0x57b59c[_0x126c('0x1b')],util[_0x126c('0x28')](_0x57b59c,{'showHidden':![],'depth':null}));if(_0x57b59c['application'][_0x126c('0x67')]()===_0x126c('0x68')){_0x57b59c['applicationdata']=(_0x57b59c[_0x126c('0x69')]||_0x57b59c['applicationdata'])[_0x126c('0x67')]();if(_[_0x126c('0x6a')](_0x57b59c['applicationdata'],_0x126c('0x6b'))){if(_['isUndefined'](this['applications'][_0x57b59c[_0x126c('0x1b')]]))this[_0x126c('0xc')][_0x57b59c['uniqueid']]={};logger[_0x126c('0x23')](_0x126c('0x6c'),_0x57b59c[_0x126c('0x1b')],_0x57b59c[_0x126c('0x6d')],_0x57b59c[_0x126c('0x6e')]);var _0x221486=_0x57b59c[_0x126c('0x6e')][_0x126c('0x6f')]('=');var _0x59ae25=_0x221486[0x0][_0x126c('0x70')](/cdr\((.*)\)/);if(_0x59ae25)this[_0x126c('0xc')][_0x57b59c['uniqueid']][_0x59ae25[0x1]]=_0x221486[0x1];}}}}catch(_0x125dce){logger[_0x126c('0x2d')](_0x126c('0x71'),_0x57b59c['uniqueid'],util[_0x126c('0x28')](_0x125dce,{'showHidden':![],'depth':null}));}};module['exports']=VoiceDialReport;