502830ffd81a281de43dc60eee6f0a5e1156bc40
[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 _0xea91=['[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','inspect','merge','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','event','privilege','info','membername','interface','voice:outbound','voice_outbound_channel:save','[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:','error','[%s][voiceDialReport][dialbegin]','dialstatus','ANSWER','connectedlinenum','connectedlinename','lastevent','connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','custom:dialconnect','[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:','[%s][voiceDialReport][dialend]','syncVarSet','[%s][voiceDialReport][varset]\x20event:','addVariable','keys','variable','value','outboundrouteid','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged','rtpaudioqosrttbridged','sipuri','bridgepeer','bridgepvtcallid','memberdynamic','memberinterface','memberlastcall','memberpenalty','memberrealtime','includes','[%s][voiceDialReport][hangup]\x20event:','endtime','duration','starttime','complete','total','answertime','answered','seconds','diff','sumHoldTime','holdtime','sumBillable','billableseconds','sumDuration','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','[%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','voice_outbound_channel:remove','linkedid','exports','ioredis','../../../config/environment','../../../config/logger','ami','../ami','redis','defaults','socket.io-emitter','channels','outbound','variables','dialbegin','syncDialBegin','bind','dialend','syncDialEnd','varset','hangup','syncHangup','isUndefined','prototype','emit','isNotNull','debug'];(function(_0x23c679,_0x146416){var _0x370759=function(_0x1fb38d){while(--_0x1fb38d){_0x23c679['push'](_0x23c679['shift']());}};_0x370759(++_0x146416);}(_0xea91,0x180));var _0x1ea9=function(_0x291830,_0x386bb0){_0x291830=_0x291830-0x0;var _0x4713e2=_0xea91[_0x291830];return _0x4713e2;};'use strict';var _=require('lodash');var moment=require('moment');var util=require('util');var Redis=require(_0x1ea9('0x0'));var config=require(_0x1ea9('0x1'));var logger=require(_0x1ea9('0x2'))(_0x1ea9('0x3'));var ami=require(_0x1ea9('0x4'));config[_0x1ea9('0x5')]=_[_0x1ea9('0x6')](config[_0x1ea9('0x5')],{'host':'localhost','port':0x18eb});var io=require(_0x1ea9('0x7'))(new Redis(config['redis']));function VoiceDialReport(_0x713d83){this[_0x1ea9('0x8')]=_0x713d83['outboundChannels'];this[_0x1ea9('0x9')]=_0x713d83[_0x1ea9('0x9')];this[_0x1ea9('0xa')]={};ami['on'](_0x1ea9('0xb'),this[_0x1ea9('0xc')][_0x1ea9('0xd')](this));ami['on'](_0x1ea9('0xe'),this[_0x1ea9('0xf')]['bind'](this));ami['on'](_0x1ea9('0x10'),this['syncVarSet']['bind'](this));ami['on'](_0x1ea9('0x11'),this[_0x1ea9('0x12')]['bind'](this));}VoiceDialReport['prototype']['isNotNull']=function(_0x474936){return _0x474936!==null&&!_[_0x1ea9('0x13')](_0x474936);};VoiceDialReport[_0x1ea9('0x14')][_0x1ea9('0x15')]=function(_0x56b83d,_0x1eecf1,_0x436fd0){io['to'](_0x56b83d)[_0x1ea9('0x15')](_0x1eecf1,_0x436fd0);};VoiceDialReport[_0x1ea9('0x14')][_0x1ea9('0xc')]=function(_0x56ea36){try{if(this[_0x1ea9('0x16')](_0x56ea36)){logger[_0x1ea9('0x17')](_0x1ea9('0x18'),_0x56ea36[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](_0x56ea36,{'showHidden':![],'depth':null}));if(this[_0x1ea9('0x8')][_0x56ea36[_0x1ea9('0x19')]]){_[_0x1ea9('0x1b')](this[_0x1ea9('0x8')][_0x56ea36[_0x1ea9('0x19')]],{'starttime':moment()[_0x1ea9('0x1c')](_0x1ea9('0x1d')),'lastevent':_0x1ea9('0x1e'),'interface':_0x56ea36['channel']['substring'](0x0,_0x56ea36['channel']['lastIndexOf']('-')),'membername':_0x56ea36[_0x1ea9('0x1f')][_0x1ea9('0x20')](_0x56ea36[_0x1ea9('0x1f')][_0x1ea9('0x21')]('/')+0x1,_0x56ea36[_0x1ea9('0x1f')]['lastIndexOf']('-'))},_[_0x1ea9('0x22')](_0x56ea36,[_0x1ea9('0x23'),_0x1ea9('0x24')]));logger[_0x1ea9('0x25')]('[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called',_0x56ea36[_0x1ea9('0x19')],this['channels'][_0x56ea36['uniqueid']][_0x1ea9('0x26')],this[_0x1ea9('0x8')][_0x56ea36[_0x1ea9('0x19')]][_0x1ea9('0x27')]);logger[_0x1ea9('0x17')]('[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:',_0x56ea36[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0x56ea36[_0x1ea9('0x19')]],{'showHidden':![],'depth':null}));this[_0x1ea9('0x15')](_0x1ea9('0x28'),_0x1ea9('0x29'),this['channels'][_0x56ea36['uniqueid']]);logger['debug'](_0x1ea9('0x2a'),_0x56ea36[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0x56ea36['uniqueid']],{'showHidden':![],'depth':null}));ami['emit']('custom:dialbegin',this[_0x1ea9('0x8')][_0x56ea36[_0x1ea9('0x19')]]);}}}catch(_0x25f086){logger[_0x1ea9('0x2b')](_0x1ea9('0x2c'),_0x56ea36['uniqueid'],util['inspect'](_0x25f086,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x1ea9('0x14')][_0x1ea9('0xf')]=function(_0x20542a){try{if(this[_0x1ea9('0x16')](_0x20542a)){logger['debug']('[%s][voiceDialReport][dialend]\x20event:',_0x20542a[_0x1ea9('0x19')],util['inspect'](_0x20542a,{'showHidden':![],'depth':null}));if(this[_0x1ea9('0x8')][_0x20542a[_0x1ea9('0x19')]]){this[_0x1ea9('0x8')][_0x20542a['uniqueid']][_0x1ea9('0x2d')]=_0x20542a['dialstatus'];if(_0x20542a[_0x1ea9('0x2d')]===_0x1ea9('0x2e')){this[_0x1ea9('0x8')][_0x20542a[_0x1ea9('0x19')]]['connectedlinenum']=_0x20542a[_0x1ea9('0x2f')];this[_0x1ea9('0x8')][_0x20542a[_0x1ea9('0x19')]][_0x1ea9('0x30')]=_0x20542a[_0x1ea9('0x30')];this[_0x1ea9('0x8')][_0x20542a['uniqueid']]['answertime']=moment()['format'](_0x1ea9('0x1d'));this[_0x1ea9('0x8')][_0x20542a[_0x1ea9('0x19')]][_0x1ea9('0x31')]=_0x1ea9('0x32');logger['info']('[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect',_0x20542a[_0x1ea9('0x19')],_0x20542a[_0x1ea9('0x1f')][_0x1ea9('0x20')](_0x20542a[_0x1ea9('0x1f')][_0x1ea9('0x21')]('/')+0x1,_0x20542a['channel'][_0x1ea9('0x21')]('-')));logger[_0x1ea9('0x17')](_0x1ea9('0x33'),_0x20542a[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0x20542a['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x1ea9('0x15')](_0x1ea9('0x34'),this['channels'][_0x20542a[_0x1ea9('0x19')]]);}logger[_0x1ea9('0x17')](_0x1ea9('0x35'),_0x20542a['uniqueid'],util[_0x1ea9('0x1a')](this['channels'][_0x20542a[_0x1ea9('0x19')]],{'showHidden':![],'depth':null}));this[_0x1ea9('0x15')](_0x1ea9('0x28'),_0x1ea9('0x29'),this[_0x1ea9('0x8')][_0x20542a['uniqueid']]);}}}catch(_0x3100ee){logger[_0x1ea9('0x2b')](_0x1ea9('0x36'),_0x20542a[_0x1ea9('0x19')],util['inspect'](_0x3100ee,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x1ea9('0x14')][_0x1ea9('0x37')]=function(_0x3c6a1e){try{if(this[_0x1ea9('0x16')](_0x3c6a1e)){logger[_0x1ea9('0x17')](_0x1ea9('0x38'),_0x3c6a1e[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](_0x3c6a1e,{'showHidden':![],'depth':null}));this[_0x1ea9('0x39')](_0x3c6a1e[_0x1ea9('0x19')],_[_0x1ea9('0x3a')](_0x3c6a1e[_0x1ea9('0x3b')])[0x0],_0x3c6a1e[_0x1ea9('0x3c')]);if(this[_0x1ea9('0x16')](_0x3c6a1e[_0x1ea9('0x3b')])&&this[_0x1ea9('0x16')](_0x3c6a1e[_0x1ea9('0x3b')][_0x1ea9('0x3d')])){if(_['isUndefined'](this[_0x1ea9('0x8')][_0x3c6a1e[_0x1ea9('0x19')]])){this['channels'][_0x3c6a1e['uniqueid']]={'routeId':_0x3c6a1e['value'],'variables':this[_0x1ea9('0xa')][_0x3c6a1e[_0x1ea9('0x19')]]};logger[_0x1ea9('0x25')]('[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s',_0x3c6a1e[_0x1ea9('0x19')],_0x3c6a1e[_0x1ea9('0x3b')]['outboundrouteid'],_['keys'](_0x3c6a1e[_0x1ea9('0x3b')])[0x0],_0x3c6a1e['value']);logger['debug']('[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:',_0x3c6a1e['uniqueid'],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0x3c6a1e[_0x1ea9('0x19')]],{'showHidden':![],'depth':null}));this[_0x1ea9('0x15')]('voice:outbound',_0x1ea9('0x29'),this['channels'][_0x3c6a1e[_0x1ea9('0x19')]]);}}}}catch(_0x42a889){logger['error'](_0x1ea9('0x3e'),_0x3c6a1e[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](_0x42a889,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x1ea9('0x14')]['addVariable']=function(_0x1caff7,_0x4e674d,_0x139e91){var _0x504740=[_0x1ea9('0x3f'),_0x1ea9('0x40'),_0x1ea9('0x41'),_0x1ea9('0x42'),'rtpaudioqosloss',_0x1ea9('0x43'),'rtpaudioqosrtt',_0x1ea9('0x44'),'sipcallid',_0x1ea9('0x45'),_0x1ea9('0x46'),_0x1ea9('0x47'),'membercalls',_0x1ea9('0x48'),_0x1ea9('0x49'),_0x1ea9('0x4a'),_0x1ea9('0x26'),_0x1ea9('0x4b'),_0x1ea9('0x4c')];if(!_['isNil'](_0x4e674d)&&!_[_0x1ea9('0x4d')](_0x504740,_0x4e674d)){if(_[_0x1ea9('0x13')](this[_0x1ea9('0xa')][_0x1caff7])){this[_0x1ea9('0xa')][_0x1caff7]={};}this[_0x1ea9('0xa')][_0x1caff7][_0x4e674d]=_0x139e91;}};VoiceDialReport[_0x1ea9('0x14')][_0x1ea9('0x12')]=function(_0xf2b97e){try{if(this[_0x1ea9('0x16')](_0xf2b97e)){logger[_0x1ea9('0x17')](_0x1ea9('0x4e'),_0xf2b97e['uniqueid'],util[_0x1ea9('0x1a')](_0xf2b97e,{'showHidden':![],'depth':null}));if(this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]]){logger[_0x1ea9('0x25')]('[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete',_0xf2b97e[_0x1ea9('0x19')],_0xf2b97e['cause-txt']);this[_0x1ea9('0x8')][_0xf2b97e['uniqueid']][_0x1ea9('0x4f')]=moment()[_0x1ea9('0x1c')](_0x1ea9('0x1d'));this['channels'][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x50')]=moment(this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x4f')])['diff'](this[_0x1ea9('0x8')][_0xf2b97e['uniqueid']][_0x1ea9('0x51')],'seconds');this['channels'][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x31')]=_0x1ea9('0x52');this['outbound'][_0x1ea9('0x53')]+=0x1;if(this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x54')]){this[_0x1ea9('0x9')][_0x1ea9('0x55')]+=0x1;this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]]['holdtime']=moment(this['channels'][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x54')])['diff'](this['channels'][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x51')],_0x1ea9('0x56'));this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]]['billableseconds']=moment(this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]]['endtime'])[_0x1ea9('0x57')](this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x54')],_0x1ea9('0x56'));this['outbound'][_0x1ea9('0x58')]+=this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x59')]||0x0;this['outbound'][_0x1ea9('0x5a')]+=this['channels'][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x5b')];}this[_0x1ea9('0x9')][_0x1ea9('0x5c')]+=this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]][_0x1ea9('0x50')];logger[_0x1ea9('0x17')](_0x1ea9('0x5d'),_0xf2b97e[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0xf2b97e['uniqueid']],{'showHidden':![],'depth':null}));ami['emit']('custom:voiceDialReport',this['channels'][_0xf2b97e['uniqueid']]);logger['debug'](_0x1ea9('0x5e'),_0xf2b97e[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]],{'showHidden':![],'depth':null}));ami['emit']('custom:dialend',this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]]);logger[_0x1ea9('0x17')](_0x1ea9('0x5f'),_0xf2b97e[_0x1ea9('0x19')],util['inspect'](this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]],{'showHidden':![],'depth':null}));this[_0x1ea9('0x15')](_0x1ea9('0x28'),_0x1ea9('0x60'),this['outbound']);logger[_0x1ea9('0x25')](_0x1ea9('0x61'),JSON[_0x1ea9('0x62')](this[_0x1ea9('0x8')][_0xf2b97e['uniqueid']]));logger[_0x1ea9('0x17')]('[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:',_0xf2b97e[_0x1ea9('0x19')],util['inspect'](this['channels'][_0xf2b97e['uniqueid']],{'showHidden':![],'depth':null}));this[_0x1ea9('0x15')](_0x1ea9('0x28'),_0x1ea9('0x63'),this['channels'][_0xf2b97e[_0x1ea9('0x19')]]);delete this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x19')]];}else if(this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x64')]]){this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x64')]][_0x1ea9('0x19')]=this[_0x1ea9('0x8')][_0xf2b97e[_0x1ea9('0x64')]]['destuniqueid'];}if(this[_0x1ea9('0xa')][_0xf2b97e[_0x1ea9('0x19')]]){delete this['variables'][_0xf2b97e['uniqueid']];}}}catch(_0x13818f){logger[_0x1ea9('0x2b')]('[%s][voiceDialReport][hangup]',_0xf2b97e[_0x1ea9('0x19')],util[_0x1ea9('0x1a')](_0x13818f,{'showHidden':![],'depth':null}));}};module[_0x1ea9('0x65')]=VoiceDialReport;