2dd216fc1da88e6d16ddb039d027fe1e13537249
[motion2.git] / server / services / ami / realtime / index.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 _0xf112=['isUndefined','initTelephones','name','initTrunks','initTriggers','initTemplates','templates','zendeskAccounts','initFreshdeskAccounts','initZohoAccounts','initDeskAccounts','initSugarcrmAccounts','initVtigerAccounts','initDynamics365Accounts','merge','initVoiceQueueReports','queuecallerexit','queuecallerabandon','queuecallerleaveAt','diff','queuecallerjoinAt','queuecallercompleteAt','queuecallerabandonAt','queuecallerexitAt','seconds','queuecallercomplete','initVoiceCallReports','duration','disposition','billableseconds','initCampaigns','initVoiceExtensions','voiceExtensions','initCampaignHopperHistory','initFaxAccounts','exports','bluebird','util','../model/agent','../model/telephone','../model/trunk','../model/voiceQueue','../model/template','../model/campaign','../model/voiceExtension','../model/zendeskAccount','../model/salesforceAccount','../model/freshdeskAccount','../model/zohoAccount','../model/vtigerAccount','../model/servicenowAccount','../model/faxAccount','agents','telephones','trunks','voiceQueues','triggers','campaigns','outbound','channels','outboundChannels','timers','salesforceAccounts','sugarcrmAccounts','freshdeskAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','faxAccounts','hasOwnProperty','mapKeys','format','SIP/%s','isNil','interface','total','answered','sumHoldTime','sumDuration','sumBillable','isEmpty','ivrTotalCallsDays','unmanaged','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundRejectCallsDay','outboundReCallsDay','outboundAnswerCallsDay','queueStatusComplete','prototype','mergeFromDatabase','initAgents','length'];(function(_0x2db179,_0x322e47){var _0x3272cd=function(_0x35d24e){while(--_0x35d24e){_0x2db179['push'](_0x2db179['shift']());}};_0x3272cd(++_0x322e47);}(_0xf112,0x1ac));var _0x2f11=function(_0x15876a,_0x15383d){_0x15876a=_0x15876a-0x0;var _0xbd900f=_0xf112[_0x15876a];return _0xbd900f;};'use strict';var BPromise=require(_0x2f11('0x0'));var util=require(_0x2f11('0x1'));var _=require('lodash');var moment=require('moment');var Agent=require(_0x2f11('0x2'));var Telephone=require(_0x2f11('0x3'));var Trunk=require(_0x2f11('0x4'));var VoiceQueue=require(_0x2f11('0x5'));var Trigger=require('../model/trigger');var Template=require(_0x2f11('0x6'));var Campaign=require(_0x2f11('0x7'));var VoiceExtension=require(_0x2f11('0x8'));var ZendeskAccount=require(_0x2f11('0x9'));var SalesforceAccount=require(_0x2f11('0xa'));var FreshdeskAccount=require(_0x2f11('0xb'));var SugarcrmAccount=require('../model/sugarcrmAccount');var ZohoAccount=require(_0x2f11('0xc'));var DeskAccount=require('../model/deskAccount');var VtigerAccount=require(_0x2f11('0xd'));var ServicenowAccount=require(_0x2f11('0xe'));var Dynamics365Account=require('../model/dynamics365Account');var FreshsalesAccount=require('../model/freshsalesAccount');var FaxAccount=require(_0x2f11('0xf'));var Realtime=function(){this[_0x2f11('0x10')]={};this[_0x2f11('0x11')]={};this[_0x2f11('0x12')]={};this[_0x2f11('0x13')]={};this[_0x2f11('0x14')]={};this[_0x2f11('0x15')]={};this['templates']={};this[_0x2f11('0x16')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this['voiceExtensions']={};this[_0x2f11('0x17')]={};this['queueChannels']={};this[_0x2f11('0x18')]={};this[_0x2f11('0x19')]={};this['zendeskAccounts']={};this[_0x2f11('0x1a')]={};this[_0x2f11('0x1b')]={};this[_0x2f11('0x1c')]={};this[_0x2f11('0x1d')]={};this[_0x2f11('0x1e')]={};this[_0x2f11('0x1f')]={};this[_0x2f11('0x20')]={};this[_0x2f11('0x21')]={};this[_0x2f11('0x22')]={};this[_0x2f11('0x23')]={};};function freeIsNotKey(_0x491dea,_0x470c95,_0x3549dc){var _0x3169e9=_['mapKeys'](_0x491dea,function(_0x39ccef,_0x40d6f0){return _0x39ccef[_0x3549dc];});for(var _0x2e8bb7 in _0x470c95){if(_0x470c95[_0x2f11('0x24')](_0x2e8bb7)){if(!_0x3169e9[_0x2e8bb7]){delete _0x470c95[_0x2e8bb7];}}}}function freeIsNotKeySip(_0x1e4f17,_0x5bc359){var _0x279062=_[_0x2f11('0x25')](_0x1e4f17,function(_0x274e53,_0x48d1d2){return util[_0x2f11('0x26')](_0x2f11('0x27'),_0x274e53['name']);});for(var _0x4a761d in _0x5bc359){if(_0x5bc359[_0x2f11('0x24')](_0x4a761d)){if(!_0x279062[_0x4a761d]){delete _0x5bc359[_0x4a761d];}}}}function freeIsNotKeyAgent(_0x2d2466,_0x25b9fc){var _0xe4db95=_['mapKeys'](_0x2d2466,function(_0x3f5073,_0x25a6b0){var _0x5cba58=_[_0x2f11('0x28')](_0x3f5073[_0x2f11('0x29')])?util[_0x2f11('0x26')](_0x2f11('0x27'),_0x3f5073['name']):_0x3f5073[_0x2f11('0x29')];return _0x5cba58;});for(var _0x269746 in _0x25b9fc){if(_0x25b9fc[_0x2f11('0x24')](_0x269746)){if(!_0xe4db95[_0x269746]){delete _0x25b9fc[_0x269746];}}}}function clearVoiceCallReports(_0x118411){_0x118411[_0x2f11('0x2a')]=0x0;_0x118411[_0x2f11('0x2b')]=0x0;_0x118411[_0x2f11('0x2c')]=0x0;_0x118411[_0x2f11('0x2d')]=0x0;_0x118411[_0x2f11('0x2e')]=0x0;}function clearCampaigns(_0x2cfa65){if(!_[_0x2f11('0x2f')](_0x2cfa65)){for(var _0x46b452 in _0x2cfa65){if(_0x2cfa65[_0x2f11('0x24')](_0x46b452)){_0x2cfa65[_0x46b452][_0x2f11('0x30')]=0x0;_0x2cfa65[_0x46b452]['ivrAnswerCallsDay']=0x0;}}}}function clearVoiceQueues(_0x3a5b17){if(!_[_0x2f11('0x2f')](_0x3a5b17)){for(var _0x182aa6 in _0x3a5b17){if(_0x3a5b17[_0x2f11('0x24')](_0x182aa6)){_0x3a5b17[_0x182aa6][_0x2f11('0x2a')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x2b')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x31')]=0x0;_0x3a5b17[_0x182aa6]['abandoned']=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x2c')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x2d')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x2e')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x32')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x33')]=0x0;_0x3a5b17[_0x182aa6]['outboundBusyCallsDay']=0x0;_0x3a5b17[_0x182aa6]['outboundCongestionCallsDay']=0x0;_0x3a5b17[_0x182aa6]['outboundNoSuchCallsDay']=0x0;_0x3a5b17[_0x182aa6]['outboundUnknownCallsDay']=0x0;_0x3a5b17[_0x182aa6]['outboundDropCallsDayTimeout']=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x34')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x35')]=0x0;_0x3a5b17[_0x182aa6]['outboundOriginateFailureCallsDay']=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x36')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x37')]=0x0;_0x3a5b17[_0x182aa6]['outboundAnswerAgiCallsDay']=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x38')]=0x0;_0x3a5b17[_0x182aa6][_0x2f11('0x39')]=!![];}}}}Realtime[_0x2f11('0x3a')][_0x2f11('0x3b')]=function(_0x574209,_0x2d2710){for(var _0x25cd77 in _0x2d2710){if(_0x574209[_0x2f11('0x24')](_0x25cd77)){_0x574209[_0x25cd77]=_0x2d2710[_0x25cd77];}}};Realtime[_0x2f11('0x3a')][_0x2f11('0x3c')]=function(){var _0x209f90=this;return function(_0x1494af){if(_0x1494af){freeIsNotKeyAgent(_0x1494af,_0x209f90['agents']);for(var _0x19225b=0x0,_0x4c6fb8={},_0x1b0f56={};_0x19225b<_0x1494af[_0x2f11('0x3d')];_0x19225b+=0x1){_0x4c6fb8=_0x1494af[_0x19225b];var _0x559476=_[_0x2f11('0x28')](_0x4c6fb8[_0x2f11('0x29')])?util[_0x2f11('0x26')](_0x2f11('0x27'),_0x4c6fb8['name']):_0x4c6fb8[_0x2f11('0x29')];if(_[_0x2f11('0x3e')](_0x209f90[_0x2f11('0x10')][_0x559476])){_0x209f90['agents'][_0x559476]=new Agent(_0x4c6fb8);}else{_0x209f90[_0x2f11('0x3b')](_0x209f90[_0x2f11('0x10')][_0x559476],_0x4c6fb8);}}}return _0x209f90[_0x2f11('0x10')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x3f')]=function(){var _0xa9ed37=this;return function(_0x465810){if(_0x465810){freeIsNotKeySip(_0x465810,_0xa9ed37['telephones']);for(var _0x1cef86=0x0,_0x116546={},_0x120702={};_0x1cef86<_0x465810[_0x2f11('0x3d')];_0x1cef86+=0x1){_0x116546=_0x465810[_0x1cef86];if(_[_0x2f11('0x3e')](_0xa9ed37[_0x2f11('0x11')][util[_0x2f11('0x26')](_0x2f11('0x27'),_0x116546[_0x2f11('0x40')])])){_0xa9ed37[_0x2f11('0x11')][util[_0x2f11('0x26')](_0x2f11('0x27'),_0x116546['name'])]=new Telephone(_0x116546);}else{_0xa9ed37[_0x2f11('0x3b')](_0xa9ed37[_0x2f11('0x11')][util[_0x2f11('0x26')](_0x2f11('0x27'),_0x116546[_0x2f11('0x40')])],_0x116546);}}}return _0xa9ed37[_0x2f11('0x11')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x41')]=function(){var _0x2e09c3=this;return function(_0x52c4cd){if(_0x52c4cd){freeIsNotKeySip(_0x52c4cd,_0x2e09c3[_0x2f11('0x12')]);for(var _0x136ede=0x0,_0x208eec={},_0x113c2c={};_0x136ede<_0x52c4cd[_0x2f11('0x3d')];_0x136ede+=0x1){_0x208eec=_0x52c4cd[_0x136ede];if(_[_0x2f11('0x3e')](_0x2e09c3[_0x2f11('0x12')][util[_0x2f11('0x26')](_0x2f11('0x27'),_0x208eec[_0x2f11('0x40')])])){_0x2e09c3['trunks'][util[_0x2f11('0x26')](_0x2f11('0x27'),_0x208eec[_0x2f11('0x40')])]=new Trunk(_0x208eec);}else{_0x2e09c3[_0x2f11('0x3b')](_0x2e09c3[_0x2f11('0x12')][util[_0x2f11('0x26')]('SIP/%s',_0x208eec[_0x2f11('0x40')])],_0x208eec);}}}return _0x2e09c3[_0x2f11('0x12')];};};Realtime[_0x2f11('0x3a')]['initVoiceQueues']=function(){var _0x824436=this;return function(_0x39c616){if(_0x39c616){freeIsNotKey(_0x39c616,_0x824436[_0x2f11('0x13')],_0x2f11('0x40'));for(var _0x40875a=0x0,_0x5c2b79={},_0x3ae1b9={};_0x40875a<_0x39c616[_0x2f11('0x3d')];_0x40875a+=0x1){_0x5c2b79=_0x39c616[_0x40875a];if(_[_0x2f11('0x3e')](_0x824436['voiceQueues'][_0x5c2b79[_0x2f11('0x40')]])){_0x824436[_0x2f11('0x13')][_0x5c2b79[_0x2f11('0x40')]]=new VoiceQueue(_0x5c2b79);}else{_0x824436[_0x2f11('0x3b')](_0x824436[_0x2f11('0x13')][_0x5c2b79[_0x2f11('0x40')]],_0x5c2b79);}}}return _0x824436[_0x2f11('0x13')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x42')]=function(){var _0x2db3ec=this;return function(_0x3089d6){if(_0x3089d6){freeIsNotKey(_0x3089d6,_0x2db3ec[_0x2f11('0x14')],'id');for(var _0x46554d=0x0,_0x30451d={},_0x5a680b={};_0x46554d<_0x3089d6['length'];_0x46554d+=0x1){_0x30451d=_0x3089d6[_0x46554d];if(_['isUndefined'](_0x2db3ec['triggers'][_0x30451d['id']])){_0x2db3ec[_0x2f11('0x14')][_0x30451d['id']]=new Trigger(_0x30451d);}else{_0x2db3ec['mergeFromDatabase'](_0x2db3ec[_0x2f11('0x14')][_0x30451d['id']],_0x30451d);}}}return _0x2db3ec[_0x2f11('0x14')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x43')]=function(){var _0x2508b6=this;return function(_0x17813f){if(_0x17813f){freeIsNotKey(_0x17813f,_0x2508b6[_0x2f11('0x44')],'id');for(var _0x3bdfe6=0x0,_0x28f374={},_0xcf9494={};_0x3bdfe6<_0x17813f[_0x2f11('0x3d')];_0x3bdfe6+=0x1){_0x28f374=_0x17813f[_0x3bdfe6];if(_[_0x2f11('0x3e')](_0x2508b6[_0x2f11('0x44')][_0x28f374['id']])){_0x2508b6[_0x2f11('0x44')][_0x28f374['id']]=new Template(_0x28f374);}else{_0x2508b6['mergeFromDatabase'](_0x2508b6[_0x2f11('0x44')][_0x28f374['id']],_0x28f374);}}}return _0x2508b6[_0x2f11('0x44')];};};Realtime['prototype']['initZendeskAccounts']=function(){var _0x27da48=this;return function(_0x300f23){if(_0x300f23){freeIsNotKey(_0x300f23,_0x27da48[_0x2f11('0x45')],'id');for(var _0xd4bc35=0x0,_0xf749ef={},_0x5c7529={};_0xd4bc35<_0x300f23[_0x2f11('0x3d')];_0xd4bc35+=0x1){_0xf749ef=_0x300f23[_0xd4bc35];if(_[_0x2f11('0x3e')](_0x27da48[_0x2f11('0x45')][_0xf749ef['id']])){_0x27da48[_0x2f11('0x45')][_0xf749ef['id']]=new ZendeskAccount(_0xf749ef);}else{_0x27da48[_0x2f11('0x3b')](_0x27da48['zendeskAccounts'][_0xf749ef['id']],_0xf749ef);}}}return _0x27da48[_0x2f11('0x45')];};};Realtime[_0x2f11('0x3a')]['initSalesforceAccounts']=function(){var _0x25f78d=this;return function(_0x12000e){if(_0x12000e){freeIsNotKey(_0x12000e,_0x25f78d[_0x2f11('0x1a')],'id');for(var _0x1a4a08=0x0,_0x4f82e5={},_0x35e0ff={};_0x1a4a08<_0x12000e['length'];_0x1a4a08+=0x1){_0x4f82e5=_0x12000e[_0x1a4a08];if(_[_0x2f11('0x3e')](_0x25f78d['salesforceAccounts'][_0x4f82e5['id']])){_0x25f78d[_0x2f11('0x1a')][_0x4f82e5['id']]=new SalesforceAccount(_0x4f82e5);}else{_0x25f78d[_0x2f11('0x3b')](_0x25f78d[_0x2f11('0x1a')][_0x4f82e5['id']],_0x4f82e5);}}}return _0x25f78d[_0x2f11('0x1a')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x46')]=function(){var _0x23c343=this;return function(_0x493435){if(_0x493435){freeIsNotKey(_0x493435,_0x23c343[_0x2f11('0x1c')],'id');for(var _0x43a687=0x0,_0x5f56bb={},_0x57293c={};_0x43a687<_0x493435[_0x2f11('0x3d')];_0x43a687+=0x1){_0x5f56bb=_0x493435[_0x43a687];if(_[_0x2f11('0x3e')](_0x23c343['freshdeskAccounts'][_0x5f56bb['id']])){_0x23c343[_0x2f11('0x1c')][_0x5f56bb['id']]=new FreshdeskAccount(_0x5f56bb);}else{_0x23c343['mergeFromDatabase'](_0x23c343[_0x2f11('0x1c')][_0x5f56bb['id']],_0x5f56bb);}}}return _0x23c343['freshdeskAccounts'];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x47')]=function(){var _0x1d027f=this;return function(_0x1aa0d8){if(_0x1aa0d8){freeIsNotKey(_0x1aa0d8,_0x1d027f[_0x2f11('0x1d')],'id');for(var _0x16257f=0x0,_0x524184={},_0xa924ca={};_0x16257f<_0x1aa0d8[_0x2f11('0x3d')];_0x16257f+=0x1){_0x524184=_0x1aa0d8[_0x16257f];if(_[_0x2f11('0x3e')](_0x1d027f['zohoAccounts'][_0x524184['id']])){_0x1d027f['zohoAccounts'][_0x524184['id']]=new ZohoAccount(_0x524184);}else{_0x1d027f['mergeFromDatabase'](_0x1d027f[_0x2f11('0x1d')][_0x524184['id']],_0x524184);}}}return _0x1d027f[_0x2f11('0x1d')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x48')]=function(){var _0x147b0f=this;return function(_0x5a20c8){if(_0x5a20c8){freeIsNotKey(_0x5a20c8,_0x147b0f['deskAccounts'],'id');for(var _0x4ce4b9=0x0,_0x15db8d={},_0x2d2240={};_0x4ce4b9<_0x5a20c8['length'];_0x4ce4b9+=0x1){_0x15db8d=_0x5a20c8[_0x4ce4b9];if(_['isUndefined'](_0x147b0f[_0x2f11('0x1e')][_0x15db8d['id']])){_0x147b0f[_0x2f11('0x1e')][_0x15db8d['id']]=new DeskAccount(_0x15db8d);}else{_0x147b0f[_0x2f11('0x3b')](_0x147b0f['deskAccounts'][_0x15db8d['id']],_0x15db8d);}}}return _0x147b0f['deskAccounts'];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x49')]=function(){var _0x5d645d=this;return function(_0x1d6fdd){if(_0x1d6fdd){freeIsNotKey(_0x1d6fdd,_0x5d645d[_0x2f11('0x1b')],'id');for(var _0x29b978=0x0,_0x4fb660={},_0x1c30b1={};_0x29b978<_0x1d6fdd[_0x2f11('0x3d')];_0x29b978+=0x1){_0x4fb660=_0x1d6fdd[_0x29b978];if(_[_0x2f11('0x3e')](_0x5d645d[_0x2f11('0x1b')][_0x4fb660['id']])){_0x5d645d[_0x2f11('0x1b')][_0x4fb660['id']]=new SugarcrmAccount(_0x4fb660);}else{_0x5d645d['mergeFromDatabase'](_0x5d645d['sugarcrmAccounts'][_0x4fb660['id']],_0x4fb660);}}}return _0x5d645d['sugarcrmAccounts'];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x4a')]=function(){var _0x9f7dfc=this;return function(_0x4c68b2){if(_0x4c68b2){freeIsNotKey(_0x4c68b2,_0x9f7dfc[_0x2f11('0x1f')],'id');for(var _0x2f3e42=0x0,_0x3c909b={},_0x9277dc={};_0x2f3e42<_0x4c68b2[_0x2f11('0x3d')];_0x2f3e42+=0x1){_0x3c909b=_0x4c68b2[_0x2f3e42];if(_[_0x2f11('0x3e')](_0x9f7dfc[_0x2f11('0x1f')][_0x3c909b['id']])){_0x9f7dfc[_0x2f11('0x1f')][_0x3c909b['id']]=new VtigerAccount(_0x3c909b);}else{_0x9f7dfc['mergeFromDatabase'](_0x9f7dfc[_0x2f11('0x1f')][_0x3c909b['id']],_0x3c909b);}}}return _0x9f7dfc[_0x2f11('0x1f')];};};Realtime['prototype']['initServicenowAccounts']=function(){var _0x12db7b=this;return function(_0x3532bb){if(_0x3532bb){freeIsNotKey(_0x3532bb,_0x12db7b[_0x2f11('0x20')],'id');for(var _0x28cbc2=0x0,_0x2d0657={},_0x1e9e25={};_0x28cbc2<_0x3532bb[_0x2f11('0x3d')];_0x28cbc2+=0x1){_0x2d0657=_0x3532bb[_0x28cbc2];if(_[_0x2f11('0x3e')](_0x12db7b[_0x2f11('0x20')][_0x2d0657['id']])){_0x12db7b[_0x2f11('0x20')][_0x2d0657['id']]=new ServicenowAccount(_0x2d0657);}else{_0x12db7b[_0x2f11('0x3b')](_0x12db7b[_0x2f11('0x20')][_0x2d0657['id']],_0x2d0657);}}}return _0x12db7b[_0x2f11('0x20')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x4b')]=function(){var _0x483959=this;return function(_0x20cfde){if(_0x20cfde){freeIsNotKey(_0x20cfde,_0x483959['dynamics365Accounts'],'id');for(var _0x59522d=0x0,_0xc17c23={},_0x47a427={};_0x59522d<_0x20cfde['length'];_0x59522d+=0x1){_0xc17c23=_0x20cfde[_0x59522d];if(_[_0x2f11('0x3e')](_0x483959[_0x2f11('0x21')][_0xc17c23['id']])){_0x483959[_0x2f11('0x21')][_0xc17c23['id']]=new Dynamics365Account(_0xc17c23);}else{_0x483959['mergeFromDatabase'](_0x483959[_0x2f11('0x21')][_0xc17c23['id']],_0xc17c23);}}}return _0x483959[_0x2f11('0x21')];};};Realtime[_0x2f11('0x3a')]['initFreshsalesAccounts']=function(){var _0x2356a2=this;return function(_0x1292be){if(_0x1292be){freeIsNotKey(_0x1292be,_0x2356a2['freshsalesAccounts'],'id');for(var _0x2b9afa=0x0,_0x159813={},_0x3bfd2e={};_0x2b9afa<_0x1292be[_0x2f11('0x3d')];_0x2b9afa+=0x1){_0x159813=_0x1292be[_0x2b9afa];if(_[_0x2f11('0x3e')](_0x2356a2[_0x2f11('0x22')][_0x159813['id']])){_0x2356a2[_0x2f11('0x22')][_0x159813['id']]=new FreshsalesAccount(_0x159813);}else{_0x2356a2['mergeFromDatabase'](_0x2356a2['freshsalesAccounts'][_0x159813['id']],_0x159813);}}}return _0x2356a2[_0x2f11('0x22')];};};Realtime['prototype']['initVoiceQueueHopperHistory']=function(){var _0x1d7229=this;return function(_0x508569){for(var _0x4b8cbb=0x0;_0x4b8cbb<_0x508569[_0x2f11('0x3d')];_0x4b8cbb+=0x1){_[_0x2f11('0x4c')](_0x1d7229[_0x2f11('0x13')][_0x508569[_0x4b8cbb][_0x2f11('0x40')]],_0x508569[_0x4b8cbb]);}return _0x1d7229[_0x2f11('0x13')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x4d')]=function(){var _0x5bce5b=this;return function(_0x4aa94d){clearVoiceQueues(_0x5bce5b['voiceQueues']);if(_0x4aa94d){_0x4aa94d=_['groupBy'](_0x4aa94d,'uniqueid');for(var _0x2ee93d in _0x4aa94d){if(_0x4aa94d[_0x2f11('0x24')](_0x2ee93d)){var _0x41595d={};for(var _0x551fc5=0x0;_0x551fc5<_0x4aa94d[_0x2ee93d]['length'];_0x551fc5+=0x1){var _0x19e035=_0x4aa94d[_0x2ee93d][_0x551fc5]['queue'];if(_0x5bce5b['voiceQueues'][_0x19e035]){if(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x4e')]){_0x5bce5b['voiceQueues'][_0x19e035][_0x2f11('0x31')]+=0x1;}if(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x4f')]){_0x5bce5b[_0x2f11('0x13')][_0x19e035]['abandoned']+=0x1;}_0x5bce5b[_0x2f11('0x13')][_0x19e035][_0x2f11('0x2c')]+=moment(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x50')])[_0x2f11('0x51')](moment(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x52')]),'seconds')||0x0;if(_0x551fc5===_0x4aa94d[_0x2ee93d][_0x2f11('0x3d')]-0x1){_0x5bce5b[_0x2f11('0x13')][_0x19e035][_0x2f11('0x2d')]+=moment(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x53')]||_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x54')]||_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x55')])[_0x2f11('0x51')](moment(_0x4aa94d[_0x2ee93d][_0x551fc5]['queuecallerjoinAt']),_0x2f11('0x56'))||0x0;_0x5bce5b[_0x2f11('0x13')][_0x19e035][_0x2f11('0x2a')]+=0x1;if(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x57')]){_0x5bce5b[_0x2f11('0x13')][_0x19e035]['answered']+=0x1;_0x5bce5b[_0x2f11('0x13')][_0x19e035][_0x2f11('0x2e')]+=moment(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x53')])[_0x2f11('0x51')](moment(_0x4aa94d[_0x2ee93d][_0x551fc5][_0x2f11('0x50')]),_0x2f11('0x56'))||0x0;}}else{_0x5bce5b['voiceQueues'][_0x19e035]['sumDuration']+=_0x5bce5b[_0x2f11('0x13')][_0x19e035]['sumHoldTime']||0x0;}}}}}}return _0x5bce5b['voiceQueues'];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x58')]=function(){var _0x23562f=this;return function(_0x345ea8){clearVoiceCallReports(_0x23562f[_0x2f11('0x16')]);if(_0x345ea8){for(var _0x305b27=0x0;_0x305b27<_0x345ea8['length'];_0x305b27+=0x1){_0x23562f[_0x2f11('0x16')]['total']+=0x1;_0x23562f['outbound'][_0x2f11('0x2d')]+=_0x345ea8[_0x305b27][_0x2f11('0x59')];if(_0x345ea8[_0x305b27][_0x2f11('0x5a')]==='ANSWERED'){_0x23562f['outbound'][_0x2f11('0x2b')]+=0x1;_0x23562f[_0x2f11('0x16')]['sumHoldTime']+=_0x345ea8[_0x305b27][_0x2f11('0x59')]-_0x345ea8[_0x305b27][_0x2f11('0x5b')]||0x0;_0x23562f[_0x2f11('0x16')]['sumBillable']+=_0x345ea8[_0x305b27][_0x2f11('0x5b')];}}}return _0x23562f[_0x2f11('0x16')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x5c')]=function(){var _0x38dc1f=this;return function(_0x5ee1c7){if(_0x5ee1c7){freeIsNotKey(_0x5ee1c7,_0x38dc1f['campaigns'],_0x2f11('0x40'));for(var _0x1b32b0=0x0,_0x453900={};_0x1b32b0<_0x5ee1c7[_0x2f11('0x3d')];_0x1b32b0+=0x1){_0x453900=_0x5ee1c7[_0x1b32b0];if(_['isUndefined'](_0x38dc1f['campaigns'][_0x453900[_0x2f11('0x40')]])){_0x38dc1f['campaigns'][_0x453900[_0x2f11('0x40')]]=new Campaign(_0x453900);}else{_0x38dc1f[_0x2f11('0x3b')](_0x38dc1f['campaigns'][_0x453900['name']],_0x453900);}}}return _0x38dc1f[_0x2f11('0x15')];};};Realtime[_0x2f11('0x3a')][_0x2f11('0x5d')]=function(){var _0x3389=this;return function(_0x191f30){if(_0x191f30){freeIsNotKey(_0x191f30,_0x3389['voiceExtensions'],'id');for(var _0x48b2a8=0x0,_0x588522={};_0x48b2a8<_0x191f30[_0x2f11('0x3d')];_0x48b2a8+=0x1){_0x588522=_0x191f30[_0x48b2a8];if(_[_0x2f11('0x3e')](_0x3389[_0x2f11('0x5e')][_0x588522['id']])){_0x3389[_0x2f11('0x5e')][_0x588522['id']]=new VoiceExtension(_0x588522);}else{_0x3389[_0x2f11('0x3b')](_0x3389[_0x2f11('0x5e')][_0x588522['id']],_0x588522);}}}return _0x3389[_0x2f11('0x5e')];};};Realtime['prototype'][_0x2f11('0x5f')]=function(){var _0x594f11=this;return function(_0x848982){clearCampaigns(_0x594f11[_0x2f11('0x15')]);for(var _0x117db2=0x0;_0x117db2<_0x848982[_0x2f11('0x3d')];_0x117db2+=0x1){_['merge'](_0x594f11[_0x2f11('0x15')][_0x848982[_0x117db2]['name']],_0x848982[_0x117db2]);}return _0x594f11['campaigns'];};};Realtime['prototype'][_0x2f11('0x60')]=function(){var _0x30704e=this;return function(_0x305ddb){if(_0x305ddb){freeIsNotKey(_0x305ddb,_0x30704e[_0x2f11('0x23')],'id');for(var _0x5449f5=0x0,_0x15cdbc={},_0x266adf={};_0x5449f5<_0x305ddb[_0x2f11('0x3d')];_0x5449f5+=0x1){_0x15cdbc=_0x305ddb[_0x5449f5];if(_[_0x2f11('0x3e')](_0x30704e['faxAccounts'][_0x15cdbc['id']])){_0x30704e[_0x2f11('0x23')][_0x15cdbc['id']]=new FaxAccount(_0x15cdbc);}else{_0x30704e['mergeFromDatabase'](_0x30704e[_0x2f11('0x23')][_0x15cdbc['id']],_0x15cdbc);}}}return _0x30704e[_0x2f11('0x23')];};};module[_0x2f11('0x61')]=Realtime;