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