91dc03a6bedb516133a597d0c0b45175b2e5e483
[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 _0xa368=['dialstatus','connectedlinenum','connectedlinename','answertime','YYYY-MM-DD\x20HH:mm:ss','lastevent','connect','custom:dialconnect','[syncDialEnd][VoiceDialReport]','isNotNull','addVariable','keys','variable','value','[syncVarSet][VoiceDialReport]','rtpaudioqos','rtpaudioqosbridged','rtpaudioqosjitter','rtpaudioqosjitterbridged','rtpaudioqosrtt','rtpaudioqosrttbridged','sipuri','bridgepeer','bridgepvtcallid','memberinterface','membername','memberpenalty','memberrealtime','isNil','includes','endtime','starttime','seconds','complete','answered','holdtime','diff','sumBillable','billableseconds','duration','custom:voiceDialReport','voice_outbound:save','info','[DEBUG]\x20Emit\x20voice_outbound_channel:remove\x20event','stringify','voice_outbound_channel:remove','[syncHangup][VoiceDialReport]','lodash','util','ami','../ami','redis','localhost','socket.io-emitter','outboundChannels','outbound','variables','syncDialBegin','bind','dialend','syncDialEnd','varset','syncVarSet','hangup','syncHangup','prototype','isUndefined','emit','channels','merge','uniqueid','format','channel','substring','lastIndexOf','omit','event','voice:outbound','voice_outbound_channel:save','error','[syncDialBegin][VoiceDialReport]','inspect'];(function(_0x3ae9aa,_0x48a0ec){var _0x3c11e1=function(_0x3e45b5){while(--_0x3e45b5){_0x3ae9aa['push'](_0x3ae9aa['shift']());}};_0x3c11e1(++_0x48a0ec);}(_0xa368,0xd3));var _0x8a36=function(_0x8d44aa,_0x3d979e){_0x8d44aa=_0x8d44aa-0x0;var _0x3d5d40=_0xa368[_0x8d44aa];return _0x3d5d40;};'use strict';var _=require(_0x8a36('0x0'));var moment=require('moment');var util=require(_0x8a36('0x1'));var Redis=require('ioredis');var config=require('../../../config/environment');var logger=require('../../../config/logger')(_0x8a36('0x2'));var ami=require(_0x8a36('0x3'));config[_0x8a36('0x4')]=_['defaults'](config['redis'],{'host':_0x8a36('0x5'),'port':0x18eb});var io=require(_0x8a36('0x6'))(new Redis(config[_0x8a36('0x4')]));function VoiceDialReport(_0x26d1a9){this['channels']=_0x26d1a9[_0x8a36('0x7')];this['outbound']=_0x26d1a9[_0x8a36('0x8')];this[_0x8a36('0x9')]={};ami['on']('dialbegin',this[_0x8a36('0xa')][_0x8a36('0xb')](this));ami['on'](_0x8a36('0xc'),this[_0x8a36('0xd')][_0x8a36('0xb')](this));ami['on'](_0x8a36('0xe'),this[_0x8a36('0xf')][_0x8a36('0xb')](this));ami['on'](_0x8a36('0x10'),this[_0x8a36('0x11')]['bind'](this));}VoiceDialReport[_0x8a36('0x12')]['isNotNull']=function(_0x102796){return _0x102796!==null&&!_[_0x8a36('0x13')](_0x102796);};VoiceDialReport['prototype'][_0x8a36('0x14')]=function(_0x352787,_0x3a4fa2,_0x2416a0){io['to'](_0x352787)['emit'](_0x3a4fa2,_0x2416a0);};VoiceDialReport[_0x8a36('0x12')][_0x8a36('0xa')]=function(_0x542a32){try{if(this['isNotNull'](_0x542a32)){if(this[_0x8a36('0x15')][_0x542a32['uniqueid']]){_[_0x8a36('0x16')](this[_0x8a36('0x15')][_0x542a32[_0x8a36('0x17')]],{'starttime':moment()[_0x8a36('0x18')]('YYYY-MM-DD\x20HH:mm:ss'),'lastevent':'called','interface':_0x542a32[_0x8a36('0x19')][_0x8a36('0x1a')](0x0,_0x542a32[_0x8a36('0x19')][_0x8a36('0x1b')]('-')),'membername':_0x542a32[_0x8a36('0x19')][_0x8a36('0x1a')](_0x542a32[_0x8a36('0x19')]['lastIndexOf']('/')+0x1,_0x542a32[_0x8a36('0x19')][_0x8a36('0x1b')]('-'))},_[_0x8a36('0x1c')](_0x542a32,[_0x8a36('0x1d'),'privilege']));this['emit'](_0x8a36('0x1e'),_0x8a36('0x1f'),this[_0x8a36('0x15')][_0x542a32[_0x8a36('0x17')]]);ami[_0x8a36('0x14')]('custom:dialbegin',this['channels'][_0x542a32['uniqueid']]);}}}catch(_0x5a6113){logger[_0x8a36('0x20')](_0x8a36('0x21'),util[_0x8a36('0x22')](_0x5a6113,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8a36('0x12')]['syncDialEnd']=function(_0x1a1d2f){try{if(this['isNotNull'](_0x1a1d2f)){if(this[_0x8a36('0x15')][_0x1a1d2f[_0x8a36('0x17')]]){this[_0x8a36('0x15')][_0x1a1d2f[_0x8a36('0x17')]]['dialstatus']=_0x1a1d2f[_0x8a36('0x23')];if(_0x1a1d2f[_0x8a36('0x23')]==='ANSWER'){this['channels'][_0x1a1d2f['uniqueid']][_0x8a36('0x24')]=_0x1a1d2f[_0x8a36('0x24')];this[_0x8a36('0x15')][_0x1a1d2f[_0x8a36('0x17')]][_0x8a36('0x25')]=_0x1a1d2f[_0x8a36('0x25')];this[_0x8a36('0x15')][_0x1a1d2f[_0x8a36('0x17')]][_0x8a36('0x26')]=moment()[_0x8a36('0x18')](_0x8a36('0x27'));this['channels'][_0x1a1d2f[_0x8a36('0x17')]][_0x8a36('0x28')]=_0x8a36('0x29');ami[_0x8a36('0x14')](_0x8a36('0x2a'),this['channels'][_0x1a1d2f[_0x8a36('0x17')]]);}this[_0x8a36('0x14')](_0x8a36('0x1e'),_0x8a36('0x1f'),this[_0x8a36('0x15')][_0x1a1d2f[_0x8a36('0x17')]]);}}}catch(_0x4d57a4){logger[_0x8a36('0x20')](_0x8a36('0x2b'),util[_0x8a36('0x22')](_0x4d57a4,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x8a36('0xf')]=function(_0x57eb36){try{if(this[_0x8a36('0x2c')](_0x57eb36)){this[_0x8a36('0x2d')](_0x57eb36[_0x8a36('0x17')],_[_0x8a36('0x2e')](_0x57eb36[_0x8a36('0x2f')])[0x0],_0x57eb36[_0x8a36('0x30')]);if(this['isNotNull'](_0x57eb36[_0x8a36('0x2f')])&&this['isNotNull'](_0x57eb36[_0x8a36('0x2f')]['outboundrouteid'])){if(_['isUndefined'](this[_0x8a36('0x15')][_0x57eb36[_0x8a36('0x17')]])){this[_0x8a36('0x15')][_0x57eb36[_0x8a36('0x17')]]={'routeId':_0x57eb36['value'],'variables':this[_0x8a36('0x9')][_0x57eb36[_0x8a36('0x17')]]};this[_0x8a36('0x14')](_0x8a36('0x1e'),_0x8a36('0x1f'),this['channels'][_0x57eb36[_0x8a36('0x17')]]);}}}}catch(_0xe2c24c){logger[_0x8a36('0x20')](_0x8a36('0x31'),util[_0x8a36('0x22')](_0xe2c24c,{'showHidden':![],'depth':null}));}};VoiceDialReport[_0x8a36('0x12')][_0x8a36('0x2d')]=function(_0x3b900b,_0x2cc7a6,_0x259ff3){var _0x349847=[_0x8a36('0x32'),_0x8a36('0x33'),_0x8a36('0x34'),_0x8a36('0x35'),'rtpaudioqosloss','rtpaudioqoslossbridged',_0x8a36('0x36'),_0x8a36('0x37'),'sipcallid',_0x8a36('0x38'),_0x8a36('0x39'),_0x8a36('0x3a'),'membercalls','memberdynamic',_0x8a36('0x3b'),'memberlastcall',_0x8a36('0x3c'),_0x8a36('0x3d'),_0x8a36('0x3e')];if(!_[_0x8a36('0x3f')](_0x2cc7a6)&&!_[_0x8a36('0x40')](_0x349847,_0x2cc7a6)){if(_[_0x8a36('0x13')](this['variables'][_0x3b900b])){this[_0x8a36('0x9')][_0x3b900b]={};}this[_0x8a36('0x9')][_0x3b900b][_0x2cc7a6]=_0x259ff3;}};VoiceDialReport[_0x8a36('0x12')][_0x8a36('0x11')]=function(_0x9f4514){try{if(this[_0x8a36('0x2c')](_0x9f4514)){if(this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]){this['channels'][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x41')]=moment()[_0x8a36('0x18')]('YYYY-MM-DD\x20HH:mm:ss');this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]['duration']=moment(this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]['endtime'])['diff'](this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x42')],_0x8a36('0x43'));this['channels'][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x28')]=_0x8a36('0x44');this[_0x8a36('0x8')]['total']+=0x1;if(this[_0x8a36('0x15')][_0x9f4514['uniqueid']][_0x8a36('0x26')]){this['outbound'][_0x8a36('0x45')]+=0x1;this['channels'][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x46')]=moment(this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x26')])[_0x8a36('0x47')](this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x42')],_0x8a36('0x43'));this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]['billableseconds']=moment(this['channels'][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x41')])[_0x8a36('0x47')](this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]['answertime'],_0x8a36('0x43'));this['outbound']['sumHoldTime']+=this[_0x8a36('0x15')][_0x9f4514['uniqueid']]['holdtime']||0x0;this['outbound'][_0x8a36('0x48')]+=this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x49')];}this['outbound']['sumDuration']+=this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]][_0x8a36('0x4a')];ami['emit'](_0x8a36('0x4b'),this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]);ami[_0x8a36('0x14')]('custom:dialend',this['channels'][_0x9f4514[_0x8a36('0x17')]]);this[_0x8a36('0x14')](_0x8a36('0x1e'),_0x8a36('0x4c'),this['outbound']);logger[_0x8a36('0x4d')](_0x8a36('0x4e'),JSON[_0x8a36('0x4f')](this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]));this[_0x8a36('0x14')](_0x8a36('0x1e'),_0x8a36('0x50'),this[_0x8a36('0x15')][_0x9f4514[_0x8a36('0x17')]]);delete this['channels'][_0x9f4514[_0x8a36('0x17')]];}if(this[_0x8a36('0x9')][_0x9f4514[_0x8a36('0x17')]]){delete this['variables'][_0x9f4514[_0x8a36('0x17')]];}}}catch(_0x17e8c9){logger['error'](_0x8a36('0x51'),util['inspect'](_0x17e8c9,{'showHidden':![],'depth':null}));}};module['exports']=VoiceDialReport;