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