Built motion from commit c1aa34a0.|2.6.28
[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 _0x4c60=['debug','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','voice:outbound','custom:dialbegin','error','dialstatus','ANSWER','connectedlinenum','connectedlinename','format','connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','custom:dialconnect','voice_outbound_channel:save','addVariable','variable','outboundrouteid','value','voice','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','keys','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','sipcallid','sipuri','bridgepeer','bridgepvtcallid','membercalls','memberdynamic','memberinterface','memberlastcall','membername','memberpenalty','memberrealtime','isNil','includes','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','duration','diff','starttime','lastevent','complete','total','answertime','answered','holdtime','billableseconds','sumHoldTime','sumBillable','custom:voiceDialReport','[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','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','[%s][voiceDialReport][newexten]\x20event:','toLowerCase','applicationdata','appdata','startsWith','cdr(','[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s','application','split','match','lodash','moment','util','ioredis','../../../config/logger','redis','localhost','socket.io-emitter','channels','outboundChannels','outbound','applications','variables','dialbegin','syncDialEnd','varset','syncVarSet','hangup','syncHangup','bind','prototype','isUndefined','emit','syncDialBegin','isNotNull','[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','inspect','merge','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','privilege','info','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','interface'];(function(_0x58dc25,_0x49b9d5){var _0x21b0a7=function(_0x38a186){while(--_0x38a186){_0x58dc25['push'](_0x58dc25['shift']());}};_0x21b0a7(++_0x49b9d5);}(_0x4c60,0xc1));var _0x04c6=function(_0x200cbe,_0x5452f1){_0x200cbe=_0x200cbe-0x0;var _0xc33783=_0x4c60[_0x200cbe];return _0xc33783;};'use strict';var _=require(_0x04c6('0x0'));var moment=require(_0x04c6('0x1'));var util=require(_0x04c6('0x2'));var Redis=require(_0x04c6('0x3'));var config=require('../../../config/environment');var logger=require(_0x04c6('0x4'))('ami');var ami=require('../ami');config['redis']=_['defaults'](config[_0x04c6('0x5')],{'host':_0x04c6('0x6'),'port':0x18eb});var io=require(_0x04c6('0x7'))(new Redis(config[_0x04c6('0x5')]));function VoiceDialReport(_0x2b9041){this[_0x04c6('0x8')]=_0x2b9041[_0x04c6('0x9')];this['outbound']=_0x2b9041[_0x04c6('0xa')];this[_0x04c6('0xb')]={};this[_0x04c6('0xc')]={};ami['on'](_0x04c6('0xd'),this['syncDialBegin']['bind'](this));ami['on']('dialend',this[_0x04c6('0xe')]['bind'](this));ami['on'](_0x04c6('0xf'),this[_0x04c6('0x10')]['bind'](this));ami['on'](_0x04c6('0x11'),this[_0x04c6('0x12')][_0x04c6('0x13')](this));}VoiceDialReport[_0x04c6('0x14')]['isNotNull']=function(_0x257a0a){return _0x257a0a!==null&&!_[_0x04c6('0x15')](_0x257a0a);};VoiceDialReport[_0x04c6('0x14')]['emit']=function(_0x12d1c5,_0x15cbe0,_0x28632e){io['to'](_0x12d1c5)[_0x04c6('0x16')](_0x15cbe0,_0x28632e);};VoiceDialReport[_0x04c6('0x14')][_0x04c6('0x17')]=function(_0x1cd963){try{if(this[_0x04c6('0x18')](_0x1cd963)){logger['debug'](_0x04c6('0x19'),_0x1cd963[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x1cd963,{'showHidden':![],'depth':null}));if(this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]]){_[_0x04c6('0x1c')](this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]],{'starttime':moment()['format'](_0x04c6('0x1d')),'lastevent':_0x04c6('0x1e'),'interface':_0x1cd963[_0x04c6('0x1f')]['substring'](0x0,_0x1cd963['channel']['lastIndexOf']('-')),'membername':_0x1cd963[_0x04c6('0x1f')][_0x04c6('0x20')](_0x1cd963['channel']['lastIndexOf']('/')+0x1,_0x1cd963[_0x04c6('0x1f')][_0x04c6('0x21')]('-'))},_[_0x04c6('0x22')](_0x1cd963,['event',_0x04c6('0x23')]));logger[_0x04c6('0x24')](_0x04c6('0x25'),_0x1cd963['uniqueid'],this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]]['membername'],this['channels'][_0x1cd963['uniqueid']][_0x04c6('0x26')]);logger[_0x04c6('0x27')](_0x04c6('0x28'),_0x1cd963[_0x04c6('0x1a')],util[_0x04c6('0x1b')](this['channels'][_0x1cd963['uniqueid']],{'showHidden':![],'depth':null}));if(this[_0x04c6('0xb')][_0x1cd963[_0x04c6('0x1a')]])_[_0x04c6('0x1c')](this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]],this[_0x04c6('0xb')][_0x1cd963['uniqueid']]);this[_0x04c6('0x16')](_0x04c6('0x29'),'voice_outbound_channel:save',this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]]);logger['debug']('[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:',_0x1cd963[_0x04c6('0x1a')],util[_0x04c6('0x1b')](this[_0x04c6('0x8')][_0x1cd963[_0x04c6('0x1a')]],{'showHidden':![],'depth':null}));ami[_0x04c6('0x16')](_0x04c6('0x2a'),this['channels'][_0x1cd963['uniqueid']]);}}}catch(_0x4fd842){logger[_0x04c6('0x2b')]('[%s][voiceDialReport][dialbegin]',_0x1cd963[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x4fd842,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x04c6('0xe')]=function(_0x36f2af){try{if(this[_0x04c6('0x18')](_0x36f2af)){logger[_0x04c6('0x27')]('[%s][voiceDialReport][dialend]\x20event:',_0x36f2af[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x36f2af,{'showHidden':![],'depth':null}));if(this[_0x04c6('0x8')][_0x36f2af[_0x04c6('0x1a')]]){this[_0x04c6('0x8')][_0x36f2af[_0x04c6('0x1a')]][_0x04c6('0x2c')]=_0x36f2af[_0x04c6('0x2c')];if(_0x36f2af[_0x04c6('0x2c')]===_0x04c6('0x2d')){this[_0x04c6('0x8')][_0x36f2af[_0x04c6('0x1a')]][_0x04c6('0x2e')]=_0x36f2af[_0x04c6('0x2e')];this[_0x04c6('0x8')][_0x36f2af['uniqueid']][_0x04c6('0x2f')]=_0x36f2af[_0x04c6('0x2f')];this[_0x04c6('0x8')][_0x36f2af[_0x04c6('0x1a')]]['answertime']=moment()[_0x04c6('0x30')](_0x04c6('0x1d'));this['channels'][_0x36f2af['uniqueid']]['lastevent']=_0x04c6('0x31');logger[_0x04c6('0x24')]('[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect',_0x36f2af[_0x04c6('0x1a')],_0x36f2af['channel'][_0x04c6('0x20')](_0x36f2af[_0x04c6('0x1f')][_0x04c6('0x21')]('/')+0x1,_0x36f2af[_0x04c6('0x1f')]['lastIndexOf']('-')));logger['debug'](_0x04c6('0x32'),_0x36f2af[_0x04c6('0x1a')],util['inspect'](this[_0x04c6('0x8')][_0x36f2af['uniqueid']],{'showHidden':![],'depth':null}));ami['emit'](_0x04c6('0x33'),this['channels'][_0x36f2af[_0x04c6('0x1a')]]);}logger[_0x04c6('0x27')]('[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:',_0x36f2af[_0x04c6('0x1a')],util['inspect'](this[_0x04c6('0x8')][_0x36f2af[_0x04c6('0x1a')]],{'showHidden':![],'depth':null}));this[_0x04c6('0x16')](_0x04c6('0x29'),_0x04c6('0x34'),this['channels'][_0x36f2af[_0x04c6('0x1a')]]);}}}catch(_0x51aacb){logger[_0x04c6('0x2b')]('[%s][voiceDialReport][dialend]',_0x36f2af[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x51aacb,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x04c6('0x14')][_0x04c6('0x10')]=function(_0xe6012e){try{if(this[_0x04c6('0x18')](_0xe6012e)){logger[_0x04c6('0x27')]('[%s][voiceDialReport][varset]\x20event:',_0xe6012e[_0x04c6('0x1a')],util['inspect'](_0xe6012e,{'showHidden':![],'depth':null}));this[_0x04c6('0x35')](_0xe6012e['uniqueid'],_['keys'](_0xe6012e[_0x04c6('0x36')])[0x0],_0xe6012e['value']);if(this[_0x04c6('0x18')](_0xe6012e[_0x04c6('0x36')])&&this[_0x04c6('0x18')](_0xe6012e['variable'][_0x04c6('0x37')])){if(_[_0x04c6('0x15')](this[_0x04c6('0x8')][_0xe6012e[_0x04c6('0x1a')]])){this[_0x04c6('0x8')][_0xe6012e[_0x04c6('0x1a')]]={'routeId':_0xe6012e[_0x04c6('0x38')],'variables':this['variables'][_0xe6012e['uniqueid']],'motionChannel':_0x04c6('0x39')};logger[_0x04c6('0x24')](_0x04c6('0x3a'),_0xe6012e['uniqueid'],_0xe6012e[_0x04c6('0x36')][_0x04c6('0x37')],_[_0x04c6('0x3b')](_0xe6012e['variable'])[0x0],_0xe6012e['value']);logger['debug'](_0x04c6('0x3c'),_0xe6012e[_0x04c6('0x1a')],util['inspect'](this[_0x04c6('0x8')][_0xe6012e[_0x04c6('0x1a')]],{'showHidden':![],'depth':null}));this[_0x04c6('0x16')]('voice:outbound',_0x04c6('0x34'),this[_0x04c6('0x8')][_0xe6012e['uniqueid']]);}}}}catch(_0x25a6fc){logger[_0x04c6('0x2b')](_0x04c6('0x3d'),_0xe6012e[_0x04c6('0x1a')],util['inspect'](_0x25a6fc,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x04c6('0x14')][_0x04c6('0x35')]=function(_0xc706d3,_0x3aaf1a,_0x5155aa){var _0x192437=[_0x04c6('0x3e'),_0x04c6('0x3f'),_0x04c6('0x40'),'rtpaudioqosjitterbridged',_0x04c6('0x41'),_0x04c6('0x42'),_0x04c6('0x43'),'rtpaudioqosrttbridged',_0x04c6('0x44'),_0x04c6('0x45'),_0x04c6('0x46'),_0x04c6('0x47'),_0x04c6('0x48'),_0x04c6('0x49'),_0x04c6('0x4a'),_0x04c6('0x4b'),_0x04c6('0x4c'),_0x04c6('0x4d'),_0x04c6('0x4e')];if(!_[_0x04c6('0x4f')](_0x3aaf1a)&&!_[_0x04c6('0x50')](_0x192437,_0x3aaf1a)){if(_['isUndefined'](this[_0x04c6('0xc')][_0xc706d3])){this[_0x04c6('0xc')][_0xc706d3]={};}this[_0x04c6('0xc')][_0xc706d3][_0x3aaf1a]=_0x5155aa;}};VoiceDialReport[_0x04c6('0x14')][_0x04c6('0x12')]=function(_0x48124f){try{if(this[_0x04c6('0x18')](_0x48124f)){logger[_0x04c6('0x27')](_0x04c6('0x51'),_0x48124f[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x48124f,{'showHidden':![],'depth':null}));if(this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]]){logger[_0x04c6('0x24')](_0x04c6('0x52'),_0x48124f[_0x04c6('0x1a')],_0x48124f['cause-txt']);this['channels'][_0x48124f['uniqueid']]['endtime']=moment()[_0x04c6('0x30')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x04c6('0x8')][_0x48124f['uniqueid']][_0x04c6('0x53')]=moment(this[_0x04c6('0x8')][_0x48124f['uniqueid']]['endtime'])[_0x04c6('0x54')](this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x55')],'seconds');this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x56')]=_0x04c6('0x57');this[_0x04c6('0xa')][_0x04c6('0x58')]+=0x1;if(this[_0x04c6('0x8')][_0x48124f['uniqueid']][_0x04c6('0x59')]){this['outbound'][_0x04c6('0x5a')]+=0x1;this[_0x04c6('0x8')][_0x48124f['uniqueid']][_0x04c6('0x5b')]=moment(this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x59')])[_0x04c6('0x54')](this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x55')],'seconds');this[_0x04c6('0x8')][_0x48124f['uniqueid']][_0x04c6('0x5c')]=moment(this[_0x04c6('0x8')][_0x48124f['uniqueid']]['endtime'])[_0x04c6('0x54')](this['channels'][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x59')],'seconds');this[_0x04c6('0xa')][_0x04c6('0x5d')]+=this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x5b')]||0x0;this[_0x04c6('0xa')][_0x04c6('0x5e')]+=this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x5c')];}this[_0x04c6('0xa')]['sumDuration']+=this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]][_0x04c6('0x53')];logger[_0x04c6('0x27')]('[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:',_0x48124f[_0x04c6('0x1a')],util[_0x04c6('0x1b')](this[_0x04c6('0x8')][_0x48124f['uniqueid']],{'showHidden':![],'depth':null}));ami['emit'](_0x04c6('0x5f'),this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]]);logger[_0x04c6('0x27')](_0x04c6('0x60'),_0x48124f[_0x04c6('0x1a')],util['inspect'](this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]],{'showHidden':![],'depth':null}));ami[_0x04c6('0x16')]('custom:dialend',this['channels'][_0x48124f[_0x04c6('0x1a')]]);logger[_0x04c6('0x27')](_0x04c6('0x61'),_0x48124f[_0x04c6('0x1a')],util['inspect'](this[_0x04c6('0x8')][_0x48124f['uniqueid']],{'showHidden':![],'depth':null}));this['emit'](_0x04c6('0x29'),_0x04c6('0x62'),this[_0x04c6('0xa')]);logger[_0x04c6('0x24')](_0x04c6('0x63'),JSON[_0x04c6('0x64')](this[_0x04c6('0x8')][_0x48124f['uniqueid']]));logger[_0x04c6('0x27')](_0x04c6('0x65'),_0x48124f[_0x04c6('0x1a')],util[_0x04c6('0x1b')](this[_0x04c6('0x8')][_0x48124f['uniqueid']],{'showHidden':![],'depth':null}));this['emit'](_0x04c6('0x29'),_0x04c6('0x66'),this[_0x04c6('0x8')][_0x48124f['uniqueid']]);delete this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x1a')]];}else if(this['channels'][_0x48124f[_0x04c6('0x67')]]){this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x67')]][_0x04c6('0x1a')]=this[_0x04c6('0x8')][_0x48124f[_0x04c6('0x67')]][_0x04c6('0x68')];}if(this[_0x04c6('0xc')][_0x48124f[_0x04c6('0x1a')]]){delete this[_0x04c6('0xc')][_0x48124f[_0x04c6('0x1a')]];}}}catch(_0x384018){logger[_0x04c6('0x2b')]('[%s][voiceDialReport][hangup]',_0x48124f[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x384018,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x04c6('0x69')]=function(_0x285dd1){try{if(this[_0x04c6('0x18')](_0x285dd1)){logger[_0x04c6('0x27')](_0x04c6('0x6a'),_0x285dd1['uniqueid'],util[_0x04c6('0x1b')](_0x285dd1,{'showHidden':![],'depth':null}));if(_0x285dd1['application'][_0x04c6('0x6b')]()==='set'){_0x285dd1[_0x04c6('0x6c')]=(_0x285dd1[_0x04c6('0x6d')]||_0x285dd1[_0x04c6('0x6c')])[_0x04c6('0x6b')]();if(_[_0x04c6('0x6e')](_0x285dd1[_0x04c6('0x6c')],_0x04c6('0x6f'))){if(_[_0x04c6('0x15')](this[_0x04c6('0xb')][_0x285dd1['uniqueid']]))this[_0x04c6('0xb')][_0x285dd1[_0x04c6('0x1a')]]={};logger['info'](_0x04c6('0x70'),_0x285dd1['uniqueid'],_0x285dd1[_0x04c6('0x71')],_0x285dd1[_0x04c6('0x6c')]);var _0x53293f=_0x285dd1[_0x04c6('0x6c')][_0x04c6('0x72')]('=');var _0x5bdad4=_0x53293f[0x0][_0x04c6('0x73')](/cdr\((.*)\)/);if(_0x5bdad4)this[_0x04c6('0xb')][_0x285dd1['uniqueid']][_0x5bdad4[0x1]]=_0x53293f[0x1];}}}}catch(_0x7b9132){logger[_0x04c6('0x2b')]('[%s][voiceDialReport][newexten]',_0x285dd1[_0x04c6('0x1a')],util[_0x04c6('0x1b')](_0x7b9132,{'showHidden':![],'depth':null}));}};module['exports']=VoiceDialReport;