62f3b814db356c6aa6cd5e7950b55933193d416c
[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 _0xb477=['[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event','stringify','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:','voice_outbound_channel:remove','linkedid','destuniqueid','variables','exports','lodash','moment','util','ioredis','../../../config/environment','../../../config/logger','../ami','redis','defaults','localhost','socket.io-emitter','outboundChannels','outbound','syncDialBegin','bind','syncDialEnd','varset','syncVarSet','hangup','syncHangup','prototype','isUndefined','emit','isNotNull','debug','[%s][voiceDialReport][dialbegin]\x20event:','inspect','channels','uniqueid','YYYY-MM-DD\x20HH:mm:ss','channel','substring','lastIndexOf','omit','privilege','info','[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called','membername','interface','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','format','lastevent','connect','[%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','variable','value','[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s','[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:','[%s][voiceDialReport][varset]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosloss','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid','sipuri','bridgepeer','membercalls','memberdynamic','memberinterface','memberrealtime','isNil','includes','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','endtime','duration','diff','starttime','seconds','total','answered','holdtime','billableseconds','sumHoldTime','sumBillable','sumDuration','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','custom:voiceDialReport'];(function(_0x172ed7,_0x3d08fd){var _0xfa8f61=function(_0xe07a21){while(--_0xe07a21){_0x172ed7['push'](_0x172ed7['shift']());}};_0xfa8f61(++_0x3d08fd);}(_0xb477,0x1be));var _0x7b47=function(_0x334841,_0x2bbc4c){_0x334841=_0x334841-0x0;var _0x5beb4b=_0xb477[_0x334841];return _0x5beb4b;};'use strict';var _=require(_0x7b47('0x0'));var moment=require(_0x7b47('0x1'));var util=require(_0x7b47('0x2'));var Redis=require(_0x7b47('0x3'));var config=require(_0x7b47('0x4'));var logger=require(_0x7b47('0x5'))('ami');var ami=require(_0x7b47('0x6'));config[_0x7b47('0x7')]=_[_0x7b47('0x8')](config[_0x7b47('0x7')],{'host':_0x7b47('0x9'),'port':0x18eb});var io=require(_0x7b47('0xa'))(new Redis(config['redis']));function VoiceDialReport(_0x3f499c){this['channels']=_0x3f499c[_0x7b47('0xb')];this['outbound']=_0x3f499c[_0x7b47('0xc')];this['variables']={};ami['on']('dialbegin',this[_0x7b47('0xd')][_0x7b47('0xe')](this));ami['on']('dialend',this[_0x7b47('0xf')]['bind'](this));ami['on'](_0x7b47('0x10'),this[_0x7b47('0x11')][_0x7b47('0xe')](this));ami['on'](_0x7b47('0x12'),this[_0x7b47('0x13')]['bind'](this));}VoiceDialReport[_0x7b47('0x14')]['isNotNull']=function(_0x54ef4d){return _0x54ef4d!==null&&!_[_0x7b47('0x15')](_0x54ef4d);};VoiceDialReport[_0x7b47('0x14')]['emit']=function(_0x47e52e,_0x46c44c,_0x31c182){io['to'](_0x47e52e)[_0x7b47('0x16')](_0x46c44c,_0x31c182);};VoiceDialReport[_0x7b47('0x14')]['syncDialBegin']=function(_0x2f6144){try{if(this[_0x7b47('0x17')](_0x2f6144)){logger[_0x7b47('0x18')](_0x7b47('0x19'),_0x2f6144['uniqueid'],util[_0x7b47('0x1a')](_0x2f6144,{'showHidden':![],'depth':null}));if(this[_0x7b47('0x1b')][_0x2f6144[_0x7b47('0x1c')]]){_['merge'](this['channels'][_0x2f6144['uniqueid']],{'starttime':moment()['format'](_0x7b47('0x1d')),'lastevent':'called','interface':_0x2f6144[_0x7b47('0x1e')][_0x7b47('0x1f')](0x0,_0x2f6144[_0x7b47('0x1e')][_0x7b47('0x20')]('-')),'membername':_0x2f6144[_0x7b47('0x1e')][_0x7b47('0x1f')](_0x2f6144[_0x7b47('0x1e')]['lastIndexOf']('/')+0x1,_0x2f6144[_0x7b47('0x1e')][_0x7b47('0x20')]('-'))},_[_0x7b47('0x21')](_0x2f6144,['event',_0x7b47('0x22')]));logger[_0x7b47('0x23')](_0x7b47('0x24'),_0x2f6144['uniqueid'],this[_0x7b47('0x1b')][_0x2f6144[_0x7b47('0x1c')]][_0x7b47('0x25')],this[_0x7b47('0x1b')][_0x2f6144['uniqueid']][_0x7b47('0x26')]);logger[_0x7b47('0x18')]('[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:',_0x2f6144[_0x7b47('0x1c')],util[_0x7b47('0x1a')](this[_0x7b47('0x1b')][_0x2f6144[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));this[_0x7b47('0x16')](_0x7b47('0x27'),_0x7b47('0x28'),this[_0x7b47('0x1b')][_0x2f6144[_0x7b47('0x1c')]]);logger[_0x7b47('0x18')](_0x7b47('0x29'),_0x2f6144['uniqueid'],util[_0x7b47('0x1a')](this[_0x7b47('0x1b')][_0x2f6144[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x7b47('0x16')](_0x7b47('0x2a'),this[_0x7b47('0x1b')][_0x2f6144['uniqueid']]);}}}catch(_0x3fa1a3){logger[_0x7b47('0x2b')](_0x7b47('0x2c'),_0x2f6144[_0x7b47('0x1c')],util[_0x7b47('0x1a')](_0x3fa1a3,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x7b47('0x14')][_0x7b47('0xf')]=function(_0x13914c){try{if(this[_0x7b47('0x17')](_0x13914c)){logger[_0x7b47('0x18')](_0x7b47('0x2d'),_0x13914c[_0x7b47('0x1c')],util[_0x7b47('0x1a')](_0x13914c,{'showHidden':![],'depth':null}));if(this[_0x7b47('0x1b')][_0x13914c['uniqueid']]){this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]]['dialstatus']=_0x13914c['dialstatus'];if(_0x13914c[_0x7b47('0x2e')]===_0x7b47('0x2f')){this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]][_0x7b47('0x30')]=_0x13914c[_0x7b47('0x30')];this[_0x7b47('0x1b')][_0x13914c['uniqueid']][_0x7b47('0x31')]=_0x13914c[_0x7b47('0x31')];this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]][_0x7b47('0x32')]=moment()[_0x7b47('0x33')](_0x7b47('0x1d'));this['channels'][_0x13914c[_0x7b47('0x1c')]][_0x7b47('0x34')]=_0x7b47('0x35');logger['info'](_0x7b47('0x36'),_0x13914c[_0x7b47('0x1c')],_0x13914c[_0x7b47('0x1e')][_0x7b47('0x1f')](_0x13914c[_0x7b47('0x1e')][_0x7b47('0x20')]('/')+0x1,_0x13914c[_0x7b47('0x1e')][_0x7b47('0x20')]('-')));logger[_0x7b47('0x18')](_0x7b47('0x37'),_0x13914c[_0x7b47('0x1c')],util['inspect'](this[_0x7b47('0x1b')][_0x13914c['uniqueid']],{'showHidden':![],'depth':null}));ami[_0x7b47('0x16')](_0x7b47('0x38'),this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]]);}logger[_0x7b47('0x18')](_0x7b47('0x39'),_0x13914c[_0x7b47('0x1c')],util[_0x7b47('0x1a')](this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));this[_0x7b47('0x16')]('voice:outbound','voice_outbound_channel:save',this[_0x7b47('0x1b')][_0x13914c[_0x7b47('0x1c')]]);}}}catch(_0x4b66f0){logger['error'](_0x7b47('0x3a'),_0x13914c[_0x7b47('0x1c')],util['inspect'](_0x4b66f0,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x7b47('0x14')][_0x7b47('0x11')]=function(_0x369a6){try{if(this[_0x7b47('0x17')](_0x369a6)){logger['debug'](_0x7b47('0x3b'),_0x369a6[_0x7b47('0x1c')],util['inspect'](_0x369a6,{'showHidden':![],'depth':null}));this[_0x7b47('0x3c')](_0x369a6[_0x7b47('0x1c')],_[_0x7b47('0x3d')](_0x369a6[_0x7b47('0x3e')])[0x0],_0x369a6[_0x7b47('0x3f')]);if(this['isNotNull'](_0x369a6[_0x7b47('0x3e')])&&this[_0x7b47('0x17')](_0x369a6[_0x7b47('0x3e')]['outboundrouteid'])){if(_[_0x7b47('0x15')](this[_0x7b47('0x1b')][_0x369a6['uniqueid']])){this['channels'][_0x369a6['uniqueid']]={'routeId':_0x369a6[_0x7b47('0x3f')],'variables':this['variables'][_0x369a6['uniqueid']]};logger['info'](_0x7b47('0x40'),_0x369a6[_0x7b47('0x1c')],_0x369a6[_0x7b47('0x3e')]['outboundrouteid'],_[_0x7b47('0x3d')](_0x369a6['variable'])[0x0],_0x369a6['value']);logger[_0x7b47('0x18')](_0x7b47('0x41'),_0x369a6['uniqueid'],util['inspect'](this[_0x7b47('0x1b')][_0x369a6[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));this[_0x7b47('0x16')]('voice:outbound',_0x7b47('0x28'),this[_0x7b47('0x1b')][_0x369a6[_0x7b47('0x1c')]]);}}}}catch(_0x3c7b73){logger[_0x7b47('0x2b')](_0x7b47('0x42'),_0x369a6[_0x7b47('0x1c')],util[_0x7b47('0x1a')](_0x3c7b73,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x7b47('0x14')][_0x7b47('0x3c')]=function(_0x499cbf,_0x5dd2cb,_0x2f948b){var _0xaced59=[_0x7b47('0x43'),_0x7b47('0x44'),'rtpaudioqosjitter','rtpaudioqosjitterbridged',_0x7b47('0x45'),_0x7b47('0x46'),_0x7b47('0x47'),_0x7b47('0x48'),_0x7b47('0x49'),_0x7b47('0x4a'),_0x7b47('0x4b'),'bridgepvtcallid',_0x7b47('0x4c'),_0x7b47('0x4d'),_0x7b47('0x4e'),'memberlastcall',_0x7b47('0x25'),'memberpenalty',_0x7b47('0x4f')];if(!_[_0x7b47('0x50')](_0x5dd2cb)&&!_[_0x7b47('0x51')](_0xaced59,_0x5dd2cb)){if(_['isUndefined'](this['variables'][_0x499cbf])){this['variables'][_0x499cbf]={};}this['variables'][_0x499cbf][_0x5dd2cb]=_0x2f948b;}};VoiceDialReport[_0x7b47('0x14')][_0x7b47('0x13')]=function(_0x110891){try{if(this[_0x7b47('0x17')](_0x110891)){logger[_0x7b47('0x18')](_0x7b47('0x52'),_0x110891['uniqueid'],util[_0x7b47('0x1a')](_0x110891,{'showHidden':![],'depth':null}));if(this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]]){logger[_0x7b47('0x23')](_0x7b47('0x53'),_0x110891[_0x7b47('0x1c')],_0x110891[_0x7b47('0x54')]);this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x55')]=moment()[_0x7b47('0x33')](_0x7b47('0x1d'));this['channels'][_0x110891['uniqueid']][_0x7b47('0x56')]=moment(this['channels'][_0x110891[_0x7b47('0x1c')]]['endtime'])[_0x7b47('0x57')](this['channels'][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x58')],_0x7b47('0x59'));this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x34')]='complete';this[_0x7b47('0xc')][_0x7b47('0x5a')]+=0x1;if(this[_0x7b47('0x1b')][_0x110891['uniqueid']]['answertime']){this[_0x7b47('0xc')][_0x7b47('0x5b')]+=0x1;this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x5c')]=moment(this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x32')])[_0x7b47('0x57')](this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]]['starttime'],_0x7b47('0x59'));this['channels'][_0x110891['uniqueid']][_0x7b47('0x5d')]=moment(this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x55')])[_0x7b47('0x57')](this['channels'][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x32')],_0x7b47('0x59'));this['outbound'][_0x7b47('0x5e')]+=this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x5c')]||0x0;this['outbound'][_0x7b47('0x5f')]+=this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]]['billableseconds'];}this[_0x7b47('0xc')][_0x7b47('0x60')]+=this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]][_0x7b47('0x56')];logger['debug'](_0x7b47('0x61'),_0x110891[_0x7b47('0x1c')],util[_0x7b47('0x1a')](this['channels'][_0x110891[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x7b47('0x16')](_0x7b47('0x62'),this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]]);logger[_0x7b47('0x18')](_0x7b47('0x63'),_0x110891[_0x7b47('0x1c')],util[_0x7b47('0x1a')](this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));ami['emit']('custom:dialend',this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]]);logger[_0x7b47('0x18')](_0x7b47('0x64'),_0x110891['uniqueid'],util['inspect'](this[_0x7b47('0x1b')][_0x110891['uniqueid']],{'showHidden':![],'depth':null}));this['emit'](_0x7b47('0x27'),'voice_outbound:save',this[_0x7b47('0xc')]);logger[_0x7b47('0x23')](_0x7b47('0x65'),JSON[_0x7b47('0x66')](this['channels'][_0x110891[_0x7b47('0x1c')]]));logger[_0x7b47('0x18')](_0x7b47('0x67'),_0x110891[_0x7b47('0x1c')],util[_0x7b47('0x1a')](this['channels'][_0x110891[_0x7b47('0x1c')]],{'showHidden':![],'depth':null}));this['emit'](_0x7b47('0x27'),_0x7b47('0x68'),this[_0x7b47('0x1b')][_0x110891['uniqueid']]);delete this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x1c')]];}else if(this['channels'][_0x110891[_0x7b47('0x69')]]){this[_0x7b47('0x1b')][_0x110891['linkedid']][_0x7b47('0x1c')]=this[_0x7b47('0x1b')][_0x110891[_0x7b47('0x69')]][_0x7b47('0x6a')];}if(this['variables'][_0x110891['uniqueid']]){delete this[_0x7b47('0x6b')][_0x110891[_0x7b47('0x1c')]];}}}catch(_0x51cd05){logger[_0x7b47('0x2b')]('[%s][voiceDialReport][hangup]',_0x110891[_0x7b47('0x1c')],util['inspect'](_0x51cd05,{'showHidden':![],'depth':null}));}};module[_0x7b47('0x6c')]=VoiceDialReport;