da8ebd95f097c4871fbd0a954eda12f4c9c927c5
[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 _0x5fab=['[%s][voiceDialReport][hangup]','[%s][voiceDialReport][newexten]\x20event:','application','set','applicationdata','appdata','toLowerCase','startsWith','[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s','split','match','exports','lodash','moment','ioredis','../../../config/environment','../../../config/logger','ami','../ami','redis','defaults','localhost','socket.io-emitter','channels','outboundChannels','outbound','applications','variables','dialbegin','dialend','syncDialEnd','bind','varset','syncVarSet','hangup','syncHangup','isNotNull','prototype','emit','debug','[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','merge','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','event','info','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','membername','interface','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','inspect','voice:outbound','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','[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','custom:dialconnect','[%s][voiceDialReport][dialend]','[%s][voiceDialReport][varset]\x20event:','addVariable','keys','variable','isUndefined','value','voice','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','outboundrouteid','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrttbridged','sipuri','bridgepeer','bridgepvtcallid','memberdynamic','memberinterface','memberpenalty','memberrealtime','isNil','includes','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','diff','starttime','seconds','complete','total','holdtime','billableseconds','sumHoldTime','sumBillable','duration','[%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'];(function(_0x29ce14,_0x334166){var _0x48f289=function(_0x288d11){while(--_0x288d11){_0x29ce14['push'](_0x29ce14['shift']());}};_0x48f289(++_0x334166);}(_0x5fab,0x177));var _0xb5fa=function(_0x16e6db,_0x2e5a01){_0x16e6db=_0x16e6db-0x0;var _0x5a9151=_0x5fab[_0x16e6db];return _0x5a9151;};'use strict';var _=require(_0xb5fa('0x0'));var moment=require(_0xb5fa('0x1'));var util=require('util');var Redis=require(_0xb5fa('0x2'));var config=require(_0xb5fa('0x3'));var logger=require(_0xb5fa('0x4'))(_0xb5fa('0x5'));var ami=require(_0xb5fa('0x6'));config[_0xb5fa('0x7')]=_[_0xb5fa('0x8')](config[_0xb5fa('0x7')],{'host':_0xb5fa('0x9'),'port':0x18eb});var io=require(_0xb5fa('0xa'))(new Redis(config['redis']));function VoiceDialReport(_0x5d70f6){this[_0xb5fa('0xb')]=_0x5d70f6[_0xb5fa('0xc')];this[_0xb5fa('0xd')]=_0x5d70f6['outbound'];this[_0xb5fa('0xe')]={};this[_0xb5fa('0xf')]={};ami['on'](_0xb5fa('0x10'),this['syncDialBegin']['bind'](this));ami['on'](_0xb5fa('0x11'),this[_0xb5fa('0x12')][_0xb5fa('0x13')](this));ami['on'](_0xb5fa('0x14'),this[_0xb5fa('0x15')][_0xb5fa('0x13')](this));ami['on'](_0xb5fa('0x16'),this[_0xb5fa('0x17')][_0xb5fa('0x13')](this));}VoiceDialReport['prototype'][_0xb5fa('0x18')]=function(_0x3dad4d){return _0x3dad4d!==null&&!_['isUndefined'](_0x3dad4d);};VoiceDialReport[_0xb5fa('0x19')]['emit']=function(_0x265992,_0x3fc372,_0x40c914){io['to'](_0x265992)[_0xb5fa('0x1a')](_0x3fc372,_0x40c914);};VoiceDialReport[_0xb5fa('0x19')]['syncDialBegin']=function(_0x567f31){try{if(this[_0xb5fa('0x18')](_0x567f31)){logger[_0xb5fa('0x1b')](_0xb5fa('0x1c'),_0x567f31[_0xb5fa('0x1d')],util['inspect'](_0x567f31,{'showHidden':![],'depth':null}));if(this['channels'][_0x567f31[_0xb5fa('0x1d')]]){_[_0xb5fa('0x1e')](this[_0xb5fa('0xb')][_0x567f31[_0xb5fa('0x1d')]],{'starttime':moment()[_0xb5fa('0x1f')](_0xb5fa('0x20')),'lastevent':_0xb5fa('0x21'),'interface':_0x567f31[_0xb5fa('0x22')][_0xb5fa('0x23')](0x0,_0x567f31[_0xb5fa('0x22')][_0xb5fa('0x24')]('-')),'membername':_0x567f31[_0xb5fa('0x22')]['substring'](_0x567f31[_0xb5fa('0x22')]['lastIndexOf']('/')+0x1,_0x567f31[_0xb5fa('0x22')]['lastIndexOf']('-'))},_[_0xb5fa('0x25')](_0x567f31,[_0xb5fa('0x26'),'privilege']));logger[_0xb5fa('0x27')](_0xb5fa('0x28'),_0x567f31[_0xb5fa('0x1d')],this['channels'][_0x567f31[_0xb5fa('0x1d')]][_0xb5fa('0x29')],this[_0xb5fa('0xb')][_0x567f31['uniqueid']][_0xb5fa('0x2a')]);logger['debug'](_0xb5fa('0x2b'),_0x567f31[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x567f31[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));if(this[_0xb5fa('0xe')][_0x567f31[_0xb5fa('0x1d')]])_[_0xb5fa('0x1e')](this['channels'][_0x567f31['uniqueid']],this['applications'][_0x567f31['uniqueid']]);this[_0xb5fa('0x1a')](_0xb5fa('0x2d'),_0xb5fa('0x2e'),this[_0xb5fa('0xb')][_0x567f31[_0xb5fa('0x1d')]]);logger[_0xb5fa('0x1b')](_0xb5fa('0x2f'),_0x567f31[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x567f31[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));ami[_0xb5fa('0x1a')](_0xb5fa('0x30'),this[_0xb5fa('0xb')][_0x567f31[_0xb5fa('0x1d')]]);}}}catch(_0x116773){logger[_0xb5fa('0x31')](_0xb5fa('0x32'),_0x567f31[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0x116773,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0xb5fa('0x19')][_0xb5fa('0x12')]=function(_0x10fb43){try{if(this[_0xb5fa('0x18')](_0x10fb43)){logger['debug'](_0xb5fa('0x33'),_0x10fb43['uniqueid'],util['inspect'](_0x10fb43,{'showHidden':![],'depth':null}));if(this['channels'][_0x10fb43[_0xb5fa('0x1d')]]){this['channels'][_0x10fb43[_0xb5fa('0x1d')]]['dialstatus']=_0x10fb43['dialstatus'];if(_0x10fb43[_0xb5fa('0x34')]===_0xb5fa('0x35')){this['channels'][_0x10fb43['uniqueid']][_0xb5fa('0x36')]=_0x10fb43[_0xb5fa('0x36')];this[_0xb5fa('0xb')][_0x10fb43['uniqueid']][_0xb5fa('0x37')]=_0x10fb43[_0xb5fa('0x37')];this['channels'][_0x10fb43[_0xb5fa('0x1d')]][_0xb5fa('0x38')]=moment()[_0xb5fa('0x1f')]('YYYY-MM-DD\x20HH:mm:ss');this[_0xb5fa('0xb')][_0x10fb43[_0xb5fa('0x1d')]][_0xb5fa('0x39')]='connect';logger[_0xb5fa('0x27')](_0xb5fa('0x3a'),_0x10fb43[_0xb5fa('0x1d')],_0x10fb43[_0xb5fa('0x22')]['substring'](_0x10fb43['channel']['lastIndexOf']('/')+0x1,_0x10fb43['channel']['lastIndexOf']('-')));logger['debug'](_0xb5fa('0x3b'),_0x10fb43['uniqueid'],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x10fb43[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));ami[_0xb5fa('0x1a')](_0xb5fa('0x3c'),this[_0xb5fa('0xb')][_0x10fb43['uniqueid']]);}logger['debug']('[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:',_0x10fb43[_0xb5fa('0x1d')],util['inspect'](this[_0xb5fa('0xb')][_0x10fb43['uniqueid']],{'showHidden':![],'depth':null}));this['emit'](_0xb5fa('0x2d'),_0xb5fa('0x2e'),this[_0xb5fa('0xb')][_0x10fb43[_0xb5fa('0x1d')]]);}}}catch(_0x5bc93f){logger[_0xb5fa('0x31')](_0xb5fa('0x3d'),_0x10fb43[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0x5bc93f,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0xb5fa('0x19')]['syncVarSet']=function(_0x284bbb){try{if(this['isNotNull'](_0x284bbb)){logger[_0xb5fa('0x1b')](_0xb5fa('0x3e'),_0x284bbb[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0x284bbb,{'showHidden':![],'depth':null}));this[_0xb5fa('0x3f')](_0x284bbb[_0xb5fa('0x1d')],_[_0xb5fa('0x40')](_0x284bbb[_0xb5fa('0x41')])[0x0],_0x284bbb['value']);if(this[_0xb5fa('0x18')](_0x284bbb[_0xb5fa('0x41')])&&this['isNotNull'](_0x284bbb[_0xb5fa('0x41')]['outboundrouteid'])){if(_[_0xb5fa('0x42')](this[_0xb5fa('0xb')][_0x284bbb['uniqueid']])){this['channels'][_0x284bbb[_0xb5fa('0x1d')]]={'routeId':_0x284bbb[_0xb5fa('0x43')],'variables':this[_0xb5fa('0xf')][_0x284bbb[_0xb5fa('0x1d')]],'motionChannel':_0xb5fa('0x44')};logger[_0xb5fa('0x27')](_0xb5fa('0x45'),_0x284bbb[_0xb5fa('0x1d')],_0x284bbb['variable'][_0xb5fa('0x46')],_[_0xb5fa('0x40')](_0x284bbb['variable'])[0x0],_0x284bbb[_0xb5fa('0x43')]);logger[_0xb5fa('0x1b')](_0xb5fa('0x47'),_0x284bbb[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x284bbb[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));this[_0xb5fa('0x1a')](_0xb5fa('0x2d'),_0xb5fa('0x2e'),this[_0xb5fa('0xb')][_0x284bbb[_0xb5fa('0x1d')]]);}}}}catch(_0x6ae261){logger[_0xb5fa('0x31')](_0xb5fa('0x48'),_0x284bbb[_0xb5fa('0x1d')],util['inspect'](_0x6ae261,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0xb5fa('0x3f')]=function(_0x55268f,_0x14fbb0,_0x1049d9){var _0x5404f6=[_0xb5fa('0x49'),_0xb5fa('0x4a'),_0xb5fa('0x4b'),_0xb5fa('0x4c'),_0xb5fa('0x4d'),_0xb5fa('0x4e'),'rtpaudioqosrtt',_0xb5fa('0x4f'),'sipcallid',_0xb5fa('0x50'),_0xb5fa('0x51'),_0xb5fa('0x52'),'membercalls',_0xb5fa('0x53'),_0xb5fa('0x54'),'memberlastcall','membername',_0xb5fa('0x55'),_0xb5fa('0x56')];if(!_[_0xb5fa('0x57')](_0x14fbb0)&&!_[_0xb5fa('0x58')](_0x5404f6,_0x14fbb0)){if(_[_0xb5fa('0x42')](this[_0xb5fa('0xf')][_0x55268f])){this[_0xb5fa('0xf')][_0x55268f]={};}this[_0xb5fa('0xf')][_0x55268f][_0x14fbb0]=_0x1049d9;}};VoiceDialReport[_0xb5fa('0x19')][_0xb5fa('0x17')]=function(_0x25de19){try{if(this[_0xb5fa('0x18')](_0x25de19)){logger[_0xb5fa('0x1b')](_0xb5fa('0x59'),_0x25de19[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0x25de19,{'showHidden':![],'depth':null}));if(this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]]){logger['info'](_0xb5fa('0x5a'),_0x25de19[_0xb5fa('0x1d')],_0x25de19[_0xb5fa('0x5b')]);this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x5c')]=moment()[_0xb5fa('0x1f')](_0xb5fa('0x20'));this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]]['duration']=moment(this['channels'][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x5c')])[_0xb5fa('0x5d')](this['channels'][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x5e')],_0xb5fa('0x5f'));this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x39')]=_0xb5fa('0x60');this['outbound'][_0xb5fa('0x61')]+=0x1;if(this[_0xb5fa('0xb')][_0x25de19['uniqueid']][_0xb5fa('0x38')]){this[_0xb5fa('0xd')]['answered']+=0x1;this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x62')]=moment(this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x38')])[_0xb5fa('0x5d')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x5e')],_0xb5fa('0x5f'));this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x63')]=moment(this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x5c')])[_0xb5fa('0x5d')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x38')],_0xb5fa('0x5f'));this['outbound'][_0xb5fa('0x64')]+=this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]]['holdtime']||0x0;this[_0xb5fa('0xd')][_0xb5fa('0x65')]+=this['channels'][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x63')];}this[_0xb5fa('0xd')]['sumDuration']+=this['channels'][_0x25de19[_0xb5fa('0x1d')]][_0xb5fa('0x66')];logger[_0xb5fa('0x1b')]('[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:',_0x25de19[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));ami['emit']('custom:voiceDialReport',this['channels'][_0x25de19[_0xb5fa('0x1d')]]);logger[_0xb5fa('0x1b')](_0xb5fa('0x67'),_0x25de19['uniqueid'],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));ami[_0xb5fa('0x1a')](_0xb5fa('0x68'),this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]]);logger[_0xb5fa('0x1b')](_0xb5fa('0x69'),_0x25de19[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));this[_0xb5fa('0x1a')](_0xb5fa('0x2d'),'voice_outbound:save',this[_0xb5fa('0xd')]);logger['info'](_0xb5fa('0x6a'),JSON[_0xb5fa('0x6b')](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]]));logger[_0xb5fa('0x1b')]('[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:',_0x25de19[_0xb5fa('0x1d')],util['inspect'](this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]],{'showHidden':![],'depth':null}));this[_0xb5fa('0x1a')](_0xb5fa('0x2d'),'voice_outbound_channel:remove',this['channels'][_0x25de19['uniqueid']]);delete this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x1d')]];}else if(this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x6c')]]){this[_0xb5fa('0xb')][_0x25de19[_0xb5fa('0x6c')]]['uniqueid']=this[_0xb5fa('0xb')][_0x25de19['linkedid']]['destuniqueid'];}if(this[_0xb5fa('0xf')][_0x25de19['uniqueid']]){delete this['variables'][_0x25de19['uniqueid']];}}}catch(_0x193e63){logger['error'](_0xb5fa('0x6d'),_0x25de19[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0x193e63,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype']['syncNewExten']=function(_0xb1fcac){try{if(this[_0xb5fa('0x18')](_0xb1fcac)){logger['debug'](_0xb5fa('0x6e'),_0xb1fcac[_0xb5fa('0x1d')],util[_0xb5fa('0x2c')](_0xb1fcac,{'showHidden':![],'depth':null}));if(_0xb1fcac[_0xb5fa('0x6f')]['toLowerCase']()===_0xb5fa('0x70')){_0xb1fcac[_0xb5fa('0x71')]=(_0xb1fcac[_0xb5fa('0x72')]||_0xb1fcac[_0xb5fa('0x71')])[_0xb5fa('0x73')]();if(_[_0xb5fa('0x74')](_0xb1fcac[_0xb5fa('0x71')],'cdr(')){if(_[_0xb5fa('0x42')](this['applications'][_0xb1fcac[_0xb5fa('0x1d')]]))this[_0xb5fa('0xe')][_0xb1fcac['uniqueid']]={};logger[_0xb5fa('0x27')](_0xb5fa('0x75'),_0xb1fcac[_0xb5fa('0x1d')],_0xb1fcac[_0xb5fa('0x6f')],_0xb1fcac[_0xb5fa('0x71')]);var _0x8ce5b8=_0xb1fcac[_0xb5fa('0x71')][_0xb5fa('0x76')]('=');var _0x4b1135=_0x8ce5b8[0x0][_0xb5fa('0x77')](/cdr\((.*)\)/);if(_0x4b1135)this[_0xb5fa('0xe')][_0xb1fcac[_0xb5fa('0x1d')]][_0x4b1135[0x1]]=_0x8ce5b8[0x1];}}}}catch(_0x20ffa1){logger['error']('[%s][voiceDialReport][newexten]',_0xb1fcac['uniqueid'],util['inspect'](_0x20ffa1,{'showHidden':![],'depth':null}));}};module[_0xb5fa('0x78')]=VoiceDialReport;