Built motion from commit (unavailable).|2.5.3
[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 _0x4cfd=['initTemplates','initZendeskAccounts','initSalesforceAccounts','initFreshdeskAccounts','freshdeskAccounts','initZohoAccounts','initDeskAccounts','initSugarcrmAccounts','sugarcrmAccounts','initVtigerAccounts','initServicenowAccounts','initDynamics365Accounts','initFreshsalesAccounts','initVoiceQueueHopperHistory','merge','initVoiceQueueReports','groupBy','uniqueid','queuecallerexit','queuecallerabandon','queuecallerleaveAt','diff','queuecallerjoinAt','queuecallercompleteAt','queuecallerabandonAt','queuecallerexitAt','seconds','duration','disposition','ANSWERED','billableseconds','initCampaigns','campaigns','dialQueueProject','SquareProject','initVoiceExtensions','voiceExtensions','initCampaignHopperHistory','faxAccounts','exports','bluebird','lodash','moment','../model/agent','../model/telephone','../model/trunk','../model/voiceQueue','../model/trigger','../model/campaign','../model/voiceExtension','../model/salesforceAccount','../model/freshdeskAccount','../model/zohoAccount','../model/deskAccount','../model/servicenowAccount','../model/dynamics365Account','../model/freshsalesAccount','../model/faxAccount','agents','trunks','voiceQueues','triggers','templates','outbound','channels','queueChannels','outboundChannels','timers','zendeskAccounts','salesforceAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','mapKeys','format','SIP/%s','name','hasOwnProperty','isNil','interface','total','answered','sumHoldTime','sumDuration','sumBillable','isEmpty','ivrAnswerCallsDay','unmanaged','abandoned','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundUnknownCallsDay','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundReCallsDay','outboundAnswerCallsDay','prototype','mergeFromDatabase','initAgents','length','initTelephones','telephones','initTrunks','isUndefined','initVoiceQueues','initTriggers'];(function(_0x358858,_0x2c2e69){var _0x24ca83=function(_0x8a59d4){while(--_0x8a59d4){_0x358858['push'](_0x358858['shift']());}};_0x24ca83(++_0x2c2e69);}(_0x4cfd,0x178));var _0xd4cf=function(_0xfa634c,_0x414e0e){_0xfa634c=_0xfa634c-0x0;var _0x73e478=_0x4cfd[_0xfa634c];return _0x73e478;};'use strict';var BPromise=require(_0xd4cf('0x0'));var util=require('util');var _=require(_0xd4cf('0x1'));var moment=require(_0xd4cf('0x2'));var Agent=require(_0xd4cf('0x3'));var Telephone=require(_0xd4cf('0x4'));var Trunk=require(_0xd4cf('0x5'));var VoiceQueue=require(_0xd4cf('0x6'));var Trigger=require(_0xd4cf('0x7'));var Template=require('../model/template');var Campaign=require(_0xd4cf('0x8'));var VoiceExtension=require(_0xd4cf('0x9'));var ZendeskAccount=require('../model/zendeskAccount');var SalesforceAccount=require(_0xd4cf('0xa'));var FreshdeskAccount=require(_0xd4cf('0xb'));var SugarcrmAccount=require('../model/sugarcrmAccount');var ZohoAccount=require(_0xd4cf('0xc'));var DeskAccount=require(_0xd4cf('0xd'));var VtigerAccount=require('../model/vtigerAccount');var ServicenowAccount=require(_0xd4cf('0xe'));var Dynamics365Account=require(_0xd4cf('0xf'));var FreshsalesAccount=require(_0xd4cf('0x10'));var FaxAccount=require(_0xd4cf('0x11'));var Realtime=function(){this[_0xd4cf('0x12')]={};this['telephones']={};this[_0xd4cf('0x13')]={};this[_0xd4cf('0x14')]={};this[_0xd4cf('0x15')]={};this['campaigns']={};this[_0xd4cf('0x16')]={};this[_0xd4cf('0x17')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this['voiceExtensions']={};this[_0xd4cf('0x18')]={};this[_0xd4cf('0x19')]={};this[_0xd4cf('0x1a')]={};this[_0xd4cf('0x1b')]={};this[_0xd4cf('0x1c')]={};this[_0xd4cf('0x1d')]={};this['sugarcrmAccounts']={};this['freshdeskAccounts']={};this[_0xd4cf('0x1e')]={};this[_0xd4cf('0x1f')]={};this[_0xd4cf('0x20')]={};this[_0xd4cf('0x21')]={};this[_0xd4cf('0x22')]={};this[_0xd4cf('0x23')]={};this['faxAccounts']={};};function freeIsNotKey(_0xe243bc,_0x52f73a,_0x356b1b){var _0x16d796=_[_0xd4cf('0x24')](_0xe243bc,function(_0x5e5b1e,_0x2e23d0){return _0x5e5b1e[_0x356b1b];});for(var _0x196c2c in _0x52f73a){if(_0x52f73a['hasOwnProperty'](_0x196c2c)){if(!_0x16d796[_0x196c2c]){delete _0x52f73a[_0x196c2c];}}}}function freeIsNotKeySip(_0xe76b87,_0x3c2101){var _0xf5c4c2=_[_0xd4cf('0x24')](_0xe76b87,function(_0x4c76c3,_0xc7537c){return util[_0xd4cf('0x25')](_0xd4cf('0x26'),_0x4c76c3[_0xd4cf('0x27')]);});for(var _0x54b99c in _0x3c2101){if(_0x3c2101[_0xd4cf('0x28')](_0x54b99c)){if(!_0xf5c4c2[_0x54b99c]){delete _0x3c2101[_0x54b99c];}}}}function freeIsNotKeyAgent(_0x142321,_0x19fb08){var _0x11bcd9=_[_0xd4cf('0x24')](_0x142321,function(_0x246905,_0xcb22f0){var _0x1e559b=_[_0xd4cf('0x29')](_0x246905[_0xd4cf('0x2a')])?util['format'](_0xd4cf('0x26'),_0x246905['name']):_0x246905[_0xd4cf('0x2a')];return _0x1e559b;});for(var _0x33ac6b in _0x19fb08){if(_0x19fb08['hasOwnProperty'](_0x33ac6b)){if(!_0x11bcd9[_0x33ac6b]){delete _0x19fb08[_0x33ac6b];}}}}function clearVoiceCallReports(_0x5723a8){_0x5723a8[_0xd4cf('0x2b')]=0x0;_0x5723a8[_0xd4cf('0x2c')]=0x0;_0x5723a8[_0xd4cf('0x2d')]=0x0;_0x5723a8[_0xd4cf('0x2e')]=0x0;_0x5723a8[_0xd4cf('0x2f')]=0x0;}function clearCampaigns(_0x377987){if(!_[_0xd4cf('0x30')](_0x377987)){for(var _0x6149a0 in _0x377987){if(_0x377987[_0xd4cf('0x28')](_0x6149a0)){_0x377987[_0x6149a0]['ivrTotalCallsDays']=0x0;_0x377987[_0x6149a0][_0xd4cf('0x31')]=0x0;}}}}function clearVoiceQueues(_0x4684f1){if(!_['isEmpty'](_0x4684f1)){for(var _0x444637 in _0x4684f1){if(_0x4684f1['hasOwnProperty'](_0x444637)){_0x4684f1[_0x444637][_0xd4cf('0x2b')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x2c')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x32')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x33')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x2d')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x2e')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x2f')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x34')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x35')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x36')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x37')]=0x0;_0x4684f1[_0x444637]['outboundNoSuchCallsDay']=0x0;_0x4684f1[_0x444637][_0xd4cf('0x38')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x39')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x3a')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x3b')]=0x0;_0x4684f1[_0x444637]['outboundOriginateFailureCallsDay']=0x0;_0x4684f1[_0x444637]['outboundRejectCallsDay']=0x0;_0x4684f1[_0x444637][_0xd4cf('0x3c')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x34')]=0x0;_0x4684f1[_0x444637][_0xd4cf('0x3d')]=0x0;_0x4684f1[_0x444637]['queueStatusComplete']=!![];}}}}Realtime[_0xd4cf('0x3e')][_0xd4cf('0x3f')]=function(_0x469c6f,_0x181c69){for(var _0x2c32f6 in _0x181c69){if(_0x469c6f[_0xd4cf('0x28')](_0x2c32f6)){_0x469c6f[_0x2c32f6]=_0x181c69[_0x2c32f6];}}};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x40')]=function(){var _0x25e517=this;return function(_0xf6c2ed){if(_0xf6c2ed){freeIsNotKeyAgent(_0xf6c2ed,_0x25e517['agents']);for(var _0x7ccfa2=0x0,_0x706f2={},_0x46b234={};_0x7ccfa2<_0xf6c2ed[_0xd4cf('0x41')];_0x7ccfa2+=0x1){_0x706f2=_0xf6c2ed[_0x7ccfa2];var _0x59fcf7=_[_0xd4cf('0x29')](_0x706f2['interface'])?util['format']('SIP/%s',_0x706f2[_0xd4cf('0x27')]):_0x706f2[_0xd4cf('0x2a')];if(_['isUndefined'](_0x25e517['agents'][_0x59fcf7])){_0x25e517[_0xd4cf('0x12')][_0x59fcf7]=new Agent(_0x706f2);}else{_0x25e517[_0xd4cf('0x3f')](_0x25e517[_0xd4cf('0x12')][_0x59fcf7],_0x706f2);}}}return _0x25e517['agents'];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x42')]=function(){var _0x342c72=this;return function(_0x44adfe){if(_0x44adfe){freeIsNotKeySip(_0x44adfe,_0x342c72[_0xd4cf('0x43')]);for(var _0x4349f9=0x0,_0x331d0c={},_0x599402={};_0x4349f9<_0x44adfe[_0xd4cf('0x41')];_0x4349f9+=0x1){_0x331d0c=_0x44adfe[_0x4349f9];if(_['isUndefined'](_0x342c72[_0xd4cf('0x43')][util['format'](_0xd4cf('0x26'),_0x331d0c[_0xd4cf('0x27')])])){_0x342c72['telephones'][util[_0xd4cf('0x25')]('SIP/%s',_0x331d0c[_0xd4cf('0x27')])]=new Telephone(_0x331d0c);}else{_0x342c72[_0xd4cf('0x3f')](_0x342c72[_0xd4cf('0x43')][util[_0xd4cf('0x25')](_0xd4cf('0x26'),_0x331d0c[_0xd4cf('0x27')])],_0x331d0c);}}}return _0x342c72['telephones'];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x44')]=function(){var _0x3bbeeb=this;return function(_0x3ec8c4){if(_0x3ec8c4){freeIsNotKeySip(_0x3ec8c4,_0x3bbeeb[_0xd4cf('0x13')]);for(var _0x3973b3=0x0,_0x2aefa3={},_0x1e7e8e={};_0x3973b3<_0x3ec8c4[_0xd4cf('0x41')];_0x3973b3+=0x1){_0x2aefa3=_0x3ec8c4[_0x3973b3];if(_[_0xd4cf('0x45')](_0x3bbeeb[_0xd4cf('0x13')][util['format'](_0xd4cf('0x26'),_0x2aefa3[_0xd4cf('0x27')])])){_0x3bbeeb[_0xd4cf('0x13')][util[_0xd4cf('0x25')](_0xd4cf('0x26'),_0x2aefa3[_0xd4cf('0x27')])]=new Trunk(_0x2aefa3);}else{_0x3bbeeb['mergeFromDatabase'](_0x3bbeeb[_0xd4cf('0x13')][util[_0xd4cf('0x25')]('SIP/%s',_0x2aefa3[_0xd4cf('0x27')])],_0x2aefa3);}}}return _0x3bbeeb['trunks'];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x46')]=function(){var _0x48fae0=this;return function(_0x2e713b){if(_0x2e713b){freeIsNotKey(_0x2e713b,_0x48fae0[_0xd4cf('0x14')],_0xd4cf('0x27'));for(var _0x347637=0x0,_0x34ed7d={},_0x3e0f3c={};_0x347637<_0x2e713b[_0xd4cf('0x41')];_0x347637+=0x1){_0x34ed7d=_0x2e713b[_0x347637];if(_[_0xd4cf('0x45')](_0x48fae0[_0xd4cf('0x14')][_0x34ed7d[_0xd4cf('0x27')]])){_0x48fae0[_0xd4cf('0x14')][_0x34ed7d[_0xd4cf('0x27')]]=new VoiceQueue(_0x34ed7d);}else{_0x48fae0[_0xd4cf('0x3f')](_0x48fae0[_0xd4cf('0x14')][_0x34ed7d[_0xd4cf('0x27')]],_0x34ed7d);}}}return _0x48fae0[_0xd4cf('0x14')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x47')]=function(){var _0x32edf1=this;return function(_0x590d0c){if(_0x590d0c){freeIsNotKey(_0x590d0c,_0x32edf1[_0xd4cf('0x15')],'id');for(var _0x38d78e=0x0,_0x54ca02={},_0x59424d={};_0x38d78e<_0x590d0c['length'];_0x38d78e+=0x1){_0x54ca02=_0x590d0c[_0x38d78e];if(_[_0xd4cf('0x45')](_0x32edf1['triggers'][_0x54ca02['id']])){_0x32edf1[_0xd4cf('0x15')][_0x54ca02['id']]=new Trigger(_0x54ca02);}else{_0x32edf1['mergeFromDatabase'](_0x32edf1[_0xd4cf('0x15')][_0x54ca02['id']],_0x54ca02);}}}return _0x32edf1[_0xd4cf('0x15')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x48')]=function(){var _0x334fb1=this;return function(_0xdb3f58){if(_0xdb3f58){freeIsNotKey(_0xdb3f58,_0x334fb1[_0xd4cf('0x16')],'id');for(var _0x387810=0x0,_0x2af4bf={},_0x3a9b89={};_0x387810<_0xdb3f58[_0xd4cf('0x41')];_0x387810+=0x1){_0x2af4bf=_0xdb3f58[_0x387810];if(_['isUndefined'](_0x334fb1[_0xd4cf('0x16')][_0x2af4bf['id']])){_0x334fb1[_0xd4cf('0x16')][_0x2af4bf['id']]=new Template(_0x2af4bf);}else{_0x334fb1['mergeFromDatabase'](_0x334fb1[_0xd4cf('0x16')][_0x2af4bf['id']],_0x2af4bf);}}}return _0x334fb1[_0xd4cf('0x16')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x49')]=function(){var _0x50d7aa=this;return function(_0x13bfb2){if(_0x13bfb2){freeIsNotKey(_0x13bfb2,_0x50d7aa['zendeskAccounts'],'id');for(var _0x451e1b=0x0,_0x4d2021={},_0x502d90={};_0x451e1b<_0x13bfb2[_0xd4cf('0x41')];_0x451e1b+=0x1){_0x4d2021=_0x13bfb2[_0x451e1b];if(_[_0xd4cf('0x45')](_0x50d7aa[_0xd4cf('0x1c')][_0x4d2021['id']])){_0x50d7aa[_0xd4cf('0x1c')][_0x4d2021['id']]=new ZendeskAccount(_0x4d2021);}else{_0x50d7aa[_0xd4cf('0x3f')](_0x50d7aa[_0xd4cf('0x1c')][_0x4d2021['id']],_0x4d2021);}}}return _0x50d7aa[_0xd4cf('0x1c')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x4a')]=function(){var _0x40fe90=this;return function(_0xa288f7){if(_0xa288f7){freeIsNotKey(_0xa288f7,_0x40fe90[_0xd4cf('0x1d')],'id');for(var _0x40774a=0x0,_0x2b278f={},_0x519e97={};_0x40774a<_0xa288f7[_0xd4cf('0x41')];_0x40774a+=0x1){_0x2b278f=_0xa288f7[_0x40774a];if(_['isUndefined'](_0x40fe90[_0xd4cf('0x1d')][_0x2b278f['id']])){_0x40fe90[_0xd4cf('0x1d')][_0x2b278f['id']]=new SalesforceAccount(_0x2b278f);}else{_0x40fe90['mergeFromDatabase'](_0x40fe90[_0xd4cf('0x1d')][_0x2b278f['id']],_0x2b278f);}}}return _0x40fe90['salesforceAccounts'];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x4b')]=function(){var _0x4a8f62=this;return function(_0x43a8c8){if(_0x43a8c8){freeIsNotKey(_0x43a8c8,_0x4a8f62[_0xd4cf('0x4c')],'id');for(var _0x5dfcf7=0x0,_0x80e614={},_0xdf866a={};_0x5dfcf7<_0x43a8c8[_0xd4cf('0x41')];_0x5dfcf7+=0x1){_0x80e614=_0x43a8c8[_0x5dfcf7];if(_[_0xd4cf('0x45')](_0x4a8f62[_0xd4cf('0x4c')][_0x80e614['id']])){_0x4a8f62[_0xd4cf('0x4c')][_0x80e614['id']]=new FreshdeskAccount(_0x80e614);}else{_0x4a8f62[_0xd4cf('0x3f')](_0x4a8f62[_0xd4cf('0x4c')][_0x80e614['id']],_0x80e614);}}}return _0x4a8f62[_0xd4cf('0x4c')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x4d')]=function(){var _0x156caf=this;return function(_0x530fdb){if(_0x530fdb){freeIsNotKey(_0x530fdb,_0x156caf[_0xd4cf('0x1e')],'id');for(var _0x281756=0x0,_0x16c316={},_0x346a25={};_0x281756<_0x530fdb[_0xd4cf('0x41')];_0x281756+=0x1){_0x16c316=_0x530fdb[_0x281756];if(_['isUndefined'](_0x156caf[_0xd4cf('0x1e')][_0x16c316['id']])){_0x156caf[_0xd4cf('0x1e')][_0x16c316['id']]=new ZohoAccount(_0x16c316);}else{_0x156caf[_0xd4cf('0x3f')](_0x156caf[_0xd4cf('0x1e')][_0x16c316['id']],_0x16c316);}}}return _0x156caf[_0xd4cf('0x1e')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x4e')]=function(){var _0x45184b=this;return function(_0x3600f9){if(_0x3600f9){freeIsNotKey(_0x3600f9,_0x45184b[_0xd4cf('0x1f')],'id');for(var _0x3170cc=0x0,_0x2d20ef={},_0x47df06={};_0x3170cc<_0x3600f9[_0xd4cf('0x41')];_0x3170cc+=0x1){_0x2d20ef=_0x3600f9[_0x3170cc];if(_['isUndefined'](_0x45184b['deskAccounts'][_0x2d20ef['id']])){_0x45184b[_0xd4cf('0x1f')][_0x2d20ef['id']]=new DeskAccount(_0x2d20ef);}else{_0x45184b[_0xd4cf('0x3f')](_0x45184b['deskAccounts'][_0x2d20ef['id']],_0x2d20ef);}}}return _0x45184b[_0xd4cf('0x1f')];};};Realtime['prototype'][_0xd4cf('0x4f')]=function(){var _0x567133=this;return function(_0x558c09){if(_0x558c09){freeIsNotKey(_0x558c09,_0x567133[_0xd4cf('0x50')],'id');for(var _0x31bdce=0x0,_0x387067={},_0x320f6c={};_0x31bdce<_0x558c09[_0xd4cf('0x41')];_0x31bdce+=0x1){_0x387067=_0x558c09[_0x31bdce];if(_[_0xd4cf('0x45')](_0x567133['sugarcrmAccounts'][_0x387067['id']])){_0x567133[_0xd4cf('0x50')][_0x387067['id']]=new SugarcrmAccount(_0x387067);}else{_0x567133['mergeFromDatabase'](_0x567133[_0xd4cf('0x50')][_0x387067['id']],_0x387067);}}}return _0x567133[_0xd4cf('0x50')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x51')]=function(){var _0x38864d=this;return function(_0x1d6087){if(_0x1d6087){freeIsNotKey(_0x1d6087,_0x38864d['vtigerAccounts'],'id');for(var _0x5edaf=0x0,_0x19c4c2={},_0x391829={};_0x5edaf<_0x1d6087[_0xd4cf('0x41')];_0x5edaf+=0x1){_0x19c4c2=_0x1d6087[_0x5edaf];if(_[_0xd4cf('0x45')](_0x38864d['vtigerAccounts'][_0x19c4c2['id']])){_0x38864d[_0xd4cf('0x20')][_0x19c4c2['id']]=new VtigerAccount(_0x19c4c2);}else{_0x38864d[_0xd4cf('0x3f')](_0x38864d[_0xd4cf('0x20')][_0x19c4c2['id']],_0x19c4c2);}}}return _0x38864d[_0xd4cf('0x20')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x52')]=function(){var _0x4189a6=this;return function(_0x14187b){if(_0x14187b){freeIsNotKey(_0x14187b,_0x4189a6[_0xd4cf('0x21')],'id');for(var _0x1bc114=0x0,_0x2ab76c={},_0x3cd2cd={};_0x1bc114<_0x14187b['length'];_0x1bc114+=0x1){_0x2ab76c=_0x14187b[_0x1bc114];if(_[_0xd4cf('0x45')](_0x4189a6[_0xd4cf('0x21')][_0x2ab76c['id']])){_0x4189a6[_0xd4cf('0x21')][_0x2ab76c['id']]=new ServicenowAccount(_0x2ab76c);}else{_0x4189a6['mergeFromDatabase'](_0x4189a6[_0xd4cf('0x21')][_0x2ab76c['id']],_0x2ab76c);}}}return _0x4189a6[_0xd4cf('0x21')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x53')]=function(){var _0x407e0a=this;return function(_0x25e81a){if(_0x25e81a){freeIsNotKey(_0x25e81a,_0x407e0a[_0xd4cf('0x22')],'id');for(var _0x1576aa=0x0,_0x4957ca={},_0x1f0f57={};_0x1576aa<_0x25e81a[_0xd4cf('0x41')];_0x1576aa+=0x1){_0x4957ca=_0x25e81a[_0x1576aa];if(_[_0xd4cf('0x45')](_0x407e0a[_0xd4cf('0x22')][_0x4957ca['id']])){_0x407e0a[_0xd4cf('0x22')][_0x4957ca['id']]=new Dynamics365Account(_0x4957ca);}else{_0x407e0a[_0xd4cf('0x3f')](_0x407e0a[_0xd4cf('0x22')][_0x4957ca['id']],_0x4957ca);}}}return _0x407e0a['dynamics365Accounts'];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x54')]=function(){var _0x5a06bb=this;return function(_0x5837d8){if(_0x5837d8){freeIsNotKey(_0x5837d8,_0x5a06bb[_0xd4cf('0x23')],'id');for(var _0x169e33=0x0,_0x1e4b3a={},_0x4a60cc={};_0x169e33<_0x5837d8[_0xd4cf('0x41')];_0x169e33+=0x1){_0x1e4b3a=_0x5837d8[_0x169e33];if(_['isUndefined'](_0x5a06bb['freshsalesAccounts'][_0x1e4b3a['id']])){_0x5a06bb[_0xd4cf('0x23')][_0x1e4b3a['id']]=new FreshsalesAccount(_0x1e4b3a);}else{_0x5a06bb['mergeFromDatabase'](_0x5a06bb[_0xd4cf('0x23')][_0x1e4b3a['id']],_0x1e4b3a);}}}return _0x5a06bb[_0xd4cf('0x23')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x55')]=function(){var _0x532afb=this;return function(_0x3540fe){for(var _0x4aed33=0x0;_0x4aed33<_0x3540fe[_0xd4cf('0x41')];_0x4aed33+=0x1){_[_0xd4cf('0x56')](_0x532afb[_0xd4cf('0x14')][_0x3540fe[_0x4aed33]['name']],_0x3540fe[_0x4aed33]);}return _0x532afb[_0xd4cf('0x14')];};};Realtime['prototype'][_0xd4cf('0x57')]=function(){var _0x54b316=this;return function(_0x4f208a){clearVoiceQueues(_0x54b316[_0xd4cf('0x14')]);if(_0x4f208a){_0x4f208a=_[_0xd4cf('0x58')](_0x4f208a,_0xd4cf('0x59'));for(var _0x1c6eda in _0x4f208a){if(_0x4f208a[_0xd4cf('0x28')](_0x1c6eda)){var _0x3a0ac5={};for(var _0x1d82d2=0x0;_0x1d82d2<_0x4f208a[_0x1c6eda][_0xd4cf('0x41')];_0x1d82d2+=0x1){var _0x34ba37=_0x4f208a[_0x1c6eda][_0x1d82d2]['queue'];if(_0x54b316['voiceQueues'][_0x34ba37]){if(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5a')]){_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x32')]+=0x1;}if(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5b')]){_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x33')]+=0x1;}_0x54b316[_0xd4cf('0x14')][_0x34ba37]['sumHoldTime']+=moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5c')])[_0xd4cf('0x5d')](moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5e')]),'seconds')||0x0;if(_0x1d82d2===_0x4f208a[_0x1c6eda]['length']-0x1){_0x54b316[_0xd4cf('0x14')][_0x34ba37]['sumDuration']+=moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5f')]||_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x60')]||_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x61')])[_0xd4cf('0x5d')](moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5e')]),_0xd4cf('0x62'))||0x0;_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x2b')]+=0x1;if(_0x4f208a[_0x1c6eda][_0x1d82d2]['queuecallercomplete']){_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x2c')]+=0x1;_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x2f')]+=moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5f')])[_0xd4cf('0x5d')](moment(_0x4f208a[_0x1c6eda][_0x1d82d2][_0xd4cf('0x5c')]),_0xd4cf('0x62'))||0x0;}}else{_0x54b316[_0xd4cf('0x14')][_0x34ba37][_0xd4cf('0x2e')]+=_0x54b316['voiceQueues'][_0x34ba37][_0xd4cf('0x2d')]||0x0;}}}}}}return _0x54b316['voiceQueues'];};};Realtime['prototype']['initVoiceCallReports']=function(){var _0x811489=this;return function(_0x1f545a){clearVoiceCallReports(_0x811489['outbound']);if(_0x1f545a){for(var _0x848234=0x0;_0x848234<_0x1f545a['length'];_0x848234+=0x1){_0x811489[_0xd4cf('0x17')]['total']+=0x1;_0x811489[_0xd4cf('0x17')]['sumDuration']+=_0x1f545a[_0x848234][_0xd4cf('0x63')];if(_0x1f545a[_0x848234][_0xd4cf('0x64')]===_0xd4cf('0x65')){_0x811489['outbound'][_0xd4cf('0x2c')]+=0x1;_0x811489['outbound']['sumHoldTime']+=_0x1f545a[_0x848234][_0xd4cf('0x63')]-_0x1f545a[_0x848234][_0xd4cf('0x66')]||0x0;_0x811489[_0xd4cf('0x17')][_0xd4cf('0x2f')]+=_0x1f545a[_0x848234]['billableseconds'];}}}return _0x811489[_0xd4cf('0x17')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x67')]=function(){var _0x333105=this;return function(_0x5b5e32){if(_0x5b5e32){freeIsNotKey(_0x5b5e32,_0x333105['campaigns'],_0xd4cf('0x27'));for(var _0x2bb9e8=0x0,_0x43fba8={};_0x2bb9e8<_0x5b5e32['length'];_0x2bb9e8+=0x1){_0x43fba8=_0x5b5e32[_0x2bb9e8];if(_[_0xd4cf('0x45')](_0x333105[_0xd4cf('0x68')][_0x43fba8[_0xd4cf('0x27')]])){_0x333105['campaigns'][_0x43fba8[_0xd4cf('0x27')]]=new Campaign(_0x43fba8);}else{_0x333105[_0xd4cf('0x3f')](_0x333105[_0xd4cf('0x68')][_0x43fba8[_0xd4cf('0x27')]],_0x43fba8);_0x333105[_0xd4cf('0x68')][_0x43fba8['name']][_0xd4cf('0x69')]=_0x43fba8[_0xd4cf('0x6a')]?_0x43fba8[_0xd4cf('0x6a')]['name']:undefined;}}}return _0x333105[_0xd4cf('0x68')];};};Realtime[_0xd4cf('0x3e')][_0xd4cf('0x6b')]=function(){var _0x5a11f0=this;return function(_0x447bc6){if(_0x447bc6){freeIsNotKey(_0x447bc6,_0x5a11f0[_0xd4cf('0x6c')],'id');for(var _0x58c94e=0x0,_0x157b88={};_0x58c94e<_0x447bc6[_0xd4cf('0x41')];_0x58c94e+=0x1){_0x157b88=_0x447bc6[_0x58c94e];if(_[_0xd4cf('0x45')](_0x5a11f0[_0xd4cf('0x6c')][_0x157b88['id']])){_0x5a11f0[_0xd4cf('0x6c')][_0x157b88['id']]=new VoiceExtension(_0x157b88);}else{_0x5a11f0[_0xd4cf('0x3f')](_0x5a11f0['voiceExtensions'][_0x157b88['id']],_0x157b88);}}}return _0x5a11f0[_0xd4cf('0x6c')];};};Realtime['prototype'][_0xd4cf('0x6d')]=function(){var _0x51ff92=this;return function(_0x5cb7cd){clearCampaigns(_0x51ff92[_0xd4cf('0x68')]);for(var _0x34a8b8=0x0;_0x34a8b8<_0x5cb7cd[_0xd4cf('0x41')];_0x34a8b8+=0x1){_[_0xd4cf('0x56')](_0x51ff92['campaigns'][_0x5cb7cd[_0x34a8b8][_0xd4cf('0x27')]],_0x5cb7cd[_0x34a8b8]);}return _0x51ff92[_0xd4cf('0x68')];};};Realtime['prototype']['initFaxAccounts']=function(){var _0x2002c3=this;return function(_0x52f35f){if(_0x52f35f){freeIsNotKey(_0x52f35f,_0x2002c3['faxAccounts'],'id');for(var _0x10667a=0x0,_0x5a0b8e={},_0x140f85={};_0x10667a<_0x52f35f[_0xd4cf('0x41')];_0x10667a+=0x1){_0x5a0b8e=_0x52f35f[_0x10667a];if(_['isUndefined'](_0x2002c3[_0xd4cf('0x6e')][_0x5a0b8e['id']])){_0x2002c3[_0xd4cf('0x6e')][_0x5a0b8e['id']]=new FaxAccount(_0x5a0b8e);}else{_0x2002c3['mergeFromDatabase'](_0x2002c3['faxAccounts'][_0x5a0b8e['id']],_0x5a0b8e);}}}return _0x2002c3[_0xd4cf('0x6e')];};};module[_0xd4cf('0x6f')]=Realtime;