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