1b5d87a886a0a0f66f60f087be3db5837ac2a62e
[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 _0x5fc3=['rtpaudioqosrtt','rtpaudioqosrttbridged','sipcallid','sipuri','bridgepeer','bridgepvtcallid','membercalls','memberdynamic','memberpenalty','memberrealtime','isNil','includes','[%s][voiceDialReport][hangup]\x20event:','[%s][voiceDialReport][hangup]\x20reason:%s\x20lasteevent:complete','cause-txt','duration','endtime','starttime','complete','total','answered','holdtime','seconds','billableseconds','sumBillable','[%s][voiceDialReport][hangup]\x20sending\x20voiceDialReport\x20event:','custom:dialend','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound:save\x20event:','voice_outbound:save','stringify','[%s][voiceDialReport][hangup]\x20sending\x20voice_outbound_channel:remove\x20event:','voice_outbound_channel:remove','linkedid','destuniqueid','syncNewExten','[%s][voiceDialReport][newexten]\x20event:','application','toLowerCase','set','appdata','applicationdata','startsWith','cdr(','[%s][voiceDialReport][newexten]\x20application:%s\x20appdata:%s','match','[%s][voiceDialReport][newexten]','exports','lodash','moment','ioredis','../../../config/environment','../../../config/logger','ami','../ami','defaults','redis','localhost','outboundChannels','outbound','applications','variables','dialbegin','syncDialBegin','dialend','syncDialEnd','varset','syncVarSet','hangup','syncHangup','isNotNull','isUndefined','prototype','emit','debug','[%s][voiceDialReport][dialbegin]\x20event:','uniqueid','inspect','merge','format','YYYY-MM-DD\x20HH:mm:ss','channel','substring','lastIndexOf','omit','event','privilege','info','channels','membername','interface','voice:outbound','voice_outbound_channel:save','[%s][voiceDialReport][dialbegin]\x20sending\x20dialbegin\x20event:','[%s][voiceDialReport][dialbegin]','[%s][voiceDialReport][dialend]\x20event:','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','lastevent','connect','[%s][voiceDialReport][dialend]\x20agent:%s\x20lastevent:connect','[%s][voiceDialReport][dialend]\x20sending\x20dialconnect\x20event:','[%s][voiceDialReport][dialend]\x20sending\x20voice_outbound_channel:save\x20event:','error','[%s][voiceDialReport][dialend]','[%s][voiceDialReport][varset]\x20event:','keys','variable','outboundrouteid','voice','value','[%s][voiceDialReport][varset]','addVariable','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosloss','rtpaudioqoslossbridged'];(function(_0x1cd789,_0x418ba2){var _0x55cdc1=function(_0x2c6809){while(--_0x2c6809){_0x1cd789['push'](_0x1cd789['shift']());}};_0x55cdc1(++_0x418ba2);}(_0x5fc3,0xa8));var _0x35fc=function(_0x5c3ae9,_0x450f9a){_0x5c3ae9=_0x5c3ae9-0x0;var _0x3f5950=_0x5fc3[_0x5c3ae9];return _0x3f5950;};'use strict';var _=require(_0x35fc('0x0'));var moment=require(_0x35fc('0x1'));var util=require('util');var Redis=require(_0x35fc('0x2'));var config=require(_0x35fc('0x3'));var logger=require(_0x35fc('0x4'))(_0x35fc('0x5'));var ami=require(_0x35fc('0x6'));config['redis']=_[_0x35fc('0x7')](config[_0x35fc('0x8')],{'host':_0x35fc('0x9'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function VoiceDialReport(_0x19a0d1){this['channels']=_0x19a0d1[_0x35fc('0xa')];this[_0x35fc('0xb')]=_0x19a0d1[_0x35fc('0xb')];this[_0x35fc('0xc')]={};this[_0x35fc('0xd')]={};ami['on'](_0x35fc('0xe'),this[_0x35fc('0xf')]['bind'](this));ami['on'](_0x35fc('0x10'),this[_0x35fc('0x11')]['bind'](this));ami['on'](_0x35fc('0x12'),this[_0x35fc('0x13')]['bind'](this));ami['on'](_0x35fc('0x14'),this[_0x35fc('0x15')]['bind'](this));}VoiceDialReport['prototype'][_0x35fc('0x16')]=function(_0x5d462a){return _0x5d462a!==null&&!_[_0x35fc('0x17')](_0x5d462a);};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x19')]=function(_0x29730f,_0x38d9f2,_0x5cfe94){io['to'](_0x29730f)['emit'](_0x38d9f2,_0x5cfe94);};VoiceDialReport['prototype']['syncDialBegin']=function(_0x398b67){try{if(this[_0x35fc('0x16')](_0x398b67)){logger[_0x35fc('0x1a')](_0x35fc('0x1b'),_0x398b67[_0x35fc('0x1c')],util[_0x35fc('0x1d')](_0x398b67,{'showHidden':![],'depth':null}));if(this['channels'][_0x398b67[_0x35fc('0x1c')]]){_[_0x35fc('0x1e')](this['channels'][_0x398b67[_0x35fc('0x1c')]],{'starttime':moment()[_0x35fc('0x1f')](_0x35fc('0x20')),'lastevent':'called','interface':_0x398b67[_0x35fc('0x21')][_0x35fc('0x22')](0x0,_0x398b67[_0x35fc('0x21')]['lastIndexOf']('-')),'membername':_0x398b67[_0x35fc('0x21')][_0x35fc('0x22')](_0x398b67[_0x35fc('0x21')][_0x35fc('0x23')]('/')+0x1,_0x398b67[_0x35fc('0x21')][_0x35fc('0x23')]('-'))},_[_0x35fc('0x24')](_0x398b67,[_0x35fc('0x25'),_0x35fc('0x26')]));logger[_0x35fc('0x27')]('[%s][voiceDialReport][dialbegin]\x20agent:%s\x20interface:%s\x20lastevent:called',_0x398b67[_0x35fc('0x1c')],this[_0x35fc('0x28')][_0x398b67[_0x35fc('0x1c')]][_0x35fc('0x29')],this[_0x35fc('0x28')][_0x398b67['uniqueid']][_0x35fc('0x2a')]);logger[_0x35fc('0x1a')]('[%s][voiceDialReport][dialbegin]\x20sending\x20voice_outbound_channel:save\x20event:',_0x398b67[_0x35fc('0x1c')],util[_0x35fc('0x1d')](this[_0x35fc('0x28')][_0x398b67['uniqueid']],{'showHidden':![],'depth':null}));if(this[_0x35fc('0xc')][_0x398b67['uniqueid']])_[_0x35fc('0x1e')](this[_0x35fc('0x28')][_0x398b67['uniqueid']],this['applications'][_0x398b67[_0x35fc('0x1c')]]);this['emit'](_0x35fc('0x2b'),_0x35fc('0x2c'),this['channels'][_0x398b67[_0x35fc('0x1c')]]);logger[_0x35fc('0x1a')](_0x35fc('0x2d'),_0x398b67[_0x35fc('0x1c')],util[_0x35fc('0x1d')](this[_0x35fc('0x28')][_0x398b67[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x35fc('0x19')]('custom:dialbegin',this[_0x35fc('0x28')][_0x398b67[_0x35fc('0x1c')]]);}}}catch(_0x22af18){logger['error'](_0x35fc('0x2e'),_0x398b67[_0x35fc('0x1c')],util[_0x35fc('0x1d')](_0x22af18,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x11')]=function(_0x103181){try{if(this[_0x35fc('0x16')](_0x103181)){logger[_0x35fc('0x1a')](_0x35fc('0x2f'),_0x103181[_0x35fc('0x1c')],util['inspect'](_0x103181,{'showHidden':![],'depth':null}));if(this['channels'][_0x103181[_0x35fc('0x1c')]]){this['channels'][_0x103181[_0x35fc('0x1c')]][_0x35fc('0x30')]=_0x103181[_0x35fc('0x30')];if(_0x103181[_0x35fc('0x30')]===_0x35fc('0x31')){this[_0x35fc('0x28')][_0x103181['uniqueid']][_0x35fc('0x32')]=_0x103181[_0x35fc('0x32')];this[_0x35fc('0x28')][_0x103181[_0x35fc('0x1c')]][_0x35fc('0x33')]=_0x103181[_0x35fc('0x33')];this['channels'][_0x103181[_0x35fc('0x1c')]][_0x35fc('0x34')]=moment()[_0x35fc('0x1f')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x35fc('0x28')][_0x103181['uniqueid']][_0x35fc('0x35')]=_0x35fc('0x36');logger[_0x35fc('0x27')](_0x35fc('0x37'),_0x103181['uniqueid'],_0x103181['channel']['substring'](_0x103181[_0x35fc('0x21')]['lastIndexOf']('/')+0x1,_0x103181[_0x35fc('0x21')]['lastIndexOf']('-')));logger[_0x35fc('0x1a')](_0x35fc('0x38'),_0x103181[_0x35fc('0x1c')],util[_0x35fc('0x1d')](this[_0x35fc('0x28')][_0x103181[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x35fc('0x19')]('custom:dialconnect',this[_0x35fc('0x28')][_0x103181[_0x35fc('0x1c')]]);}logger['debug'](_0x35fc('0x39'),_0x103181[_0x35fc('0x1c')],util[_0x35fc('0x1d')](this[_0x35fc('0x28')][_0x103181[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));this[_0x35fc('0x19')]('voice:outbound',_0x35fc('0x2c'),this[_0x35fc('0x28')][_0x103181[_0x35fc('0x1c')]]);}}}catch(_0x52543b){logger[_0x35fc('0x3a')](_0x35fc('0x3b'),_0x103181['uniqueid'],util[_0x35fc('0x1d')](_0x52543b,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x13')]=function(_0x41e199){try{if(this[_0x35fc('0x16')](_0x41e199)){logger[_0x35fc('0x1a')](_0x35fc('0x3c'),_0x41e199[_0x35fc('0x1c')],util['inspect'](_0x41e199,{'showHidden':![],'depth':null}));this['addVariable'](_0x41e199[_0x35fc('0x1c')],_[_0x35fc('0x3d')](_0x41e199['variable'])[0x0],_0x41e199['value']);if(this['isNotNull'](_0x41e199[_0x35fc('0x3e')])&&this[_0x35fc('0x16')](_0x41e199['variable'][_0x35fc('0x3f')])){if(_[_0x35fc('0x17')](this[_0x35fc('0x28')][_0x41e199[_0x35fc('0x1c')]])){this['channels'][_0x41e199['uniqueid']]={'routeId':_0x41e199['value'],'variables':this['variables'][_0x41e199['uniqueid']],'motionChannel':_0x35fc('0x40')};logger[_0x35fc('0x27')]('[%s][voiceDialReport][varset]\x20outboundrouteid:%s\x20variable:%s\x20value:%s',_0x41e199[_0x35fc('0x1c')],_0x41e199['variable'][_0x35fc('0x3f')],_[_0x35fc('0x3d')](_0x41e199[_0x35fc('0x3e')])[0x0],_0x41e199[_0x35fc('0x41')]);logger[_0x35fc('0x1a')]('[%s][voiceDialReport][varset]\x20sending\x20voice_outbound_channel:save\x20event:',_0x41e199[_0x35fc('0x1c')],util[_0x35fc('0x1d')](this['channels'][_0x41e199[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));this[_0x35fc('0x19')](_0x35fc('0x2b'),_0x35fc('0x2c'),this['channels'][_0x41e199[_0x35fc('0x1c')]]);}}}}catch(_0x4c82d8){logger['error'](_0x35fc('0x42'),_0x41e199[_0x35fc('0x1c')],util[_0x35fc('0x1d')](_0x4c82d8,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x43')]=function(_0x302a7b,_0x405320,_0x16afa6){var _0x4f555f=[_0x35fc('0x44'),_0x35fc('0x45'),_0x35fc('0x46'),_0x35fc('0x47'),_0x35fc('0x48'),_0x35fc('0x49'),_0x35fc('0x4a'),_0x35fc('0x4b'),_0x35fc('0x4c'),_0x35fc('0x4d'),_0x35fc('0x4e'),_0x35fc('0x4f'),_0x35fc('0x50'),_0x35fc('0x51'),'memberinterface','memberlastcall',_0x35fc('0x29'),_0x35fc('0x52'),_0x35fc('0x53')];if(!_[_0x35fc('0x54')](_0x405320)&&!_[_0x35fc('0x55')](_0x4f555f,_0x405320)){if(_[_0x35fc('0x17')](this['variables'][_0x302a7b])){this['variables'][_0x302a7b]={};}this[_0x35fc('0xd')][_0x302a7b][_0x405320]=_0x16afa6;}};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x15')]=function(_0x38bc78){try{if(this['isNotNull'](_0x38bc78)){logger[_0x35fc('0x1a')](_0x35fc('0x56'),_0x38bc78['uniqueid'],util[_0x35fc('0x1d')](_0x38bc78,{'showHidden':![],'depth':null}));if(this[_0x35fc('0x28')][_0x38bc78['uniqueid']]){logger[_0x35fc('0x27')](_0x35fc('0x57'),_0x38bc78[_0x35fc('0x1c')],_0x38bc78[_0x35fc('0x58')]);this['channels'][_0x38bc78['uniqueid']]['endtime']=moment()[_0x35fc('0x1f')](_0x35fc('0x20'));this['channels'][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x59')]=moment(this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x5a')])['diff'](this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x5b')],'seconds');this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]]['lastevent']=_0x35fc('0x5c');this[_0x35fc('0xb')][_0x35fc('0x5d')]+=0x1;if(this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x34')]){this[_0x35fc('0xb')][_0x35fc('0x5e')]+=0x1;this['channels'][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x5f')]=moment(this[_0x35fc('0x28')][_0x38bc78['uniqueid']][_0x35fc('0x34')])['diff'](this['channels'][_0x38bc78['uniqueid']][_0x35fc('0x5b')],_0x35fc('0x60'));this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x61')]=moment(this['channels'][_0x38bc78['uniqueid']]['endtime'])['diff'](this['channels'][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x34')],_0x35fc('0x60'));this[_0x35fc('0xb')]['sumHoldTime']+=this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x5f')]||0x0;this[_0x35fc('0xb')][_0x35fc('0x62')]+=this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]][_0x35fc('0x61')];}this[_0x35fc('0xb')]['sumDuration']+=this[_0x35fc('0x28')][_0x38bc78['uniqueid']][_0x35fc('0x59')];logger[_0x35fc('0x1a')](_0x35fc('0x63'),_0x38bc78[_0x35fc('0x1c')],util['inspect'](this[_0x35fc('0x28')][_0x38bc78['uniqueid']],{'showHidden':![],'depth':null}));ami['emit']('custom:voiceDialReport',this[_0x35fc('0x28')][_0x38bc78['uniqueid']]);logger[_0x35fc('0x1a')]('[%s][voiceDialReport][hangup]\x20sending\x20dialend\x20event:',_0x38bc78[_0x35fc('0x1c')],util['inspect'](this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));ami[_0x35fc('0x19')](_0x35fc('0x64'),this['channels'][_0x38bc78[_0x35fc('0x1c')]]);logger[_0x35fc('0x1a')](_0x35fc('0x65'),_0x38bc78['uniqueid'],util[_0x35fc('0x1d')](this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));this[_0x35fc('0x19')](_0x35fc('0x2b'),_0x35fc('0x66'),this[_0x35fc('0xb')]);logger[_0x35fc('0x27')]('[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event',JSON[_0x35fc('0x67')](this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]]));logger['debug'](_0x35fc('0x68'),_0x38bc78[_0x35fc('0x1c')],util['inspect'](this['channels'][_0x38bc78[_0x35fc('0x1c')]],{'showHidden':![],'depth':null}));this['emit'](_0x35fc('0x2b'),_0x35fc('0x69'),this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]]);delete this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x1c')]];}else if(this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x6a')]]){this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x6a')]][_0x35fc('0x1c')]=this[_0x35fc('0x28')][_0x38bc78[_0x35fc('0x6a')]][_0x35fc('0x6b')];}if(this[_0x35fc('0xd')][_0x38bc78[_0x35fc('0x1c')]]){delete this[_0x35fc('0xd')][_0x38bc78[_0x35fc('0x1c')]];}}}catch(_0x3b2160){logger[_0x35fc('0x3a')]('[%s][voiceDialReport][hangup]',_0x38bc78[_0x35fc('0x1c')],util['inspect'](_0x3b2160,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x35fc('0x18')][_0x35fc('0x6c')]=function(_0x2185ce){try{if(this[_0x35fc('0x16')](_0x2185ce)){logger[_0x35fc('0x1a')](_0x35fc('0x6d'),_0x2185ce[_0x35fc('0x1c')],util[_0x35fc('0x1d')](_0x2185ce,{'showHidden':![],'depth':null}));if(_0x2185ce[_0x35fc('0x6e')][_0x35fc('0x6f')]()===_0x35fc('0x70')){_0x2185ce['applicationdata']=(_0x2185ce[_0x35fc('0x71')]||_0x2185ce[_0x35fc('0x72')])[_0x35fc('0x6f')]();if(_[_0x35fc('0x73')](_0x2185ce[_0x35fc('0x72')],_0x35fc('0x74'))){if(_['isUndefined'](this[_0x35fc('0xc')][_0x2185ce[_0x35fc('0x1c')]]))this[_0x35fc('0xc')][_0x2185ce[_0x35fc('0x1c')]]={};logger[_0x35fc('0x27')](_0x35fc('0x75'),_0x2185ce[_0x35fc('0x1c')],_0x2185ce[_0x35fc('0x6e')],_0x2185ce[_0x35fc('0x72')]);var _0x5f23d8=_0x2185ce[_0x35fc('0x72')]['split']('=');var _0x1c7d01=_0x5f23d8[0x0][_0x35fc('0x76')](/cdr\((.*)\)/);if(_0x1c7d01)this['applications'][_0x2185ce[_0x35fc('0x1c')]][_0x1c7d01[0x1]]=_0x5f23d8[0x1];}}}}catch(_0x41002a){logger[_0x35fc('0x3a')](_0x35fc('0x77'),_0x2185ce[_0x35fc('0x1c')],util[_0x35fc('0x1d')](_0x41002a,{'showHidden':![],'depth':null}));}};module[_0x35fc('0x78')]=VoiceDialReport;