Built motion from commit (unavailable).|2.4.4
[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 _0xb815=['rtpaudioqosrtt','rtpaudioqosrttbridged','sipuri','membercalls','memberdynamic','memberinterface','membername','memberpenalty','memberrealtime','includes','syncHangup','endtime','diff','starttime','seconds','total','answered','holdtime','billableseconds','sumBillable','sumDuration','custom:dialend','[syncHangup][VoiceDialReport]','lodash','moment','util','ioredis','../../../config/logger','ami','../ami','redis','defaults','localhost','socket.io-emitter','channels','outboundChannels','outbound','dialbegin','syncDialBegin','dialend','bind','varset','syncVarSet','hangup','prototype','isNotNull','isUndefined','emit','uniqueid','format','YYYY-MM-DD\x20HH:mm:ss','called','channel','substring','lastIndexOf','omit','event','privilege','voice:outbound','voice_outbound_channel:save','[syncDialBegin][VoiceDialReport]','inspect','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','lastevent','connect','custom:dialconnect','error','[syncDialEnd][VoiceDialReport]','keys','value','variable','outboundrouteid','variables','addVariable','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqoslossbridged'];(function(_0x1bb926,_0x58f074){var _0x53508e=function(_0xe3bc33){while(--_0xe3bc33){_0x1bb926['push'](_0x1bb926['shift']());}};_0x53508e(++_0x58f074);}(_0xb815,0x10a));var _0x5b81=function(_0x20fe7c,_0x15af9c){_0x20fe7c=_0x20fe7c-0x0;var _0x3f18ee=_0xb815[_0x20fe7c];return _0x3f18ee;};'use strict';var _=require(_0x5b81('0x0'));var moment=require(_0x5b81('0x1'));var util=require(_0x5b81('0x2'));var Redis=require(_0x5b81('0x3'));var config=require('../../../config/environment');var logger=require(_0x5b81('0x4'))(_0x5b81('0x5'));var ami=require(_0x5b81('0x6'));config[_0x5b81('0x7')]=_[_0x5b81('0x8')](config['redis'],{'host':_0x5b81('0x9'),'port':0x18eb});var io=require(_0x5b81('0xa'))(new Redis(config[_0x5b81('0x7')]));function VoiceDialReport(_0xcc6723){this[_0x5b81('0xb')]=_0xcc6723[_0x5b81('0xc')];this[_0x5b81('0xd')]=_0xcc6723[_0x5b81('0xd')];this['variables']={};ami['on'](_0x5b81('0xe'),this[_0x5b81('0xf')]['bind'](this));ami['on'](_0x5b81('0x10'),this['syncDialEnd'][_0x5b81('0x11')](this));ami['on'](_0x5b81('0x12'),this[_0x5b81('0x13')]['bind'](this));ami['on'](_0x5b81('0x14'),this['syncHangup'][_0x5b81('0x11')](this));}VoiceDialReport[_0x5b81('0x15')][_0x5b81('0x16')]=function(_0x385ee4){return _0x385ee4!==null&&!_[_0x5b81('0x17')](_0x385ee4);};VoiceDialReport[_0x5b81('0x15')][_0x5b81('0x18')]=function(_0x9c5f55,_0x357733,_0x321536){io['to'](_0x9c5f55)[_0x5b81('0x18')](_0x357733,_0x321536);};VoiceDialReport[_0x5b81('0x15')][_0x5b81('0xf')]=function(_0x53dc12){try{if(this[_0x5b81('0x16')](_0x53dc12)){if(this[_0x5b81('0xb')][_0x53dc12[_0x5b81('0x19')]]){_['merge'](this[_0x5b81('0xb')][_0x53dc12['uniqueid']],{'starttime':moment()[_0x5b81('0x1a')](_0x5b81('0x1b')),'lastevent':_0x5b81('0x1c'),'interface':_0x53dc12[_0x5b81('0x1d')][_0x5b81('0x1e')](0x0,_0x53dc12['channel'][_0x5b81('0x1f')]('-')),'membername':_0x53dc12[_0x5b81('0x1d')]['substring'](_0x53dc12[_0x5b81('0x1d')][_0x5b81('0x1f')]('/')+0x1,_0x53dc12[_0x5b81('0x1d')][_0x5b81('0x1f')]('-'))},_[_0x5b81('0x20')](_0x53dc12,[_0x5b81('0x21'),_0x5b81('0x22')]));this[_0x5b81('0x18')](_0x5b81('0x23'),_0x5b81('0x24'),this[_0x5b81('0xb')][_0x53dc12[_0x5b81('0x19')]]);ami['emit']('custom:dialbegin',this[_0x5b81('0xb')][_0x53dc12[_0x5b81('0x19')]]);}}}catch(_0x55312f){logger['error'](_0x5b81('0x25'),util[_0x5b81('0x26')](_0x55312f,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x5b81('0x15')]['syncDialEnd']=function(_0x321ef1){try{if(this[_0x5b81('0x16')](_0x321ef1)){if(this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]]){this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]][_0x5b81('0x27')]=_0x321ef1[_0x5b81('0x27')];if(_0x321ef1[_0x5b81('0x27')]===_0x5b81('0x28')){this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]][_0x5b81('0x29')]=_0x321ef1[_0x5b81('0x29')];this['channels'][_0x321ef1[_0x5b81('0x19')]][_0x5b81('0x2a')]=_0x321ef1[_0x5b81('0x2a')];this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]][_0x5b81('0x2b')]=moment()[_0x5b81('0x1a')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]][_0x5b81('0x2c')]=_0x5b81('0x2d');ami[_0x5b81('0x18')](_0x5b81('0x2e'),this['channels'][_0x321ef1[_0x5b81('0x19')]]);}this['emit']('voice:outbound',_0x5b81('0x24'),this[_0x5b81('0xb')][_0x321ef1[_0x5b81('0x19')]]);}}}catch(_0x3ce763){logger[_0x5b81('0x2f')](_0x5b81('0x30'),util[_0x5b81('0x26')](_0x3ce763,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype']['syncVarSet']=function(_0x1031b5){try{if(this['isNotNull'](_0x1031b5)){this['addVariable'](_0x1031b5['uniqueid'],_[_0x5b81('0x31')](_0x1031b5['variable'])[0x0],_0x1031b5[_0x5b81('0x32')]);if(this['isNotNull'](_0x1031b5[_0x5b81('0x33')])&&this[_0x5b81('0x16')](_0x1031b5[_0x5b81('0x33')][_0x5b81('0x34')])){if(_[_0x5b81('0x17')](this[_0x5b81('0xb')][_0x1031b5[_0x5b81('0x19')]])){this[_0x5b81('0xb')][_0x1031b5['uniqueid']]={'routeId':_0x1031b5[_0x5b81('0x32')],'variables':this[_0x5b81('0x35')][_0x1031b5[_0x5b81('0x19')]]};this[_0x5b81('0x18')](_0x5b81('0x23'),'voice_outbound_channel:save',this['channels'][_0x1031b5['uniqueid']]);}}}}catch(_0x437987){logger[_0x5b81('0x2f')]('[syncVarSet][VoiceDialReport]',util[_0x5b81('0x26')](_0x437987,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x5b81('0x15')][_0x5b81('0x36')]=function(_0x51da5d,_0xc0295d,_0x45d61d){var _0x318502=['rtpaudioqos','rtpaudioqosbridged',_0x5b81('0x37'),_0x5b81('0x38'),'rtpaudioqosloss',_0x5b81('0x39'),_0x5b81('0x3a'),_0x5b81('0x3b'),'sipcallid',_0x5b81('0x3c'),'bridgepeer','bridgepvtcallid',_0x5b81('0x3d'),_0x5b81('0x3e'),_0x5b81('0x3f'),'memberlastcall',_0x5b81('0x40'),_0x5b81('0x41'),_0x5b81('0x42')];if(!_['isNil'](_0xc0295d)&&!_[_0x5b81('0x43')](_0x318502,_0xc0295d)){if(_[_0x5b81('0x17')](this[_0x5b81('0x35')][_0x51da5d])){this[_0x5b81('0x35')][_0x51da5d]={};}this['variables'][_0x51da5d][_0xc0295d]=_0x45d61d;}};VoiceDialReport['prototype'][_0x5b81('0x44')]=function(_0x417b01){try{if(this[_0x5b81('0x16')](_0x417b01)){if(this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]){this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x45')]=moment()[_0x5b81('0x1a')](_0x5b81('0x1b'));this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]['duration']=moment(this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x45')])[_0x5b81('0x46')](this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x47')],_0x5b81('0x48'));this['channels'][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x2c')]='complete';this[_0x5b81('0xd')][_0x5b81('0x49')]+=0x1;if(this['channels'][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x2b')]){this[_0x5b81('0xd')][_0x5b81('0x4a')]+=0x1;this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x4b')]=moment(this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x2b')])[_0x5b81('0x46')](this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x47')],_0x5b81('0x48'));this['channels'][_0x417b01['uniqueid']][_0x5b81('0x4c')]=moment(this['channels'][_0x417b01[_0x5b81('0x19')]]['endtime'])[_0x5b81('0x46')](this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x2b')],_0x5b81('0x48'));this[_0x5b81('0xd')]['sumHoldTime']+=this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x4b')]||0x0;this[_0x5b81('0xd')][_0x5b81('0x4d')]+=this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]][_0x5b81('0x4c')];}this[_0x5b81('0xd')][_0x5b81('0x4e')]+=this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]['duration'];ami[_0x5b81('0x18')]('custom:voiceDialReport',this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]);ami[_0x5b81('0x18')](_0x5b81('0x4f'),this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]);this[_0x5b81('0x18')]('voice:outbound','voice_outbound:save',this[_0x5b81('0xd')]);this[_0x5b81('0x18')](_0x5b81('0x23'),'voice_outbound_channel:remove',this[_0x5b81('0xb')][_0x417b01[_0x5b81('0x19')]]);delete this['channels'][_0x417b01[_0x5b81('0x19')]];}if(this[_0x5b81('0x35')][_0x417b01[_0x5b81('0x19')]]){delete this[_0x5b81('0x35')][_0x417b01[_0x5b81('0x19')]];}}}catch(_0x56eba8){logger[_0x5b81('0x2f')](_0x5b81('0x50'),util[_0x5b81('0x26')](_0x56eba8,{'showHidden':![],'depth':null}));}};module['exports']=VoiceDialReport;