Built motion from commit (unavailable).|2.5.30
[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 _0x4ec4=['memberlastcall','includes','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','duration','diff','seconds','lastevent','complete','answered','holdtime','sumHoldTime','sumBillable','billableseconds','sumDuration','custom:voiceDialReport','[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:','custom:dialend','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','voice_outbound:save','stringify','voice_outbound_channel:remove','linkedid','destuniqueid','exports','lodash','moment','util','../../../config/environment','../../../config/logger','ami','../ami','redis','defaults','localhost','socket.io-emitter','channels','outboundChannels','outbound','variables','syncDialBegin','bind','dialend','varset','hangup','syncHangup','prototype','isNotNull','isUndefined','emit','debug','[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','membername','interface','[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:','inspect','voice:outbound','voice_outbound_channel:save','custom:dialbegin','error','[%s][voiceDialReport][dialbegin]','syncDialEnd','[%s][voiceDialReport][dialend]\x20event:','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','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]','syncVarSet','addVariable','keys','variable','value','outboundrouteid','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipuri','bridgepeer','bridgepvtcallid','memberdynamic','memberinterface'];(function(_0x30f558,_0x16548e){var _0x5750b1=function(_0x3fe029){while(--_0x3fe029){_0x30f558['push'](_0x30f558['shift']());}};_0x5750b1(++_0x16548e);}(_0x4ec4,0x159));var _0x44ec=function(_0x174f7e,_0x501f15){_0x174f7e=_0x174f7e-0x0;var _0x3a09fa=_0x4ec4[_0x174f7e];return _0x3a09fa;};'use strict';var _=require(_0x44ec('0x0'));var moment=require(_0x44ec('0x1'));var util=require(_0x44ec('0x2'));var Redis=require('ioredis');var config=require(_0x44ec('0x3'));var logger=require(_0x44ec('0x4'))(_0x44ec('0x5'));var ami=require(_0x44ec('0x6'));config[_0x44ec('0x7')]=_[_0x44ec('0x8')](config[_0x44ec('0x7')],{'host':_0x44ec('0x9'),'port':0x18eb});var io=require(_0x44ec('0xa'))(new Redis(config['redis']));function VoiceDialReport(_0x72491e){this[_0x44ec('0xb')]=_0x72491e[_0x44ec('0xc')];this['outbound']=_0x72491e[_0x44ec('0xd')];this[_0x44ec('0xe')]={};ami['on']('dialbegin',this[_0x44ec('0xf')][_0x44ec('0x10')](this));ami['on'](_0x44ec('0x11'),this['syncDialEnd']['bind'](this));ami['on'](_0x44ec('0x12'),this['syncVarSet'][_0x44ec('0x10')](this));ami['on'](_0x44ec('0x13'),this[_0x44ec('0x14')][_0x44ec('0x10')](this));}VoiceDialReport[_0x44ec('0x15')][_0x44ec('0x16')]=function(_0x36aca9){return _0x36aca9!==null&&!_[_0x44ec('0x17')](_0x36aca9);};VoiceDialReport['prototype'][_0x44ec('0x18')]=function(_0x3bfcde,_0x25545c,_0xbda3b1){io['to'](_0x3bfcde)[_0x44ec('0x18')](_0x25545c,_0xbda3b1);};VoiceDialReport[_0x44ec('0x15')][_0x44ec('0xf')]=function(_0x445a0e){try{if(this[_0x44ec('0x16')](_0x445a0e)){logger[_0x44ec('0x19')](_0x44ec('0x1a'),_0x445a0e[_0x44ec('0x1b')],util['inspect'](_0x445a0e,{'showHidden':![],'depth':null}));if(this[_0x44ec('0xb')][_0x445a0e['uniqueid']]){_['merge'](this['channels'][_0x445a0e['uniqueid']],{'starttime':moment()[_0x44ec('0x1c')](_0x44ec('0x1d')),'lastevent':_0x44ec('0x1e'),'interface':_0x445a0e[_0x44ec('0x1f')][_0x44ec('0x20')](0x0,_0x445a0e[_0x44ec('0x1f')][_0x44ec('0x21')]('-')),'membername':_0x445a0e[_0x44ec('0x1f')]['substring'](_0x445a0e[_0x44ec('0x1f')][_0x44ec('0x21')]('/')+0x1,_0x445a0e[_0x44ec('0x1f')][_0x44ec('0x21')]('-'))},_[_0x44ec('0x22')](_0x445a0e,['event','privilege']));logger['info']('[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called',_0x445a0e[_0x44ec('0x1b')],this[_0x44ec('0xb')][_0x445a0e['uniqueid']][_0x44ec('0x23')],this['channels'][_0x445a0e['uniqueid']][_0x44ec('0x24')]);logger[_0x44ec('0x19')](_0x44ec('0x25'),_0x445a0e[_0x44ec('0x1b')],util[_0x44ec('0x26')](this['channels'][_0x445a0e[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));this['emit'](_0x44ec('0x27'),_0x44ec('0x28'),this[_0x44ec('0xb')][_0x445a0e[_0x44ec('0x1b')]]);logger[_0x44ec('0x19')]('[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:',_0x445a0e[_0x44ec('0x1b')],util['inspect'](this[_0x44ec('0xb')][_0x445a0e[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));ami[_0x44ec('0x18')](_0x44ec('0x29'),this['channels'][_0x445a0e['uniqueid']]);}}}catch(_0xdecc4a){logger[_0x44ec('0x2a')](_0x44ec('0x2b'),_0x445a0e[_0x44ec('0x1b')],util['inspect'](_0xdecc4a,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x44ec('0x15')][_0x44ec('0x2c')]=function(_0x2731d0){try{if(this[_0x44ec('0x16')](_0x2731d0)){logger[_0x44ec('0x19')](_0x44ec('0x2d'),_0x2731d0['uniqueid'],util[_0x44ec('0x26')](_0x2731d0,{'showHidden':![],'depth':null}));if(this[_0x44ec('0xb')][_0x2731d0[_0x44ec('0x1b')]]){this[_0x44ec('0xb')][_0x2731d0['uniqueid']][_0x44ec('0x2e')]=_0x2731d0[_0x44ec('0x2e')];if(_0x2731d0[_0x44ec('0x2e')]===_0x44ec('0x2f')){this[_0x44ec('0xb')][_0x2731d0[_0x44ec('0x1b')]][_0x44ec('0x30')]=_0x2731d0[_0x44ec('0x30')];this[_0x44ec('0xb')][_0x2731d0[_0x44ec('0x1b')]][_0x44ec('0x31')]=_0x2731d0[_0x44ec('0x31')];this[_0x44ec('0xb')][_0x2731d0['uniqueid']][_0x44ec('0x32')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');this[_0x44ec('0xb')][_0x2731d0['uniqueid']]['lastevent']=_0x44ec('0x33');logger[_0x44ec('0x34')](_0x44ec('0x35'),_0x2731d0[_0x44ec('0x1b')],_0x2731d0[_0x44ec('0x1f')][_0x44ec('0x20')](_0x2731d0[_0x44ec('0x1f')][_0x44ec('0x21')]('/')+0x1,_0x2731d0[_0x44ec('0x1f')][_0x44ec('0x21')]('-')));logger['debug'](_0x44ec('0x36'),_0x2731d0['uniqueid'],util['inspect'](this[_0x44ec('0xb')][_0x2731d0['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x44ec('0x18')](_0x44ec('0x37'),this[_0x44ec('0xb')][_0x2731d0[_0x44ec('0x1b')]]);}logger[_0x44ec('0x19')](_0x44ec('0x38'),_0x2731d0['uniqueid'],util[_0x44ec('0x26')](this['channels'][_0x2731d0[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));this['emit']('voice:outbound',_0x44ec('0x28'),this[_0x44ec('0xb')][_0x2731d0[_0x44ec('0x1b')]]);}}}catch(_0x1d4d73){logger[_0x44ec('0x2a')](_0x44ec('0x39'),_0x2731d0['uniqueid'],util[_0x44ec('0x26')](_0x1d4d73,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x44ec('0x3a')]=function(_0x5548e6){try{if(this['isNotNull'](_0x5548e6)){logger[_0x44ec('0x19')]('[%s][voiceDialReport][varset]\x20event:',_0x5548e6[_0x44ec('0x1b')],util['inspect'](_0x5548e6,{'showHidden':![],'depth':null}));this[_0x44ec('0x3b')](_0x5548e6[_0x44ec('0x1b')],_[_0x44ec('0x3c')](_0x5548e6[_0x44ec('0x3d')])[0x0],_0x5548e6[_0x44ec('0x3e')]);if(this[_0x44ec('0x16')](_0x5548e6['variable'])&&this[_0x44ec('0x16')](_0x5548e6['variable'][_0x44ec('0x3f')])){if(_[_0x44ec('0x17')](this[_0x44ec('0xb')][_0x5548e6[_0x44ec('0x1b')]])){this[_0x44ec('0xb')][_0x5548e6['uniqueid']]={'routeId':_0x5548e6[_0x44ec('0x3e')],'variables':this[_0x44ec('0xe')][_0x5548e6[_0x44ec('0x1b')]]};logger['info'](_0x44ec('0x40'),_0x5548e6[_0x44ec('0x1b')],_0x5548e6[_0x44ec('0x3d')][_0x44ec('0x3f')],_['keys'](_0x5548e6[_0x44ec('0x3d')])[0x0],_0x5548e6[_0x44ec('0x3e')]);logger['debug']('[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:',_0x5548e6[_0x44ec('0x1b')],util['inspect'](this[_0x44ec('0xb')][_0x5548e6['uniqueid']],{'showHidden':![],'depth':null}));this[_0x44ec('0x18')]('voice:outbound','voice_outbound_channel:save',this[_0x44ec('0xb')][_0x5548e6['uniqueid']]);}}}}catch(_0x8d3436){logger['error'](_0x44ec('0x41'),_0x5548e6[_0x44ec('0x1b')],util['inspect'](_0x8d3436,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x44ec('0x15')]['addVariable']=function(_0x1a11fa,_0x503e96,_0xa77ceb){var _0x10001f=[_0x44ec('0x42'),_0x44ec('0x43'),_0x44ec('0x44'),_0x44ec('0x45'),_0x44ec('0x46'),_0x44ec('0x47'),_0x44ec('0x48'),_0x44ec('0x49'),'sipcallid',_0x44ec('0x4a'),_0x44ec('0x4b'),_0x44ec('0x4c'),'membercalls',_0x44ec('0x4d'),_0x44ec('0x4e'),_0x44ec('0x4f'),_0x44ec('0x23'),'memberpenalty','memberrealtime'];if(!_['isNil'](_0x503e96)&&!_[_0x44ec('0x50')](_0x10001f,_0x503e96)){if(_[_0x44ec('0x17')](this[_0x44ec('0xe')][_0x1a11fa])){this[_0x44ec('0xe')][_0x1a11fa]={};}this[_0x44ec('0xe')][_0x1a11fa][_0x503e96]=_0xa77ceb;}};VoiceDialReport['prototype'][_0x44ec('0x14')]=function(_0x4fe254){try{if(this[_0x44ec('0x16')](_0x4fe254)){logger[_0x44ec('0x19')](_0x44ec('0x51'),_0x4fe254[_0x44ec('0x1b')],util[_0x44ec('0x26')](_0x4fe254,{'showHidden':![],'depth':null}));if(this['channels'][_0x4fe254['uniqueid']]){logger[_0x44ec('0x34')](_0x44ec('0x52'),_0x4fe254[_0x44ec('0x1b')],_0x4fe254[_0x44ec('0x53')]);this['channels'][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x54')]=moment()['format'](_0x44ec('0x1d'));this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x55')]=moment(this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x54')])[_0x44ec('0x56')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]]['starttime'],_0x44ec('0x57'));this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x58')]=_0x44ec('0x59');this['outbound']['total']+=0x1;if(this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x32')]){this[_0x44ec('0xd')][_0x44ec('0x5a')]+=0x1;this['channels'][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x5b')]=moment(this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x32')])[_0x44ec('0x56')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]]['starttime'],_0x44ec('0x57'));this['channels'][_0x4fe254[_0x44ec('0x1b')]]['billableseconds']=moment(this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x54')])[_0x44ec('0x56')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x32')],'seconds');this[_0x44ec('0xd')][_0x44ec('0x5c')]+=this['channels'][_0x4fe254[_0x44ec('0x1b')]]['holdtime']||0x0;this[_0x44ec('0xd')][_0x44ec('0x5d')]+=this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]][_0x44ec('0x5e')];}this['outbound'][_0x44ec('0x5f')]+=this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]]['duration'];logger[_0x44ec('0x19')]('[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:',_0x4fe254[_0x44ec('0x1b')],util[_0x44ec('0x26')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));ami['emit'](_0x44ec('0x60'),this[_0x44ec('0xb')][_0x4fe254['uniqueid']]);logger[_0x44ec('0x19')](_0x44ec('0x61'),_0x4fe254[_0x44ec('0x1b')],util[_0x44ec('0x26')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));ami[_0x44ec('0x18')](_0x44ec('0x62'),this[_0x44ec('0xb')][_0x4fe254['uniqueid']]);logger['debug'](_0x44ec('0x63'),_0x4fe254['uniqueid'],util[_0x44ec('0x26')](this['channels'][_0x4fe254[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));this[_0x44ec('0x18')](_0x44ec('0x27'),_0x44ec('0x64'),this[_0x44ec('0xd')]);logger[_0x44ec('0x34')]('[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event',JSON[_0x44ec('0x65')](this['channels'][_0x4fe254[_0x44ec('0x1b')]]));logger['debug']('[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:',_0x4fe254['uniqueid'],util[_0x44ec('0x26')](this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]],{'showHidden':![],'depth':null}));this[_0x44ec('0x18')]('voice:outbound',_0x44ec('0x66'),this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x1b')]]);delete this[_0x44ec('0xb')][_0x4fe254['uniqueid']];}else if(this[_0x44ec('0xb')][_0x4fe254[_0x44ec('0x67')]]){this['channels'][_0x4fe254[_0x44ec('0x67')]]['uniqueid']=this[_0x44ec('0xb')][_0x4fe254['linkedid']][_0x44ec('0x68')];}if(this[_0x44ec('0xe')][_0x4fe254[_0x44ec('0x1b')]]){delete this[_0x44ec('0xe')][_0x4fe254[_0x44ec('0x1b')]];}}}catch(_0x27e62d){logger[_0x44ec('0x2a')]('[%s][voiceDialReport][hangup]',_0x4fe254[_0x44ec('0x1b')],util[_0x44ec('0x26')](_0x27e62d,{'showHidden':![],'depth':null}));}};module[_0x44ec('0x69')]=VoiceDialReport;