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