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