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