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