Built motion from commit 67e5df37.|2.0.66
[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 _0xe114=['error','[syncDialBegin][VoiceDialReport]','inspect','dialstatus','ANSWER','connectedlinenum','connectedlinename','answertime','lastevent','keys','variable','value','outboundrouteid','voice_outbound_channel:save','[syncVarSet][VoiceDialReport]','diff','starttime','seconds','complete','total','answered','holdtime','billableseconds','endtime','sumHoldTime','sumBillable','duration','custom:voiceDialReport','voice_outbound:save','voice_outbound_channel:remove','lodash','moment','util','../../../config/logger','ami','../ami','localhost','channels','outboundChannels','outbound','variables','dialbegin','syncDialBegin','dialend','syncDialEnd','bind','syncVarSet','hangup','syncHangup','prototype','isNotNull','isUndefined','emit','uniqueid','format','YYYY-MM-DD\x20HH:mm:ss','called','lastIndexOf','channel','substring','event','voice:outbound','custom:dialbegin'];(function(_0x167cc1,_0x56ef5a){var _0x10bc4b=function(_0xd6a255){while(--_0xd6a255){_0x167cc1['push'](_0x167cc1['shift']());}};_0x10bc4b(++_0x56ef5a);}(_0xe114,0x159));var _0x4e11=function(_0x312a5e,_0x56c78a){_0x312a5e=_0x312a5e-0x0;var _0xbfa61c=_0xe114[_0x312a5e];return _0xbfa61c;};'use strict';var _=require(_0x4e11('0x0'));var moment=require(_0x4e11('0x1'));var util=require(_0x4e11('0x2'));var logger=require(_0x4e11('0x3'))(_0x4e11('0x4'));var ami=require(_0x4e11('0x5'));var io=require('socket.io-emitter')({'host':_0x4e11('0x6'),'port':0x18eb});function VoiceDialReport(_0x30d441){this[_0x4e11('0x7')]=_0x30d441[_0x4e11('0x8')];this[_0x4e11('0x9')]=_0x30d441['outbound'];this[_0x4e11('0xa')]={};ami['on'](_0x4e11('0xb'),this[_0x4e11('0xc')]['bind'](this));ami['on'](_0x4e11('0xd'),this[_0x4e11('0xe')][_0x4e11('0xf')](this));ami['on']('varset',this[_0x4e11('0x10')][_0x4e11('0xf')](this));ami['on'](_0x4e11('0x11'),this[_0x4e11('0x12')]['bind'](this));}VoiceDialReport[_0x4e11('0x13')][_0x4e11('0x14')]=function(_0x5e4970){return _0x5e4970!==null&&!_[_0x4e11('0x15')](_0x5e4970);};VoiceDialReport[_0x4e11('0x13')][_0x4e11('0x16')]=function(_0xed5476,_0x2dfb4d,_0x25ab2c){io['to'](_0xed5476)['emit'](_0x2dfb4d,_0x25ab2c);};VoiceDialReport[_0x4e11('0x13')]['syncDialBegin']=function(_0x2208fe){try{if(this[_0x4e11('0x14')](_0x2208fe)){if(this[_0x4e11('0x7')][_0x2208fe[_0x4e11('0x17')]]){_['merge'](this[_0x4e11('0x7')][_0x2208fe['uniqueid']],{'starttime':moment()[_0x4e11('0x18')](_0x4e11('0x19')),'lastevent':_0x4e11('0x1a'),'interface':_0x2208fe['channel']['substring'](0x0,_0x2208fe['channel'][_0x4e11('0x1b')]('-')),'membername':_0x2208fe[_0x4e11('0x1c')][_0x4e11('0x1d')](_0x2208fe[_0x4e11('0x1c')][_0x4e11('0x1b')]('/')+0x1,_0x2208fe[_0x4e11('0x1c')][_0x4e11('0x1b')]('-'))},_['omit'](_0x2208fe,[_0x4e11('0x1e'),'privilege']));this[_0x4e11('0x16')](_0x4e11('0x1f'),'voice_outbound_channel:save',this[_0x4e11('0x7')][_0x2208fe[_0x4e11('0x17')]]);ami['emit'](_0x4e11('0x20'),this[_0x4e11('0x7')][_0x2208fe['uniqueid']]);}}}catch(_0x3edc52){logger[_0x4e11('0x21')](_0x4e11('0x22'),util[_0x4e11('0x23')](_0x3edc52,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x4e11('0xe')]=function(_0x335dfe){try{if(this['isNotNull'](_0x335dfe)){if(this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]]){this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]]['dialstatus']=_0x335dfe[_0x4e11('0x24')];if(_0x335dfe[_0x4e11('0x24')]===_0x4e11('0x25')){this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]][_0x4e11('0x26')]=_0x335dfe['connectedlinenum'];this['channels'][_0x335dfe[_0x4e11('0x17')]][_0x4e11('0x27')]=_0x335dfe[_0x4e11('0x27')];this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]][_0x4e11('0x28')]=moment()['format'](_0x4e11('0x19'));this[_0x4e11('0x7')][_0x335dfe['uniqueid']][_0x4e11('0x29')]='connect';ami[_0x4e11('0x16')]('custom:dialconnect',this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]]);}this[_0x4e11('0x16')]('voice:outbound','voice_outbound_channel:save',this[_0x4e11('0x7')][_0x335dfe[_0x4e11('0x17')]]);}}}catch(_0x174ede){logger[_0x4e11('0x21')]('[syncDialEnd][VoiceDialReport]',util['inspect'](_0x174ede,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype'][_0x4e11('0x10')]=function(_0x1c49a1){try{if(this[_0x4e11('0x14')](_0x1c49a1)){this['addVariable'](_0x1c49a1['uniqueid'],_[_0x4e11('0x2a')](_0x1c49a1[_0x4e11('0x2b')])[0x0],_0x1c49a1[_0x4e11('0x2c')]);if(this[_0x4e11('0x14')](_0x1c49a1['variable'])&&this[_0x4e11('0x14')](_0x1c49a1['variable'][_0x4e11('0x2d')])){if(_['isUndefined'](this[_0x4e11('0x7')][_0x1c49a1[_0x4e11('0x17')]])){this[_0x4e11('0x7')][_0x1c49a1[_0x4e11('0x17')]]={'routeId':_0x1c49a1[_0x4e11('0x2c')],'variables':this['variables'][_0x1c49a1['uniqueid']]};this[_0x4e11('0x16')](_0x4e11('0x1f'),_0x4e11('0x2e'),this[_0x4e11('0x7')][_0x1c49a1[_0x4e11('0x17')]]);}}}}catch(_0x47e921){logger[_0x4e11('0x21')](_0x4e11('0x2f'),util['inspect'](_0x47e921,{'showHidden':![],'depth':null}));}};VoiceDialReport['prototype']['addVariable']=function(_0x20b7c3,_0x5c42f7,_0x5c07a5){if(_[_0x4e11('0x15')](this[_0x4e11('0xa')][_0x20b7c3])){this['variables'][_0x20b7c3]={};}this['variables'][_0x20b7c3][_0x5c42f7]=_0x5c07a5;};VoiceDialReport[_0x4e11('0x13')]['syncHangup']=function(_0x240eff){try{if(this['isNotNull'](_0x240eff)){if(this[_0x4e11('0x7')][_0x240eff['uniqueid']]){this['channels'][_0x240eff[_0x4e11('0x17')]]['endtime']=moment()[_0x4e11('0x18')](_0x4e11('0x19'));this['channels'][_0x240eff['uniqueid']]['duration']=moment(this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]]['endtime'])[_0x4e11('0x30')](this['channels'][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x31')],_0x4e11('0x32'));this['channels'][_0x240eff[_0x4e11('0x17')]]['lastevent']=_0x4e11('0x33');this[_0x4e11('0x9')][_0x4e11('0x34')]+=0x1;if(this[_0x4e11('0x7')][_0x240eff['uniqueid']][_0x4e11('0x28')]){this['outbound'][_0x4e11('0x35')]+=0x1;this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x36')]=moment(this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x28')])[_0x4e11('0x30')](this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x31')],'seconds');this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x37')]=moment(this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x38')])['diff'](this[_0x4e11('0x7')][_0x240eff['uniqueid']]['answertime'],_0x4e11('0x32'));this['outbound'][_0x4e11('0x39')]+=this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x36')];this[_0x4e11('0x9')][_0x4e11('0x3a')]+=this[_0x4e11('0x7')][_0x240eff['uniqueid']][_0x4e11('0x37')];}this[_0x4e11('0x9')]['sumDuration']+=this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]][_0x4e11('0x3b')];ami[_0x4e11('0x16')](_0x4e11('0x3c'),this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]]);ami[_0x4e11('0x16')]('custom:dialend',this[_0x4e11('0x7')][_0x240eff[_0x4e11('0x17')]]);this[_0x4e11('0x16')](_0x4e11('0x1f'),_0x4e11('0x3d'),this['outbound']);this[_0x4e11('0x16')](_0x4e11('0x1f'),_0x4e11('0x3e'),this['channels'][_0x240eff[_0x4e11('0x17')]]);delete this[_0x4e11('0x7')][_0x240eff['uniqueid']];}if(this[_0x4e11('0xa')][_0x240eff['uniqueid']]){delete this[_0x4e11('0xa')][_0x240eff[_0x4e11('0x17')]];}}}catch(_0x40ee7a){logger[_0x4e11('0x21')]('[syncHangup][VoiceDialReport]',util[_0x4e11('0x23')](_0x40ee7a,{'showHidden':![],'depth':null}));}};module['exports']=VoiceDialReport;