88bb7866e0314a0ff746a887439b55f838a2da26
[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 _0x1cb9=['varset','syncVarSet','hangup','prototype','isUndefined','emit','isNotNull','debug','uniqueid','inspect','merge','YYYY-MM-DD\x20HH:mm:ss','called','substring','channel','lastIndexOf','omit','event','privilege','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','membername','interface','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','voice_outbound_channel:save','[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:','custom:dialbegin','error','[%s][voiceDialReport][dialbegin]','[%s][voiceDialReport][dialend]\x20event:','dialstatus','connectedlinename','answertime','format','lastevent','connect','info','[%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]','[%s][voiceDialReport][varset]\x20event:','addVariable','keys','value','variable','outboundrouteid','variables','voice','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','voice:outbound','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid','membercalls','memberinterface','memberpenalty','memberrealtime','isNil','includes','syncHangup','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','duration','diff','seconds','complete','total','answered','holdtime','billableseconds','sumBillable','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','[%s][voiceDialReport][hangup]','syncNewExten','application','toLowerCase','set','applicationdata','cdr(','[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s','split','match','[%s][voiceDialReport][newexten]','exports','lodash','util','ioredis','../../../config/environment','../../../config/logger','../ami','redis','localhost','socket.io-emitter','channels','outbound','applications','dialbegin','syncDialBegin','bind','dialend','syncDialEnd'];(function(_0x14f30b,_0x4ac7ca){var _0x248b2e=function(_0x800f64){while(--_0x800f64){_0x14f30b['push'](_0x14f30b['shift']());}};_0x248b2e(++_0x4ac7ca);}(_0x1cb9,0x14e));var _0x91cb=function(_0x5d3aae,_0x47613e){_0x5d3aae=_0x5d3aae-0x0;var _0x3f0a22=_0x1cb9[_0x5d3aae];return _0x3f0a22;};'use strict';var _=require(_0x91cb('0x0'));var moment=require('moment');var util=require(_0x91cb('0x1'));var Redis=require(_0x91cb('0x2'));var config=require(_0x91cb('0x3'));var logger=require(_0x91cb('0x4'))('ami');var ami=require(_0x91cb('0x5'));config[_0x91cb('0x6')]=_['defaults'](config[_0x91cb('0x6')],{'host':_0x91cb('0x7'),'port':0x18eb});var io=require(_0x91cb('0x8'))(new Redis(config[_0x91cb('0x6')]));function VoiceDialReport(_0x3b9d98){this[_0x91cb('0x9')]=_0x3b9d98['outboundChannels'];this[_0x91cb('0xa')]=_0x3b9d98['outbound'];this[_0x91cb('0xb')]={};this['variables']={};ami['on'](_0x91cb('0xc'),this[_0x91cb('0xd')][_0x91cb('0xe')](this));ami['on'](_0x91cb('0xf'),this[_0x91cb('0x10')][_0x91cb('0xe')](this));ami['on'](_0x91cb('0x11'),this[_0x91cb('0x12')][_0x91cb('0xe')](this));ami['on'](_0x91cb('0x13'),this['syncHangup'][_0x91cb('0xe')](this));}VoiceDialReport[_0x91cb('0x14')]['isNotNull']=function(_0x20e6e0){return _0x20e6e0!==null&&!_[_0x91cb('0x15')](_0x20e6e0);};VoiceDialReport[_0x91cb('0x14')][_0x91cb('0x16')]=function(_0x4a7d45,_0x4cc6ef,_0x4aae25){io['to'](_0x4a7d45)[_0x91cb('0x16')](_0x4cc6ef,_0x4aae25);};VoiceDialReport['prototype']['syncDialBegin']=function(_0x576369){try{if(this[_0x91cb('0x17')](_0x576369)){logger[_0x91cb('0x18')]('[%s][voiceDialReport][dialbegin]\x20event:',_0x576369[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x576369,{'showHidden':![],'depth':null}));if(this['channels'][_0x576369[_0x91cb('0x19')]]){_[_0x91cb('0x1b')](this[_0x91cb('0x9')][_0x576369[_0x91cb('0x19')]],{'starttime':moment()['format'](_0x91cb('0x1c')),'lastevent':_0x91cb('0x1d'),'interface':_0x576369['channel'][_0x91cb('0x1e')](0x0,_0x576369['channel']['lastIndexOf']('-')),'membername':_0x576369[_0x91cb('0x1f')][_0x91cb('0x1e')](_0x576369['channel']['lastIndexOf']('/')+0x1,_0x576369['channel'][_0x91cb('0x20')]('-'))},_[_0x91cb('0x21')](_0x576369,[_0x91cb('0x22'),_0x91cb('0x23')]));logger['info'](_0x91cb('0x24'),_0x576369[_0x91cb('0x19')],this[_0x91cb('0x9')][_0x576369['uniqueid']][_0x91cb('0x25')],this[_0x91cb('0x9')][_0x576369[_0x91cb('0x19')]][_0x91cb('0x26')]);logger[_0x91cb('0x18')](_0x91cb('0x27'),_0x576369[_0x91cb('0x19')],util[_0x91cb('0x1a')](this[_0x91cb('0x9')][_0x576369['uniqueid']],{'showHidden':![],'depth':null}));if(this['applications'][_0x576369[_0x91cb('0x19')]])_['merge'](this[_0x91cb('0x9')][_0x576369[_0x91cb('0x19')]],this[_0x91cb('0xb')][_0x576369['uniqueid']]);this[_0x91cb('0x16')]('voice:outbound',_0x91cb('0x28'),this[_0x91cb('0x9')][_0x576369[_0x91cb('0x19')]]);logger[_0x91cb('0x18')](_0x91cb('0x29'),_0x576369['uniqueid'],util[_0x91cb('0x1a')](this['channels'][_0x576369[_0x91cb('0x19')]],{'showHidden':![],'depth':null}));ami[_0x91cb('0x16')](_0x91cb('0x2a'),this['channels'][_0x576369[_0x91cb('0x19')]]);}}}catch(_0x146e1f){logger[_0x91cb('0x2b')](_0x91cb('0x2c'),_0x576369[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x146e1f,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x91cb('0x14')][_0x91cb('0x10')]=function(_0x1a10b1){try{if(this['isNotNull'](_0x1a10b1)){logger[_0x91cb('0x18')](_0x91cb('0x2d'),_0x1a10b1[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x1a10b1,{'showHidden':![],'depth':null}));if(this[_0x91cb('0x9')][_0x1a10b1['uniqueid']]){this[_0x91cb('0x9')][_0x1a10b1[_0x91cb('0x19')]][_0x91cb('0x2e')]=_0x1a10b1[_0x91cb('0x2e')];if(_0x1a10b1[_0x91cb('0x2e')]==='ANSWER'){this[_0x91cb('0x9')][_0x1a10b1['uniqueid']]['connectedlinenum']=_0x1a10b1['connectedlinenum'];this[_0x91cb('0x9')][_0x1a10b1['uniqueid']][_0x91cb('0x2f')]=_0x1a10b1['connectedlinename'];this['channels'][_0x1a10b1[_0x91cb('0x19')]][_0x91cb('0x30')]=moment()[_0x91cb('0x31')](_0x91cb('0x1c'));this[_0x91cb('0x9')][_0x1a10b1['uniqueid']][_0x91cb('0x32')]=_0x91cb('0x33');logger[_0x91cb('0x34')](_0x91cb('0x35'),_0x1a10b1['uniqueid'],_0x1a10b1['channel'][_0x91cb('0x1e')](_0x1a10b1[_0x91cb('0x1f')]['lastIndexOf']('/')+0x1,_0x1a10b1[_0x91cb('0x1f')][_0x91cb('0x20')]('-')));logger['debug'](_0x91cb('0x36'),_0x1a10b1[_0x91cb('0x19')],util['inspect'](this[_0x91cb('0x9')][_0x1a10b1['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x91cb('0x16')](_0x91cb('0x37'),this[_0x91cb('0x9')][_0x1a10b1[_0x91cb('0x19')]]);}logger[_0x91cb('0x18')](_0x91cb('0x38'),_0x1a10b1['uniqueid'],util[_0x91cb('0x1a')](this[_0x91cb('0x9')][_0x1a10b1['uniqueid']],{'showHidden':![],'depth':null}));this[_0x91cb('0x16')]('voice:outbound',_0x91cb('0x28'),this[_0x91cb('0x9')][_0x1a10b1[_0x91cb('0x19')]]);}}}catch(_0x174794){logger['error'](_0x91cb('0x39'),_0x1a10b1[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x174794,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x91cb('0x14')][_0x91cb('0x12')]=function(_0x2b8162){try{if(this[_0x91cb('0x17')](_0x2b8162)){logger[_0x91cb('0x18')](_0x91cb('0x3a'),_0x2b8162[_0x91cb('0x19')],util['inspect'](_0x2b8162,{'showHidden':![],'depth':null}));this[_0x91cb('0x3b')](_0x2b8162['uniqueid'],_[_0x91cb('0x3c')](_0x2b8162['variable'])[0x0],_0x2b8162[_0x91cb('0x3d')]);if(this['isNotNull'](_0x2b8162[_0x91cb('0x3e')])&&this[_0x91cb('0x17')](_0x2b8162[_0x91cb('0x3e')][_0x91cb('0x3f')])){if(_['isUndefined'](this[_0x91cb('0x9')][_0x2b8162[_0x91cb('0x19')]])){this['channels'][_0x2b8162[_0x91cb('0x19')]]={'routeId':_0x2b8162[_0x91cb('0x3d')],'variables':this[_0x91cb('0x40')][_0x2b8162[_0x91cb('0x19')]],'motionChannel':_0x91cb('0x41')};logger[_0x91cb('0x34')](_0x91cb('0x42'),_0x2b8162[_0x91cb('0x19')],_0x2b8162[_0x91cb('0x3e')]['outboundrouteid'],_[_0x91cb('0x3c')](_0x2b8162[_0x91cb('0x3e')])[0x0],_0x2b8162[_0x91cb('0x3d')]);logger[_0x91cb('0x18')](_0x91cb('0x43'),_0x2b8162[_0x91cb('0x19')],util[_0x91cb('0x1a')](this[_0x91cb('0x9')][_0x2b8162['uniqueid']],{'showHidden':![],'depth':null}));this[_0x91cb('0x16')](_0x91cb('0x44'),_0x91cb('0x28'),this[_0x91cb('0x9')][_0x2b8162['uniqueid']]);}}}}catch(_0x9dae06){logger[_0x91cb('0x2b')]('[%s][voiceDialReport][varset]',_0x2b8162[_0x91cb('0x19')],util['inspect'](_0x9dae06,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x91cb('0x14')]['addVariable']=function(_0x57e921,_0x52db35,_0x98245b){var _0xff3d11=[_0x91cb('0x45'),_0x91cb('0x46'),_0x91cb('0x47'),'rtpaudioqosjitterbridged','rtpaudioqosloss',_0x91cb('0x48'),_0x91cb('0x49'),_0x91cb('0x4a'),_0x91cb('0x4b'),'sipuri','bridgepeer','bridgepvtcallid',_0x91cb('0x4c'),'memberdynamic',_0x91cb('0x4d'),'memberlastcall',_0x91cb('0x25'),_0x91cb('0x4e'),_0x91cb('0x4f')];if(!_[_0x91cb('0x50')](_0x52db35)&&!_[_0x91cb('0x51')](_0xff3d11,_0x52db35)){if(_[_0x91cb('0x15')](this[_0x91cb('0x40')][_0x57e921])){this[_0x91cb('0x40')][_0x57e921]={};}this[_0x91cb('0x40')][_0x57e921][_0x52db35]=_0x98245b;}};VoiceDialReport[_0x91cb('0x14')][_0x91cb('0x52')]=function(_0x5752ed){try{if(this[_0x91cb('0x17')](_0x5752ed)){logger[_0x91cb('0x18')]('[%s][voiceDialReport][hangup]\x20event:',_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x5752ed,{'showHidden':![],'depth':null}));if(this['channels'][_0x5752ed[_0x91cb('0x19')]]){logger[_0x91cb('0x34')](_0x91cb('0x53'),_0x5752ed[_0x91cb('0x19')],_0x5752ed[_0x91cb('0x54')]);this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x55')]=moment()[_0x91cb('0x31')](_0x91cb('0x1c'));this[_0x91cb('0x9')][_0x5752ed['uniqueid']][_0x91cb('0x56')]=moment(this['channels'][_0x5752ed[_0x91cb('0x19')]]['endtime'])[_0x91cb('0x57')](this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]['starttime'],_0x91cb('0x58'));this[_0x91cb('0x9')][_0x5752ed['uniqueid']][_0x91cb('0x32')]=_0x91cb('0x59');this[_0x91cb('0xa')][_0x91cb('0x5a')]+=0x1;if(this['channels'][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x30')]){this[_0x91cb('0xa')][_0x91cb('0x5b')]+=0x1;this['channels'][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x5c')]=moment(this['channels'][_0x5752ed['uniqueid']][_0x91cb('0x30')])['diff'](this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]['starttime'],'seconds');this[_0x91cb('0x9')][_0x5752ed['uniqueid']][_0x91cb('0x5d')]=moment(this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]['endtime'])[_0x91cb('0x57')](this['channels'][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x30')],_0x91cb('0x58'));this[_0x91cb('0xa')]['sumHoldTime']+=this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x5c')]||0x0;this[_0x91cb('0xa')][_0x91cb('0x5e')]+=this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]][_0x91cb('0x5d')];}this[_0x91cb('0xa')][_0x91cb('0x5f')]+=this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]['duration'];logger[_0x91cb('0x18')](_0x91cb('0x60'),_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]],{'showHidden':![],'depth':null}));ami[_0x91cb('0x16')]('custom:voiceDialReport',this[_0x91cb('0x9')][_0x5752ed['uniqueid']]);logger[_0x91cb('0x18')](_0x91cb('0x61'),_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](this['channels'][_0x5752ed[_0x91cb('0x19')]],{'showHidden':![],'depth':null}));ami[_0x91cb('0x16')](_0x91cb('0x62'),this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]);logger[_0x91cb('0x18')]('[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:',_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]],{'showHidden':![],'depth':null}));this[_0x91cb('0x16')](_0x91cb('0x44'),_0x91cb('0x63'),this[_0x91cb('0xa')]);logger[_0x91cb('0x34')](_0x91cb('0x64'),JSON[_0x91cb('0x65')](this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]));logger[_0x91cb('0x18')](_0x91cb('0x66'),_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](this['channels'][_0x5752ed[_0x91cb('0x19')]],{'showHidden':![],'depth':null}));this[_0x91cb('0x16')]('voice:outbound',_0x91cb('0x67'),this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x19')]]);delete this['channels'][_0x5752ed[_0x91cb('0x19')]];}else if(this[_0x91cb('0x9')][_0x5752ed['linkedid']]){this['channels'][_0x5752ed[_0x91cb('0x68')]]['uniqueid']=this[_0x91cb('0x9')][_0x5752ed[_0x91cb('0x68')]]['destuniqueid'];}if(this[_0x91cb('0x40')][_0x5752ed['uniqueid']]){delete this[_0x91cb('0x40')][_0x5752ed[_0x91cb('0x19')]];}}}catch(_0x4f827e){logger['error'](_0x91cb('0x69'),_0x5752ed[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x4f827e,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x91cb('0x6a')]=function(_0x23a458){try{if(this[_0x91cb('0x17')](_0x23a458)){logger[_0x91cb('0x18')]('[%s][voiceDialReport][newexten]\x20event:',_0x23a458[_0x91cb('0x19')],util['inspect'](_0x23a458,{'showHidden':![],'depth':null}));if(_0x23a458[_0x91cb('0x6b')][_0x91cb('0x6c')]()===_0x91cb('0x6d')){_0x23a458[_0x91cb('0x6e')]=(_0x23a458['appdata']||_0x23a458['applicationdata'])[_0x91cb('0x6c')]();if(_['startsWith'](_0x23a458[_0x91cb('0x6e')],_0x91cb('0x6f'))){if(_[_0x91cb('0x15')](this[_0x91cb('0xb')][_0x23a458[_0x91cb('0x19')]]))this[_0x91cb('0xb')][_0x23a458[_0x91cb('0x19')]]={};logger['info'](_0x91cb('0x70'),_0x23a458[_0x91cb('0x19')],_0x23a458['application'],_0x23a458[_0x91cb('0x6e')]);var _0x4d5862=_0x23a458[_0x91cb('0x6e')][_0x91cb('0x71')]('=');var _0x33fec6=_0x4d5862[0x0][_0x91cb('0x72')](/cdr\((.*)\)/);if(_0x33fec6)this[_0x91cb('0xb')][_0x23a458[_0x91cb('0x19')]][_0x33fec6[0x1]]=_0x4d5862[0x1];}}}}catch(_0x1459c4){logger[_0x91cb('0x2b')](_0x91cb('0x73'),_0x23a458[_0x91cb('0x19')],util[_0x91cb('0x1a')](_0x1459c4,{'showHidden':![],'depth':null}));}};module[_0x91cb('0x74')]=VoiceDialReport;