970a87b92b85319b6dffaa6b852811af290b693c
[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 _0x151b=['addVariable','keys','variable','value','outboundrouteid','variables','voice_outbound_channel:save','[syncVarSet][VoiceDialReport]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipuri','bridgepeer','membercalls','memberdynamic','memberlastcall','membername','memberpenalty','includes','endtime','diff','starttime','seconds','complete','billableseconds','sumHoldTime','holdtime','sumBillable','sumDuration','duration','custom:voiceDialReport','custom:dialend','voice_outbound:save','info','stringify','[syncHangup][VoiceDialReport]','exports','lodash','util','ioredis','../../../config/environment','../../../config/logger','../ami','defaults','redis','localhost','socket.io-emitter','channels','outboundChannels','outbound','syncDialBegin','bind','dialend','syncDialEnd','varset','hangup','prototype','isNotNull','isUndefined','emit','uniqueid','merge','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','event','privilege','voice:outbound','custom:dialbegin','error','inspect','dialstatus','connectedlinenum','connectedlinename','answertime','connect','custom:dialconnect','[syncDialEnd][VoiceDialReport]','syncVarSet'];(function(_0x49c8e4,_0x5d6a1b){var _0x17cf7a=function(_0x232555){while(--_0x232555){_0x49c8e4['push'](_0x49c8e4['shift']());}};_0x17cf7a(++_0x5d6a1b);}(_0x151b,0x1dc));var _0xb151=function(_0x204117,_0x498912){_0x204117=_0x204117-0x0;var _0x36b94e=_0x151b[_0x204117];return _0x36b94e;};'use strict';var _=require(_0xb151('0x0'));var moment=require('moment');var util=require(_0xb151('0x1'));var Redis=require(_0xb151('0x2'));var config=require(_0xb151('0x3'));var logger=require(_0xb151('0x4'))('ami');var ami=require(_0xb151('0x5'));config['redis']=_[_0xb151('0x6')](config[_0xb151('0x7')],{'host':_0xb151('0x8'),'port':0x18eb});var io=require(_0xb151('0x9'))(new Redis(config[_0xb151('0x7')]));function VoiceDialReport(_0x1be3b3){this[_0xb151('0xa')]=_0x1be3b3[_0xb151('0xb')];this['outbound']=_0x1be3b3[_0xb151('0xc')];this['variables']={};ami['on']('dialbegin',this[_0xb151('0xd')][_0xb151('0xe')](this));ami['on'](_0xb151('0xf'),this[_0xb151('0x10')][_0xb151('0xe')](this));ami['on'](_0xb151('0x11'),this['syncVarSet'][_0xb151('0xe')](this));ami['on'](_0xb151('0x12'),this['syncHangup'][_0xb151('0xe')](this));}VoiceDialReport[_0xb151('0x13')][_0xb151('0x14')]=function(_0x1a562a){return _0x1a562a!==null&&!_[_0xb151('0x15')](_0x1a562a);};VoiceDialReport[_0xb151('0x13')][_0xb151('0x16')]=function(_0x90317c,_0x19eb3e,_0x35a2f8){io['to'](_0x90317c)[_0xb151('0x16')](_0x19eb3e,_0x35a2f8);};VoiceDialReport[_0xb151('0x13')][_0xb151('0xd')]=function(_0x238d4d){try{if(this[_0xb151('0x14')](_0x238d4d)){if(this[_0xb151('0xa')][_0x238d4d[_0xb151('0x17')]]){_[_0xb151('0x18')](this['channels'][_0x238d4d[_0xb151('0x17')]],{'starttime':moment()[_0xb151('0x19')](_0xb151('0x1a')),'lastevent':_0xb151('0x1b'),'interface':_0x238d4d[_0xb151('0x1c')][_0xb151('0x1d')](0x0,_0x238d4d['channel'][_0xb151('0x1e')]('-')),'membername':_0x238d4d[_0xb151('0x1c')][_0xb151('0x1d')](_0x238d4d[_0xb151('0x1c')][_0xb151('0x1e')]('/')+0x1,_0x238d4d['channel'][_0xb151('0x1e')]('-'))},_[_0xb151('0x1f')](_0x238d4d,[_0xb151('0x20'),_0xb151('0x21')]));this['emit'](_0xb151('0x22'),'voice_outbound_channel:save',this['channels'][_0x238d4d[_0xb151('0x17')]]);ami[_0xb151('0x16')](_0xb151('0x23'),this[_0xb151('0xa')][_0x238d4d[_0xb151('0x17')]]);}}}catch(_0x49c5a0){logger[_0xb151('0x24')]('[syncDialBegin][VoiceDialReport]',util[_0xb151('0x25')](_0x49c5a0,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0xb151('0x13')][_0xb151('0x10')]=function(_0x53ce23){try{if(this[_0xb151('0x14')](_0x53ce23)){if(this[_0xb151('0xa')][_0x53ce23['uniqueid']]){this[_0xb151('0xa')][_0x53ce23[_0xb151('0x17')]][_0xb151('0x26')]=_0x53ce23['dialstatus'];if(_0x53ce23[_0xb151('0x26')]==='ANSWER'){this[_0xb151('0xa')][_0x53ce23[_0xb151('0x17')]][_0xb151('0x27')]=_0x53ce23[_0xb151('0x27')];this['channels'][_0x53ce23[_0xb151('0x17')]][_0xb151('0x28')]=_0x53ce23[_0xb151('0x28')];this[_0xb151('0xa')][_0x53ce23[_0xb151('0x17')]][_0xb151('0x29')]=moment()[_0xb151('0x19')](_0xb151('0x1a'));this['channels'][_0x53ce23[_0xb151('0x17')]]['lastevent']=_0xb151('0x2a');ami[_0xb151('0x16')](_0xb151('0x2b'),this[_0xb151('0xa')][_0x53ce23[_0xb151('0x17')]]);}this['emit'](_0xb151('0x22'),'voice_outbound_channel:save',this[_0xb151('0xa')][_0x53ce23[_0xb151('0x17')]]);}}}catch(_0x4b2967){logger[_0xb151('0x24')](_0xb151('0x2c'),util[_0xb151('0x25')](_0x4b2967,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0xb151('0x13')][_0xb151('0x2d')]=function(_0x24004d){try{if(this[_0xb151('0x14')](_0x24004d)){this[_0xb151('0x2e')](_0x24004d[_0xb151('0x17')],_[_0xb151('0x2f')](_0x24004d[_0xb151('0x30')])[0x0],_0x24004d[_0xb151('0x31')]);if(this[_0xb151('0x14')](_0x24004d[_0xb151('0x30')])&&this[_0xb151('0x14')](_0x24004d[_0xb151('0x30')][_0xb151('0x32')])){if(_[_0xb151('0x15')](this['channels'][_0x24004d[_0xb151('0x17')]])){this[_0xb151('0xa')][_0x24004d[_0xb151('0x17')]]={'routeId':_0x24004d[_0xb151('0x31')],'variables':this[_0xb151('0x33')][_0x24004d[_0xb151('0x17')]]};this[_0xb151('0x16')](_0xb151('0x22'),_0xb151('0x34'),this[_0xb151('0xa')][_0x24004d[_0xb151('0x17')]]);}}}}catch(_0x176781){logger[_0xb151('0x24')](_0xb151('0x35'),util[_0xb151('0x25')](_0x176781,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0xb151('0x2e')]=function(_0xcc4a5e,_0x1f4f77,_0x294d91){var _0x37358e=[_0xb151('0x36'),_0xb151('0x37'),_0xb151('0x38'),_0xb151('0x39'),'rtpaudioqosloss',_0xb151('0x3a'),_0xb151('0x3b'),_0xb151('0x3c'),'sipcallid',_0xb151('0x3d'),_0xb151('0x3e'),'bridgepvtcallid',_0xb151('0x3f'),_0xb151('0x40'),'memberinterface',_0xb151('0x41'),_0xb151('0x42'),_0xb151('0x43'),'memberrealtime'];if(!_['isNil'](_0x1f4f77)&&!_[_0xb151('0x44')](_0x37358e,_0x1f4f77)){if(_[_0xb151('0x15')](this[_0xb151('0x33')][_0xcc4a5e])){this[_0xb151('0x33')][_0xcc4a5e]={};}this['variables'][_0xcc4a5e][_0x1f4f77]=_0x294d91;}};VoiceDialReport[_0xb151('0x13')]['syncHangup']=function(_0x3f4afe){try{if(this[_0xb151('0x14')](_0x3f4afe)){if(this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]){this['channels'][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x45')]=moment()['format'](_0xb151('0x1a'));this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]['duration']=moment(this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]['endtime'])[_0xb151('0x46')](this['channels'][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x47')],_0xb151('0x48'));this[_0xb151('0xa')][_0x3f4afe['uniqueid']]['lastevent']=_0xb151('0x49');this[_0xb151('0xc')]['total']+=0x1;if(this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x29')]){this[_0xb151('0xc')]['answered']+=0x1;this['channels'][_0x3f4afe[_0xb151('0x17')]]['holdtime']=moment(this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x29')])[_0xb151('0x46')](this['channels'][_0x3f4afe['uniqueid']][_0xb151('0x47')],_0xb151('0x48'));this['channels'][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x4a')]=moment(this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x45')])[_0xb151('0x46')](this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]['answertime'],'seconds');this[_0xb151('0xc')][_0xb151('0x4b')]+=this[_0xb151('0xa')][_0x3f4afe['uniqueid']][_0xb151('0x4c')]||0x0;this[_0xb151('0xc')][_0xb151('0x4d')]+=this['channels'][_0x3f4afe[_0xb151('0x17')]]['billableseconds'];}this[_0xb151('0xc')][_0xb151('0x4e')]+=this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]][_0xb151('0x4f')];ami[_0xb151('0x16')](_0xb151('0x50'),this['channels'][_0x3f4afe[_0xb151('0x17')]]);ami['emit'](_0xb151('0x51'),this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]);this[_0xb151('0x16')](_0xb151('0x22'),_0xb151('0x52'),this['outbound']);logger[_0xb151('0x53')]('[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event',JSON[_0xb151('0x54')](this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]));this['emit'](_0xb151('0x22'),'voice_outbound_channel:remove',this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]]);delete this[_0xb151('0xa')][_0x3f4afe[_0xb151('0x17')]];}if(this['variables'][_0x3f4afe[_0xb151('0x17')]]){delete this['variables'][_0x3f4afe[_0xb151('0x17')]];}}}catch(_0x5eef05){logger[_0xb151('0x24')](_0xb151('0x55'),util[_0xb151('0x25')](_0x5eef05,{'showHidden':![],'depth':null}));}};module[_0xb151('0x56')]=VoiceDialReport;