Built motion from commit (unavailable).|2.5.24
[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 _0x2fe6=['outboundBlacklistCallsDay','outboundRejectCallsDay','outboundAnswerCallsDay','queueStatusComplete','prototype','mergeFromDatabase','initAgents','length','isUndefined','initTrunks','initVoiceQueues','initTriggers','initTemplates','templates','initZendeskAccounts','zendeskAccounts','initFreshdeskAccounts','initZohoAccounts','initDeskAccounts','initSugarcrmAccounts','initVtigerAccounts','initServicenowAccounts','servicenowAccounts','initFreshsalesAccounts','initVoiceQueueHopperHistory','merge','groupBy','uniqueid','queue','queuecallerexit','queuecallerabandon','queuecallerleaveAt','diff','seconds','queuecallercompleteAt','queuecallerabandonAt','queuecallerjoinAt','queuecallercomplete','initVoiceCallReports','duration','billableseconds','initCampaigns','dialQueueProject','SquareProject','initVoiceExtensions','voiceExtensions','initCampaignHopperHistory','bluebird','util','lodash','moment','../model/agent','../model/telephone','../model/trunk','../model/voiceQueue','../model/trigger','../model/template','../model/campaign','../model/zendeskAccount','../model/salesforceAccount','../model/freshdeskAccount','../model/sugarcrmAccount','../model/vtigerAccount','../model/servicenowAccount','../model/dynamics365Account','../model/freshsalesAccount','agents','telephones','trunks','voiceQueues','triggers','campaigns','outbound','channels','outboundChannels','timers','salesforceAccounts','sugarcrmAccounts','freshdeskAccounts','zohoAccounts','deskAccounts','vtigerAccounts','dynamics365Accounts','freshsalesAccounts','faxAccounts','mapKeys','hasOwnProperty','format','SIP/%s','name','interface','total','sumHoldTime','sumDuration','sumBillable','isEmpty','ivrAnswerCallsDay','answered','unmanaged','abandoned','outboundAnswerAgiCallsDay','outboundNoSuchCallsDay','outboundDropCallsDayTimeout'];(function(_0x2be19b,_0x309672){var _0x54b322=function(_0x23a534){while(--_0x23a534){_0x2be19b['push'](_0x2be19b['shift']());}};_0x54b322(++_0x309672);}(_0x2fe6,0x1cb));var _0x62fe=function(_0x2466f8,_0x9e91c0){_0x2466f8=_0x2466f8-0x0;var _0xacdd9c=_0x2fe6[_0x2466f8];return _0xacdd9c;};'use strict';var BPromise=require(_0x62fe('0x0'));var util=require(_0x62fe('0x1'));var _=require(_0x62fe('0x2'));var moment=require(_0x62fe('0x3'));var Agent=require(_0x62fe('0x4'));var Telephone=require(_0x62fe('0x5'));var Trunk=require(_0x62fe('0x6'));var VoiceQueue=require(_0x62fe('0x7'));var Trigger=require(_0x62fe('0x8'));var Template=require(_0x62fe('0x9'));var Campaign=require(_0x62fe('0xa'));var VoiceExtension=require('../model/voiceExtension');var ZendeskAccount=require(_0x62fe('0xb'));var SalesforceAccount=require(_0x62fe('0xc'));var FreshdeskAccount=require(_0x62fe('0xd'));var SugarcrmAccount=require(_0x62fe('0xe'));var ZohoAccount=require('../model/zohoAccount');var DeskAccount=require('../model/deskAccount');var VtigerAccount=require(_0x62fe('0xf'));var ServicenowAccount=require(_0x62fe('0x10'));var Dynamics365Account=require(_0x62fe('0x11'));var FreshsalesAccount=require(_0x62fe('0x12'));var FaxAccount=require('../model/faxAccount');var Realtime=function(){this[_0x62fe('0x13')]={};this[_0x62fe('0x14')]={};this[_0x62fe('0x15')]={};this[_0x62fe('0x16')]={};this[_0x62fe('0x17')]={};this[_0x62fe('0x18')]={};this['templates']={};this[_0x62fe('0x19')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this['voiceExtensions']={};this[_0x62fe('0x1a')]={};this['queueChannels']={};this[_0x62fe('0x1b')]={};this[_0x62fe('0x1c')]={};this['zendeskAccounts']={};this[_0x62fe('0x1d')]={};this[_0x62fe('0x1e')]={};this[_0x62fe('0x1f')]={};this[_0x62fe('0x20')]={};this[_0x62fe('0x21')]={};this[_0x62fe('0x22')]={};this['servicenowAccounts']={};this[_0x62fe('0x23')]={};this[_0x62fe('0x24')]={};this[_0x62fe('0x25')]={};};function freeIsNotKey(_0x2d7a12,_0x4650c6,_0x5b8036){var _0x1f8ee6=_[_0x62fe('0x26')](_0x2d7a12,function(_0x8bfb75,_0x3db2cb){return _0x8bfb75[_0x5b8036];});for(var _0x766eab in _0x4650c6){if(_0x4650c6[_0x62fe('0x27')](_0x766eab)){if(!_0x1f8ee6[_0x766eab]){delete _0x4650c6[_0x766eab];}}}}function freeIsNotKeySip(_0x431539,_0x19d264){var _0x2614fd=_[_0x62fe('0x26')](_0x431539,function(_0x4d096f,_0x443093){return util[_0x62fe('0x28')](_0x62fe('0x29'),_0x4d096f[_0x62fe('0x2a')]);});for(var _0xb3352a in _0x19d264){if(_0x19d264['hasOwnProperty'](_0xb3352a)){if(!_0x2614fd[_0xb3352a]){delete _0x19d264[_0xb3352a];}}}}function freeIsNotKeyAgent(_0x27ef59,_0x5e5845){var _0x1091e8=_['mapKeys'](_0x27ef59,function(_0x550d01,_0x1828b5){var _0x14dfd3=_['isNil'](_0x550d01[_0x62fe('0x2b')])?util['format'](_0x62fe('0x29'),_0x550d01[_0x62fe('0x2a')]):_0x550d01[_0x62fe('0x2b')];return _0x14dfd3;});for(var _0x5d5fc0 in _0x5e5845){if(_0x5e5845[_0x62fe('0x27')](_0x5d5fc0)){if(!_0x1091e8[_0x5d5fc0]){delete _0x5e5845[_0x5d5fc0];}}}}function clearVoiceCallReports(_0x588f7c){_0x588f7c[_0x62fe('0x2c')]=0x0;_0x588f7c['answered']=0x0;_0x588f7c[_0x62fe('0x2d')]=0x0;_0x588f7c[_0x62fe('0x2e')]=0x0;_0x588f7c[_0x62fe('0x2f')]=0x0;}function clearCampaigns(_0x56a2e6){if(!_[_0x62fe('0x30')](_0x56a2e6)){for(var _0x194909 in _0x56a2e6){if(_0x56a2e6[_0x62fe('0x27')](_0x194909)){_0x56a2e6[_0x194909]['ivrTotalCallsDays']=0x0;_0x56a2e6[_0x194909][_0x62fe('0x31')]=0x0;}}}}function clearVoiceQueues(_0x233aa8){if(!_[_0x62fe('0x30')](_0x233aa8)){for(var _0x1340f9 in _0x233aa8){if(_0x233aa8['hasOwnProperty'](_0x1340f9)){_0x233aa8[_0x1340f9]['total']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x32')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x33')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x34')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x2d')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x2e')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x2f')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x35')]=0x0;_0x233aa8[_0x1340f9]['outboundNoAnswerCallsDay']=0x0;_0x233aa8[_0x1340f9]['outboundBusyCallsDay']=0x0;_0x233aa8[_0x1340f9]['outboundCongestionCallsDay']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x36')]=0x0;_0x233aa8[_0x1340f9]['outboundUnknownCallsDay']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x37')]=0x0;_0x233aa8[_0x1340f9]['outboundDropCallsDayCallersExit']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x38')]=0x0;_0x233aa8[_0x1340f9]['outboundOriginateFailureCallsDay']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x39')]=0x0;_0x233aa8[_0x1340f9]['outboundReCallsDay']=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x35')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x3a')]=0x0;_0x233aa8[_0x1340f9][_0x62fe('0x3b')]=!![];}}}}Realtime[_0x62fe('0x3c')][_0x62fe('0x3d')]=function(_0x4285de,_0x367192){for(var _0x11cb9f in _0x367192){if(_0x4285de['hasOwnProperty'](_0x11cb9f)){_0x4285de[_0x11cb9f]=_0x367192[_0x11cb9f];}}};Realtime[_0x62fe('0x3c')][_0x62fe('0x3e')]=function(){var _0x5b159b=this;return function(_0x52b14b){if(_0x52b14b){freeIsNotKeyAgent(_0x52b14b,_0x5b159b[_0x62fe('0x13')]);for(var _0x3ab55c=0x0,_0x10e9fb={},_0x24ca1a={};_0x3ab55c<_0x52b14b[_0x62fe('0x3f')];_0x3ab55c+=0x1){_0x10e9fb=_0x52b14b[_0x3ab55c];var _0x125d90=_['isNil'](_0x10e9fb[_0x62fe('0x2b')])?util[_0x62fe('0x28')]('SIP/%s',_0x10e9fb['name']):_0x10e9fb[_0x62fe('0x2b')];if(_[_0x62fe('0x40')](_0x5b159b['agents'][_0x125d90])){_0x5b159b[_0x62fe('0x13')][_0x125d90]=new Agent(_0x10e9fb);}else{_0x5b159b[_0x62fe('0x3d')](_0x5b159b[_0x62fe('0x13')][_0x125d90],_0x10e9fb);}}}return _0x5b159b[_0x62fe('0x13')];};};Realtime['prototype']['initTelephones']=function(){var _0x4748dc=this;return function(_0x82506d){if(_0x82506d){freeIsNotKeySip(_0x82506d,_0x4748dc['telephones']);for(var _0x5ea4c9=0x0,_0x4b4a28={},_0x24969a={};_0x5ea4c9<_0x82506d['length'];_0x5ea4c9+=0x1){_0x4b4a28=_0x82506d[_0x5ea4c9];if(_[_0x62fe('0x40')](_0x4748dc[_0x62fe('0x14')][util[_0x62fe('0x28')](_0x62fe('0x29'),_0x4b4a28[_0x62fe('0x2a')])])){_0x4748dc['telephones'][util['format'](_0x62fe('0x29'),_0x4b4a28['name'])]=new Telephone(_0x4b4a28);}else{_0x4748dc['mergeFromDatabase'](_0x4748dc['telephones'][util[_0x62fe('0x28')](_0x62fe('0x29'),_0x4b4a28[_0x62fe('0x2a')])],_0x4b4a28);}}}return _0x4748dc[_0x62fe('0x14')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x41')]=function(){var _0x3b0926=this;return function(_0x344194){if(_0x344194){freeIsNotKeySip(_0x344194,_0x3b0926['trunks']);for(var _0x3a6aab=0x0,_0x477870={},_0x4318e9={};_0x3a6aab<_0x344194[_0x62fe('0x3f')];_0x3a6aab+=0x1){_0x477870=_0x344194[_0x3a6aab];if(_['isUndefined'](_0x3b0926[_0x62fe('0x15')][util[_0x62fe('0x28')](_0x62fe('0x29'),_0x477870[_0x62fe('0x2a')])])){_0x3b0926[_0x62fe('0x15')][util[_0x62fe('0x28')](_0x62fe('0x29'),_0x477870['name'])]=new Trunk(_0x477870);}else{_0x3b0926[_0x62fe('0x3d')](_0x3b0926[_0x62fe('0x15')][util[_0x62fe('0x28')]('SIP/%s',_0x477870['name'])],_0x477870);}}}return _0x3b0926[_0x62fe('0x15')];};};Realtime['prototype'][_0x62fe('0x42')]=function(){var _0x353165=this;return function(_0x4f29b5){if(_0x4f29b5){freeIsNotKey(_0x4f29b5,_0x353165[_0x62fe('0x16')],_0x62fe('0x2a'));for(var _0xa505f1=0x0,_0x53ed25={},_0x5f4b8a={};_0xa505f1<_0x4f29b5['length'];_0xa505f1+=0x1){_0x53ed25=_0x4f29b5[_0xa505f1];if(_[_0x62fe('0x40')](_0x353165['voiceQueues'][_0x53ed25[_0x62fe('0x2a')]])){_0x353165['voiceQueues'][_0x53ed25['name']]=new VoiceQueue(_0x53ed25);}else{_0x353165[_0x62fe('0x3d')](_0x353165['voiceQueues'][_0x53ed25[_0x62fe('0x2a')]],_0x53ed25);}}}return _0x353165[_0x62fe('0x16')];};};Realtime['prototype'][_0x62fe('0x43')]=function(){var _0x4546fb=this;return function(_0x4889a9){if(_0x4889a9){freeIsNotKey(_0x4889a9,_0x4546fb['triggers'],'id');for(var _0x49508a=0x0,_0x2d3b60={},_0x11f63b={};_0x49508a<_0x4889a9[_0x62fe('0x3f')];_0x49508a+=0x1){_0x2d3b60=_0x4889a9[_0x49508a];if(_[_0x62fe('0x40')](_0x4546fb[_0x62fe('0x17')][_0x2d3b60['id']])){_0x4546fb[_0x62fe('0x17')][_0x2d3b60['id']]=new Trigger(_0x2d3b60);}else{_0x4546fb[_0x62fe('0x3d')](_0x4546fb['triggers'][_0x2d3b60['id']],_0x2d3b60);}}}return _0x4546fb[_0x62fe('0x17')];};};Realtime['prototype'][_0x62fe('0x44')]=function(){var _0x3cdd28=this;return function(_0x116bc9){if(_0x116bc9){freeIsNotKey(_0x116bc9,_0x3cdd28[_0x62fe('0x45')],'id');for(var _0x1106e2=0x0,_0xb0c637={},_0x37d07d={};_0x1106e2<_0x116bc9[_0x62fe('0x3f')];_0x1106e2+=0x1){_0xb0c637=_0x116bc9[_0x1106e2];if(_[_0x62fe('0x40')](_0x3cdd28[_0x62fe('0x45')][_0xb0c637['id']])){_0x3cdd28[_0x62fe('0x45')][_0xb0c637['id']]=new Template(_0xb0c637);}else{_0x3cdd28[_0x62fe('0x3d')](_0x3cdd28['templates'][_0xb0c637['id']],_0xb0c637);}}}return _0x3cdd28[_0x62fe('0x45')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x46')]=function(){var _0x514636=this;return function(_0x119ab7){if(_0x119ab7){freeIsNotKey(_0x119ab7,_0x514636[_0x62fe('0x47')],'id');for(var _0x19b182=0x0,_0x42c180={},_0x5c92b4={};_0x19b182<_0x119ab7[_0x62fe('0x3f')];_0x19b182+=0x1){_0x42c180=_0x119ab7[_0x19b182];if(_[_0x62fe('0x40')](_0x514636[_0x62fe('0x47')][_0x42c180['id']])){_0x514636[_0x62fe('0x47')][_0x42c180['id']]=new ZendeskAccount(_0x42c180);}else{_0x514636[_0x62fe('0x3d')](_0x514636[_0x62fe('0x47')][_0x42c180['id']],_0x42c180);}}}return _0x514636[_0x62fe('0x47')];};};Realtime[_0x62fe('0x3c')]['initSalesforceAccounts']=function(){var _0x14df17=this;return function(_0x669766){if(_0x669766){freeIsNotKey(_0x669766,_0x14df17[_0x62fe('0x1d')],'id');for(var _0x143ebb=0x0,_0x1f4e9f={},_0x192bb5={};_0x143ebb<_0x669766['length'];_0x143ebb+=0x1){_0x1f4e9f=_0x669766[_0x143ebb];if(_[_0x62fe('0x40')](_0x14df17['salesforceAccounts'][_0x1f4e9f['id']])){_0x14df17['salesforceAccounts'][_0x1f4e9f['id']]=new SalesforceAccount(_0x1f4e9f);}else{_0x14df17[_0x62fe('0x3d')](_0x14df17[_0x62fe('0x1d')][_0x1f4e9f['id']],_0x1f4e9f);}}}return _0x14df17[_0x62fe('0x1d')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x48')]=function(){var _0x4ce252=this;return function(_0x5466be){if(_0x5466be){freeIsNotKey(_0x5466be,_0x4ce252[_0x62fe('0x1f')],'id');for(var _0x495f15=0x0,_0x5ead43={},_0x5a0941={};_0x495f15<_0x5466be[_0x62fe('0x3f')];_0x495f15+=0x1){_0x5ead43=_0x5466be[_0x495f15];if(_[_0x62fe('0x40')](_0x4ce252[_0x62fe('0x1f')][_0x5ead43['id']])){_0x4ce252[_0x62fe('0x1f')][_0x5ead43['id']]=new FreshdeskAccount(_0x5ead43);}else{_0x4ce252[_0x62fe('0x3d')](_0x4ce252[_0x62fe('0x1f')][_0x5ead43['id']],_0x5ead43);}}}return _0x4ce252[_0x62fe('0x1f')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x49')]=function(){var _0x240172=this;return function(_0x3ad851){if(_0x3ad851){freeIsNotKey(_0x3ad851,_0x240172[_0x62fe('0x20')],'id');for(var _0x5b9c1a=0x0,_0x5ab308={},_0x117e77={};_0x5b9c1a<_0x3ad851[_0x62fe('0x3f')];_0x5b9c1a+=0x1){_0x5ab308=_0x3ad851[_0x5b9c1a];if(_[_0x62fe('0x40')](_0x240172['zohoAccounts'][_0x5ab308['id']])){_0x240172[_0x62fe('0x20')][_0x5ab308['id']]=new ZohoAccount(_0x5ab308);}else{_0x240172[_0x62fe('0x3d')](_0x240172['zohoAccounts'][_0x5ab308['id']],_0x5ab308);}}}return _0x240172[_0x62fe('0x20')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x4a')]=function(){var _0x43a3e3=this;return function(_0xe8652c){if(_0xe8652c){freeIsNotKey(_0xe8652c,_0x43a3e3[_0x62fe('0x21')],'id');for(var _0x1249fb=0x0,_0x5b9bdc={},_0x35727d={};_0x1249fb<_0xe8652c[_0x62fe('0x3f')];_0x1249fb+=0x1){_0x5b9bdc=_0xe8652c[_0x1249fb];if(_[_0x62fe('0x40')](_0x43a3e3['deskAccounts'][_0x5b9bdc['id']])){_0x43a3e3[_0x62fe('0x21')][_0x5b9bdc['id']]=new DeskAccount(_0x5b9bdc);}else{_0x43a3e3['mergeFromDatabase'](_0x43a3e3[_0x62fe('0x21')][_0x5b9bdc['id']],_0x5b9bdc);}}}return _0x43a3e3['deskAccounts'];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x4b')]=function(){var _0x3f6120=this;return function(_0x18c825){if(_0x18c825){freeIsNotKey(_0x18c825,_0x3f6120['sugarcrmAccounts'],'id');for(var _0x38ff2a=0x0,_0x333e69={},_0xad8d0f={};_0x38ff2a<_0x18c825[_0x62fe('0x3f')];_0x38ff2a+=0x1){_0x333e69=_0x18c825[_0x38ff2a];if(_[_0x62fe('0x40')](_0x3f6120[_0x62fe('0x1e')][_0x333e69['id']])){_0x3f6120[_0x62fe('0x1e')][_0x333e69['id']]=new SugarcrmAccount(_0x333e69);}else{_0x3f6120[_0x62fe('0x3d')](_0x3f6120['sugarcrmAccounts'][_0x333e69['id']],_0x333e69);}}}return _0x3f6120[_0x62fe('0x1e')];};};Realtime['prototype'][_0x62fe('0x4c')]=function(){var _0x1cccbb=this;return function(_0x2c8cff){if(_0x2c8cff){freeIsNotKey(_0x2c8cff,_0x1cccbb[_0x62fe('0x22')],'id');for(var _0x55b4a8=0x0,_0x2f9788={},_0x3f23ce={};_0x55b4a8<_0x2c8cff['length'];_0x55b4a8+=0x1){_0x2f9788=_0x2c8cff[_0x55b4a8];if(_[_0x62fe('0x40')](_0x1cccbb[_0x62fe('0x22')][_0x2f9788['id']])){_0x1cccbb[_0x62fe('0x22')][_0x2f9788['id']]=new VtigerAccount(_0x2f9788);}else{_0x1cccbb[_0x62fe('0x3d')](_0x1cccbb[_0x62fe('0x22')][_0x2f9788['id']],_0x2f9788);}}}return _0x1cccbb[_0x62fe('0x22')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x4d')]=function(){var _0x372de9=this;return function(_0x369536){if(_0x369536){freeIsNotKey(_0x369536,_0x372de9[_0x62fe('0x4e')],'id');for(var _0x1b6080=0x0,_0x2abb14={},_0x2b4438={};_0x1b6080<_0x369536[_0x62fe('0x3f')];_0x1b6080+=0x1){_0x2abb14=_0x369536[_0x1b6080];if(_['isUndefined'](_0x372de9['servicenowAccounts'][_0x2abb14['id']])){_0x372de9['servicenowAccounts'][_0x2abb14['id']]=new ServicenowAccount(_0x2abb14);}else{_0x372de9[_0x62fe('0x3d')](_0x372de9[_0x62fe('0x4e')][_0x2abb14['id']],_0x2abb14);}}}return _0x372de9[_0x62fe('0x4e')];};};Realtime['prototype']['initDynamics365Accounts']=function(){var _0x182c8f=this;return function(_0x402f94){if(_0x402f94){freeIsNotKey(_0x402f94,_0x182c8f[_0x62fe('0x23')],'id');for(var _0x2f46b5=0x0,_0x3820a5={},_0x865bc0={};_0x2f46b5<_0x402f94[_0x62fe('0x3f')];_0x2f46b5+=0x1){_0x3820a5=_0x402f94[_0x2f46b5];if(_[_0x62fe('0x40')](_0x182c8f['dynamics365Accounts'][_0x3820a5['id']])){_0x182c8f['dynamics365Accounts'][_0x3820a5['id']]=new Dynamics365Account(_0x3820a5);}else{_0x182c8f['mergeFromDatabase'](_0x182c8f[_0x62fe('0x23')][_0x3820a5['id']],_0x3820a5);}}}return _0x182c8f[_0x62fe('0x23')];};};Realtime['prototype'][_0x62fe('0x4f')]=function(){var _0x5ced10=this;return function(_0x243a87){if(_0x243a87){freeIsNotKey(_0x243a87,_0x5ced10[_0x62fe('0x24')],'id');for(var _0xca1bc0=0x0,_0x3a4fde={},_0x37574f={};_0xca1bc0<_0x243a87[_0x62fe('0x3f')];_0xca1bc0+=0x1){_0x3a4fde=_0x243a87[_0xca1bc0];if(_['isUndefined'](_0x5ced10[_0x62fe('0x24')][_0x3a4fde['id']])){_0x5ced10['freshsalesAccounts'][_0x3a4fde['id']]=new FreshsalesAccount(_0x3a4fde);}else{_0x5ced10[_0x62fe('0x3d')](_0x5ced10[_0x62fe('0x24')][_0x3a4fde['id']],_0x3a4fde);}}}return _0x5ced10[_0x62fe('0x24')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x50')]=function(){var _0x277f6f=this;return function(_0x3631d0){for(var _0x370993=0x0;_0x370993<_0x3631d0[_0x62fe('0x3f')];_0x370993+=0x1){_[_0x62fe('0x51')](_0x277f6f[_0x62fe('0x16')][_0x3631d0[_0x370993][_0x62fe('0x2a')]],_0x3631d0[_0x370993]);}return _0x277f6f[_0x62fe('0x16')];};};Realtime['prototype']['initVoiceQueueReports']=function(){var _0x5b1e06=this;return function(_0x187b6d){clearVoiceQueues(_0x5b1e06['voiceQueues']);if(_0x187b6d){_0x187b6d=_[_0x62fe('0x52')](_0x187b6d,_0x62fe('0x53'));for(var _0x2507d5 in _0x187b6d){if(_0x187b6d['hasOwnProperty'](_0x2507d5)){var _0x186c87={};for(var _0x3dd123=0x0;_0x3dd123<_0x187b6d[_0x2507d5][_0x62fe('0x3f')];_0x3dd123+=0x1){var _0x148829=_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x54')];if(_0x5b1e06[_0x62fe('0x16')][_0x148829]){if(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x55')]){_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x33')]+=0x1;}if(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x56')]){_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x34')]+=0x1;}_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x2d')]+=moment(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x57')])[_0x62fe('0x58')](moment(_0x187b6d[_0x2507d5][_0x3dd123]['queuecallerjoinAt']),_0x62fe('0x59'))||0x0;if(_0x3dd123===_0x187b6d[_0x2507d5]['length']-0x1){_0x5b1e06[_0x62fe('0x16')][_0x148829]['sumDuration']+=moment(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x5a')]||_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x5b')]||_0x187b6d[_0x2507d5][_0x3dd123]['queuecallerexitAt'])[_0x62fe('0x58')](moment(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x5c')]),_0x62fe('0x59'))||0x0;_0x5b1e06['voiceQueues'][_0x148829]['total']+=0x1;if(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x5d')]){_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x32')]+=0x1;_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x2f')]+=moment(_0x187b6d[_0x2507d5][_0x3dd123][_0x62fe('0x5a')])[_0x62fe('0x58')](moment(_0x187b6d[_0x2507d5][_0x3dd123]['queuecallerleaveAt']),_0x62fe('0x59'))||0x0;}}else{_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x2e')]+=_0x5b1e06[_0x62fe('0x16')][_0x148829][_0x62fe('0x2d')]||0x0;}}}}}}return _0x5b1e06[_0x62fe('0x16')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x5e')]=function(){var _0x3a98b7=this;return function(_0x710c25){clearVoiceCallReports(_0x3a98b7[_0x62fe('0x19')]);if(_0x710c25){for(var _0x3f7f0b=0x0;_0x3f7f0b<_0x710c25[_0x62fe('0x3f')];_0x3f7f0b+=0x1){_0x3a98b7[_0x62fe('0x19')][_0x62fe('0x2c')]+=0x1;_0x3a98b7['outbound'][_0x62fe('0x2e')]+=_0x710c25[_0x3f7f0b][_0x62fe('0x5f')];if(_0x710c25[_0x3f7f0b]['disposition']==='ANSWERED'){_0x3a98b7[_0x62fe('0x19')]['answered']+=0x1;_0x3a98b7['outbound'][_0x62fe('0x2d')]+=_0x710c25[_0x3f7f0b][_0x62fe('0x5f')]-_0x710c25[_0x3f7f0b]['billableseconds']||0x0;_0x3a98b7['outbound'][_0x62fe('0x2f')]+=_0x710c25[_0x3f7f0b][_0x62fe('0x60')];}}}return _0x3a98b7[_0x62fe('0x19')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x61')]=function(){var _0x4e3b52=this;return function(_0x40b008){if(_0x40b008){freeIsNotKey(_0x40b008,_0x4e3b52['campaigns'],_0x62fe('0x2a'));for(var _0x5e7784=0x0,_0x39244f={};_0x5e7784<_0x40b008[_0x62fe('0x3f')];_0x5e7784+=0x1){_0x39244f=_0x40b008[_0x5e7784];if(_['isUndefined'](_0x4e3b52['campaigns'][_0x39244f[_0x62fe('0x2a')]])){_0x4e3b52['campaigns'][_0x39244f[_0x62fe('0x2a')]]=new Campaign(_0x39244f);}else{_0x4e3b52[_0x62fe('0x3d')](_0x4e3b52[_0x62fe('0x18')][_0x39244f[_0x62fe('0x2a')]],_0x39244f);_0x4e3b52[_0x62fe('0x18')][_0x39244f['name']][_0x62fe('0x62')]=_0x39244f[_0x62fe('0x63')]?_0x39244f['SquareProject'][_0x62fe('0x2a')]:undefined;}}}return _0x4e3b52[_0x62fe('0x18')];};};Realtime[_0x62fe('0x3c')][_0x62fe('0x64')]=function(){var _0x5c0d25=this;return function(_0x2db894){if(_0x2db894){freeIsNotKey(_0x2db894,_0x5c0d25[_0x62fe('0x65')],'id');for(var _0xd8c3a0=0x0,_0x44756d={};_0xd8c3a0<_0x2db894[_0x62fe('0x3f')];_0xd8c3a0+=0x1){_0x44756d=_0x2db894[_0xd8c3a0];if(_[_0x62fe('0x40')](_0x5c0d25[_0x62fe('0x65')][_0x44756d['id']])){_0x5c0d25[_0x62fe('0x65')][_0x44756d['id']]=new VoiceExtension(_0x44756d);}else{_0x5c0d25[_0x62fe('0x3d')](_0x5c0d25[_0x62fe('0x65')][_0x44756d['id']],_0x44756d);}}}return _0x5c0d25[_0x62fe('0x65')];};};Realtime['prototype'][_0x62fe('0x66')]=function(){var _0x41d891=this;return function(_0x284f3a){clearCampaigns(_0x41d891['campaigns']);for(var _0x5edf13=0x0;_0x5edf13<_0x284f3a['length'];_0x5edf13+=0x1){_[_0x62fe('0x51')](_0x41d891['campaigns'][_0x284f3a[_0x5edf13][_0x62fe('0x2a')]],_0x284f3a[_0x5edf13]);}return _0x41d891[_0x62fe('0x18')];};};Realtime[_0x62fe('0x3c')]['initFaxAccounts']=function(){var _0x42d6b2=this;return function(_0x2d730c){if(_0x2d730c){freeIsNotKey(_0x2d730c,_0x42d6b2['faxAccounts'],'id');for(var _0xeec68b=0x0,_0x1c9f56={},_0x1c82f4={};_0xeec68b<_0x2d730c[_0x62fe('0x3f')];_0xeec68b+=0x1){_0x1c9f56=_0x2d730c[_0xeec68b];if(_[_0x62fe('0x40')](_0x42d6b2[_0x62fe('0x25')][_0x1c9f56['id']])){_0x42d6b2[_0x62fe('0x25')][_0x1c9f56['id']]=new FaxAccount(_0x1c9f56);}else{_0x42d6b2[_0x62fe('0x3d')](_0x42d6b2[_0x62fe('0x25')][_0x1c9f56['id']],_0x1c9f56);}}}return _0x42d6b2[_0x62fe('0x25')];};};module['exports']=Realtime;