Built motion from commit (unavailable).|2.5.4
[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 _0xdbad=['templates','outbound','channels','queueChannels','timers','zendeskAccounts','sugarcrmAccounts','zohoAccounts','deskAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','faxAccounts','mapKeys','hasOwnProperty','format','isNil','interface','SIP/%s','name','total','sumHoldTime','sumDuration','sumBillable','isEmpty','ivrTotalCallsDays','ivrAnswerCallsDay','answered','unmanaged','abandoned','outboundAnswerAgiCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundNoSuchCallsDay','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundReCallsDay','outboundAnswerCallsDay','prototype','mergeFromDatabase','agents','length','isUndefined','initTelephones','initTrunks','initVoiceQueues','initTriggers','initTemplates','initZendeskAccounts','initSalesforceAccounts','salesforceAccounts','initFreshdeskAccounts','freshdeskAccounts','initZohoAccounts','initDeskAccounts','initSugarcrmAccounts','initVtigerAccounts','initDynamics365Accounts','initFreshsalesAccounts','freshsalesAccounts','initVoiceQueueHopperHistory','merge','initVoiceQueueReports','queue','queuecallerexit','queuecallerabandon','diff','queuecallerjoinAt','seconds','queuecallercompleteAt','queuecallerabandonAt','queuecallercomplete','initVoiceCallReports','duration','ANSWERED','billableseconds','initCampaigns','dialQueueProject','SquareProject','initVoiceExtensions','voiceExtensions','initCampaignHopperHistory','initFaxAccounts','exports','bluebird','../model/telephone','../model/trunk','../model/voiceQueue','../model/trigger','../model/template','../model/campaign','../model/voiceExtension','../model/zendeskAccount','../model/freshdeskAccount','../model/sugarcrmAccount','../model/servicenowAccount','../model/dynamics365Account','../model/freshsalesAccount','telephones','trunks','voiceQueues','triggers','campaigns'];(function(_0x5bd426,_0x4878e5){var _0x23a7eb=function(_0x594b42){while(--_0x594b42){_0x5bd426['push'](_0x5bd426['shift']());}};_0x23a7eb(++_0x4878e5);}(_0xdbad,0x18d));var _0xddba=function(_0x44cecc,_0xa22ba7){_0x44cecc=_0x44cecc-0x0;var _0x1b3e71=_0xdbad[_0x44cecc];return _0x1b3e71;};'use strict';var BPromise=require(_0xddba('0x0'));var util=require('util');var _=require('lodash');var moment=require('moment');var Agent=require('../model/agent');var Telephone=require(_0xddba('0x1'));var Trunk=require(_0xddba('0x2'));var VoiceQueue=require(_0xddba('0x3'));var Trigger=require(_0xddba('0x4'));var Template=require(_0xddba('0x5'));var Campaign=require(_0xddba('0x6'));var VoiceExtension=require(_0xddba('0x7'));var ZendeskAccount=require(_0xddba('0x8'));var SalesforceAccount=require('../model/salesforceAccount');var FreshdeskAccount=require(_0xddba('0x9'));var SugarcrmAccount=require(_0xddba('0xa'));var ZohoAccount=require('../model/zohoAccount');var DeskAccount=require('../model/deskAccount');var VtigerAccount=require('../model/vtigerAccount');var ServicenowAccount=require(_0xddba('0xb'));var Dynamics365Account=require(_0xddba('0xc'));var FreshsalesAccount=require(_0xddba('0xd'));var FaxAccount=require('../model/faxAccount');var Realtime=function(){this['agents']={};this[_0xddba('0xe')]={};this[_0xddba('0xf')]={};this[_0xddba('0x10')]={};this[_0xddba('0x11')]={};this[_0xddba('0x12')]={};this[_0xddba('0x13')]={};this[_0xddba('0x14')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this['voiceExtensions']={};this[_0xddba('0x15')]={};this[_0xddba('0x16')]={};this['outboundChannels']={};this[_0xddba('0x17')]={};this[_0xddba('0x18')]={};this['salesforceAccounts']={};this[_0xddba('0x19')]={};this['freshdeskAccounts']={};this[_0xddba('0x1a')]={};this[_0xddba('0x1b')]={};this[_0xddba('0x1c')]={};this[_0xddba('0x1d')]={};this[_0xddba('0x1e')]={};this['freshsalesAccounts']={};this[_0xddba('0x1f')]={};};function freeIsNotKey(_0x2b2a36,_0x136534,_0x24322d){var _0x5d0151=_[_0xddba('0x20')](_0x2b2a36,function(_0x27cfa1,_0x569841){return _0x27cfa1[_0x24322d];});for(var _0x31d482 in _0x136534){if(_0x136534[_0xddba('0x21')](_0x31d482)){if(!_0x5d0151[_0x31d482]){delete _0x136534[_0x31d482];}}}}function freeIsNotKeySip(_0x5e2007,_0x49c9d4){var _0xde4e1b=_[_0xddba('0x20')](_0x5e2007,function(_0x3854ee,_0x27302a){return util[_0xddba('0x22')]('SIP/%s',_0x3854ee['name']);});for(var _0x35e2cf in _0x49c9d4){if(_0x49c9d4['hasOwnProperty'](_0x35e2cf)){if(!_0xde4e1b[_0x35e2cf]){delete _0x49c9d4[_0x35e2cf];}}}}function freeIsNotKeyAgent(_0x5d4428,_0x243807){var _0x76e1eb=_['mapKeys'](_0x5d4428,function(_0x2f1397,_0x5d43ce){var _0x26c3e2=_[_0xddba('0x23')](_0x2f1397[_0xddba('0x24')])?util[_0xddba('0x22')](_0xddba('0x25'),_0x2f1397[_0xddba('0x26')]):_0x2f1397[_0xddba('0x24')];return _0x26c3e2;});for(var _0x5eaa72 in _0x243807){if(_0x243807[_0xddba('0x21')](_0x5eaa72)){if(!_0x76e1eb[_0x5eaa72]){delete _0x243807[_0x5eaa72];}}}}function clearVoiceCallReports(_0x5c0b83){_0x5c0b83[_0xddba('0x27')]=0x0;_0x5c0b83['answered']=0x0;_0x5c0b83[_0xddba('0x28')]=0x0;_0x5c0b83[_0xddba('0x29')]=0x0;_0x5c0b83[_0xddba('0x2a')]=0x0;}function clearCampaigns(_0x5031ca){if(!_[_0xddba('0x2b')](_0x5031ca)){for(var _0x498aac in _0x5031ca){if(_0x5031ca[_0xddba('0x21')](_0x498aac)){_0x5031ca[_0x498aac][_0xddba('0x2c')]=0x0;_0x5031ca[_0x498aac][_0xddba('0x2d')]=0x0;}}}}function clearVoiceQueues(_0x309e56){if(!_[_0xddba('0x2b')](_0x309e56)){for(var _0x1578fc in _0x309e56){if(_0x309e56[_0xddba('0x21')](_0x1578fc)){_0x309e56[_0x1578fc]['total']=0x0;_0x309e56[_0x1578fc][_0xddba('0x2e')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x2f')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x30')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x28')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x29')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x2a')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x31')]=0x0;_0x309e56[_0x1578fc]['outboundNoAnswerCallsDay']=0x0;_0x309e56[_0x1578fc][_0xddba('0x32')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x33')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x34')]=0x0;_0x309e56[_0x1578fc]['outboundUnknownCallsDay']=0x0;_0x309e56[_0x1578fc][_0xddba('0x35')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x36')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x37')]=0x0;_0x309e56[_0x1578fc]['outboundOriginateFailureCallsDay']=0x0;_0x309e56[_0x1578fc]['outboundRejectCallsDay']=0x0;_0x309e56[_0x1578fc][_0xddba('0x38')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x31')]=0x0;_0x309e56[_0x1578fc][_0xddba('0x39')]=0x0;_0x309e56[_0x1578fc]['queueStatusComplete']=!![];}}}}Realtime[_0xddba('0x3a')][_0xddba('0x3b')]=function(_0x82f555,_0x49b27e){for(var _0x29b512 in _0x49b27e){if(_0x82f555[_0xddba('0x21')](_0x29b512)){_0x82f555[_0x29b512]=_0x49b27e[_0x29b512];}}};Realtime[_0xddba('0x3a')]['initAgents']=function(){var _0x4efbc8=this;return function(_0x34e20c){if(_0x34e20c){freeIsNotKeyAgent(_0x34e20c,_0x4efbc8[_0xddba('0x3c')]);for(var _0x5ef804=0x0,_0x51d2e={},_0x3064de={};_0x5ef804<_0x34e20c[_0xddba('0x3d')];_0x5ef804+=0x1){_0x51d2e=_0x34e20c[_0x5ef804];var _0x3ecc3=_[_0xddba('0x23')](_0x51d2e[_0xddba('0x24')])?util[_0xddba('0x22')](_0xddba('0x25'),_0x51d2e[_0xddba('0x26')]):_0x51d2e[_0xddba('0x24')];if(_[_0xddba('0x3e')](_0x4efbc8[_0xddba('0x3c')][_0x3ecc3])){_0x4efbc8[_0xddba('0x3c')][_0x3ecc3]=new Agent(_0x51d2e);}else{_0x4efbc8['mergeFromDatabase'](_0x4efbc8[_0xddba('0x3c')][_0x3ecc3],_0x51d2e);}}}return _0x4efbc8[_0xddba('0x3c')];};};Realtime[_0xddba('0x3a')][_0xddba('0x3f')]=function(){var _0xd40616=this;return function(_0x14d3f2){if(_0x14d3f2){freeIsNotKeySip(_0x14d3f2,_0xd40616['telephones']);for(var _0x4e71e5=0x0,_0x26ad09={},_0x438f18={};_0x4e71e5<_0x14d3f2['length'];_0x4e71e5+=0x1){_0x26ad09=_0x14d3f2[_0x4e71e5];if(_[_0xddba('0x3e')](_0xd40616['telephones'][util[_0xddba('0x22')](_0xddba('0x25'),_0x26ad09['name'])])){_0xd40616[_0xddba('0xe')][util[_0xddba('0x22')]('SIP/%s',_0x26ad09[_0xddba('0x26')])]=new Telephone(_0x26ad09);}else{_0xd40616[_0xddba('0x3b')](_0xd40616['telephones'][util['format'](_0xddba('0x25'),_0x26ad09['name'])],_0x26ad09);}}}return _0xd40616[_0xddba('0xe')];};};Realtime['prototype'][_0xddba('0x40')]=function(){var _0x324f0a=this;return function(_0x20b4c2){if(_0x20b4c2){freeIsNotKeySip(_0x20b4c2,_0x324f0a[_0xddba('0xf')]);for(var _0x45b807=0x0,_0xe7942b={},_0x4fca2a={};_0x45b807<_0x20b4c2[_0xddba('0x3d')];_0x45b807+=0x1){_0xe7942b=_0x20b4c2[_0x45b807];if(_['isUndefined'](_0x324f0a[_0xddba('0xf')][util[_0xddba('0x22')]('SIP/%s',_0xe7942b[_0xddba('0x26')])])){_0x324f0a['trunks'][util[_0xddba('0x22')](_0xddba('0x25'),_0xe7942b[_0xddba('0x26')])]=new Trunk(_0xe7942b);}else{_0x324f0a[_0xddba('0x3b')](_0x324f0a['trunks'][util[_0xddba('0x22')](_0xddba('0x25'),_0xe7942b[_0xddba('0x26')])],_0xe7942b);}}}return _0x324f0a[_0xddba('0xf')];};};Realtime['prototype'][_0xddba('0x41')]=function(){var _0xaa49a4=this;return function(_0x126d2d){if(_0x126d2d){freeIsNotKey(_0x126d2d,_0xaa49a4[_0xddba('0x10')],_0xddba('0x26'));for(var _0x5ded99=0x0,_0x38f5f9={},_0x16ac1b={};_0x5ded99<_0x126d2d[_0xddba('0x3d')];_0x5ded99+=0x1){_0x38f5f9=_0x126d2d[_0x5ded99];if(_[_0xddba('0x3e')](_0xaa49a4[_0xddba('0x10')][_0x38f5f9[_0xddba('0x26')]])){_0xaa49a4[_0xddba('0x10')][_0x38f5f9[_0xddba('0x26')]]=new VoiceQueue(_0x38f5f9);}else{_0xaa49a4['mergeFromDatabase'](_0xaa49a4[_0xddba('0x10')][_0x38f5f9[_0xddba('0x26')]],_0x38f5f9);}}}return _0xaa49a4['voiceQueues'];};};Realtime['prototype'][_0xddba('0x42')]=function(){var _0x289a22=this;return function(_0x163ddf){if(_0x163ddf){freeIsNotKey(_0x163ddf,_0x289a22[_0xddba('0x11')],'id');for(var _0x574f2e=0x0,_0x5692e7={},_0x27b3ed={};_0x574f2e<_0x163ddf['length'];_0x574f2e+=0x1){_0x5692e7=_0x163ddf[_0x574f2e];if(_[_0xddba('0x3e')](_0x289a22[_0xddba('0x11')][_0x5692e7['id']])){_0x289a22[_0xddba('0x11')][_0x5692e7['id']]=new Trigger(_0x5692e7);}else{_0x289a22['mergeFromDatabase'](_0x289a22[_0xddba('0x11')][_0x5692e7['id']],_0x5692e7);}}}return _0x289a22[_0xddba('0x11')];};};Realtime['prototype'][_0xddba('0x43')]=function(){var _0x717d8b=this;return function(_0xfb0215){if(_0xfb0215){freeIsNotKey(_0xfb0215,_0x717d8b[_0xddba('0x13')],'id');for(var _0x292377=0x0,_0x524ea0={},_0x393b17={};_0x292377<_0xfb0215[_0xddba('0x3d')];_0x292377+=0x1){_0x524ea0=_0xfb0215[_0x292377];if(_[_0xddba('0x3e')](_0x717d8b[_0xddba('0x13')][_0x524ea0['id']])){_0x717d8b['templates'][_0x524ea0['id']]=new Template(_0x524ea0);}else{_0x717d8b[_0xddba('0x3b')](_0x717d8b[_0xddba('0x13')][_0x524ea0['id']],_0x524ea0);}}}return _0x717d8b[_0xddba('0x13')];};};Realtime[_0xddba('0x3a')][_0xddba('0x44')]=function(){var _0xb5d4ec=this;return function(_0x392d6a){if(_0x392d6a){freeIsNotKey(_0x392d6a,_0xb5d4ec[_0xddba('0x18')],'id');for(var _0x38f0bc=0x0,_0x721fff={},_0x4b986c={};_0x38f0bc<_0x392d6a[_0xddba('0x3d')];_0x38f0bc+=0x1){_0x721fff=_0x392d6a[_0x38f0bc];if(_[_0xddba('0x3e')](_0xb5d4ec['zendeskAccounts'][_0x721fff['id']])){_0xb5d4ec[_0xddba('0x18')][_0x721fff['id']]=new ZendeskAccount(_0x721fff);}else{_0xb5d4ec[_0xddba('0x3b')](_0xb5d4ec['zendeskAccounts'][_0x721fff['id']],_0x721fff);}}}return _0xb5d4ec[_0xddba('0x18')];};};Realtime[_0xddba('0x3a')][_0xddba('0x45')]=function(){var _0x4135a6=this;return function(_0x5db630){if(_0x5db630){freeIsNotKey(_0x5db630,_0x4135a6[_0xddba('0x46')],'id');for(var _0x4e0f65=0x0,_0x2da85e={},_0xcd031c={};_0x4e0f65<_0x5db630[_0xddba('0x3d')];_0x4e0f65+=0x1){_0x2da85e=_0x5db630[_0x4e0f65];if(_[_0xddba('0x3e')](_0x4135a6[_0xddba('0x46')][_0x2da85e['id']])){_0x4135a6[_0xddba('0x46')][_0x2da85e['id']]=new SalesforceAccount(_0x2da85e);}else{_0x4135a6[_0xddba('0x3b')](_0x4135a6['salesforceAccounts'][_0x2da85e['id']],_0x2da85e);}}}return _0x4135a6['salesforceAccounts'];};};Realtime[_0xddba('0x3a')][_0xddba('0x47')]=function(){var _0x2ead06=this;return function(_0x424527){if(_0x424527){freeIsNotKey(_0x424527,_0x2ead06['freshdeskAccounts'],'id');for(var _0x47ac74=0x0,_0x3cdfad={},_0x45c962={};_0x47ac74<_0x424527[_0xddba('0x3d')];_0x47ac74+=0x1){_0x3cdfad=_0x424527[_0x47ac74];if(_[_0xddba('0x3e')](_0x2ead06[_0xddba('0x48')][_0x3cdfad['id']])){_0x2ead06[_0xddba('0x48')][_0x3cdfad['id']]=new FreshdeskAccount(_0x3cdfad);}else{_0x2ead06['mergeFromDatabase'](_0x2ead06[_0xddba('0x48')][_0x3cdfad['id']],_0x3cdfad);}}}return _0x2ead06[_0xddba('0x48')];};};Realtime[_0xddba('0x3a')][_0xddba('0x49')]=function(){var _0x4cfb55=this;return function(_0x4cf66d){if(_0x4cf66d){freeIsNotKey(_0x4cf66d,_0x4cfb55[_0xddba('0x1a')],'id');for(var _0x28cf03=0x0,_0x4af37e={},_0x1780e6={};_0x28cf03<_0x4cf66d[_0xddba('0x3d')];_0x28cf03+=0x1){_0x4af37e=_0x4cf66d[_0x28cf03];if(_[_0xddba('0x3e')](_0x4cfb55['zohoAccounts'][_0x4af37e['id']])){_0x4cfb55[_0xddba('0x1a')][_0x4af37e['id']]=new ZohoAccount(_0x4af37e);}else{_0x4cfb55[_0xddba('0x3b')](_0x4cfb55['zohoAccounts'][_0x4af37e['id']],_0x4af37e);}}}return _0x4cfb55[_0xddba('0x1a')];};};Realtime[_0xddba('0x3a')][_0xddba('0x4a')]=function(){var _0x47df9b=this;return function(_0x3516e6){if(_0x3516e6){freeIsNotKey(_0x3516e6,_0x47df9b['deskAccounts'],'id');for(var _0x9777f7=0x0,_0x5d175b={},_0x106a7b={};_0x9777f7<_0x3516e6[_0xddba('0x3d')];_0x9777f7+=0x1){_0x5d175b=_0x3516e6[_0x9777f7];if(_[_0xddba('0x3e')](_0x47df9b[_0xddba('0x1b')][_0x5d175b['id']])){_0x47df9b[_0xddba('0x1b')][_0x5d175b['id']]=new DeskAccount(_0x5d175b);}else{_0x47df9b['mergeFromDatabase'](_0x47df9b[_0xddba('0x1b')][_0x5d175b['id']],_0x5d175b);}}}return _0x47df9b[_0xddba('0x1b')];};};Realtime['prototype'][_0xddba('0x4b')]=function(){var _0x23f30e=this;return function(_0x49ccf7){if(_0x49ccf7){freeIsNotKey(_0x49ccf7,_0x23f30e[_0xddba('0x19')],'id');for(var _0x6f73b2=0x0,_0x4a1650={},_0x345e96={};_0x6f73b2<_0x49ccf7[_0xddba('0x3d')];_0x6f73b2+=0x1){_0x4a1650=_0x49ccf7[_0x6f73b2];if(_['isUndefined'](_0x23f30e['sugarcrmAccounts'][_0x4a1650['id']])){_0x23f30e[_0xddba('0x19')][_0x4a1650['id']]=new SugarcrmAccount(_0x4a1650);}else{_0x23f30e[_0xddba('0x3b')](_0x23f30e[_0xddba('0x19')][_0x4a1650['id']],_0x4a1650);}}}return _0x23f30e[_0xddba('0x19')];};};Realtime[_0xddba('0x3a')][_0xddba('0x4c')]=function(){var _0x40daec=this;return function(_0x17522e){if(_0x17522e){freeIsNotKey(_0x17522e,_0x40daec[_0xddba('0x1c')],'id');for(var _0x385e7c=0x0,_0x20da65={},_0x1be705={};_0x385e7c<_0x17522e[_0xddba('0x3d')];_0x385e7c+=0x1){_0x20da65=_0x17522e[_0x385e7c];if(_[_0xddba('0x3e')](_0x40daec[_0xddba('0x1c')][_0x20da65['id']])){_0x40daec[_0xddba('0x1c')][_0x20da65['id']]=new VtigerAccount(_0x20da65);}else{_0x40daec[_0xddba('0x3b')](_0x40daec[_0xddba('0x1c')][_0x20da65['id']],_0x20da65);}}}return _0x40daec['vtigerAccounts'];};};Realtime[_0xddba('0x3a')]['initServicenowAccounts']=function(){var _0x1930f8=this;return function(_0x2c32c3){if(_0x2c32c3){freeIsNotKey(_0x2c32c3,_0x1930f8[_0xddba('0x1d')],'id');for(var _0x2071fa=0x0,_0x2aaa7f={},_0x53204a={};_0x2071fa<_0x2c32c3[_0xddba('0x3d')];_0x2071fa+=0x1){_0x2aaa7f=_0x2c32c3[_0x2071fa];if(_[_0xddba('0x3e')](_0x1930f8['servicenowAccounts'][_0x2aaa7f['id']])){_0x1930f8[_0xddba('0x1d')][_0x2aaa7f['id']]=new ServicenowAccount(_0x2aaa7f);}else{_0x1930f8[_0xddba('0x3b')](_0x1930f8[_0xddba('0x1d')][_0x2aaa7f['id']],_0x2aaa7f);}}}return _0x1930f8[_0xddba('0x1d')];};};Realtime[_0xddba('0x3a')][_0xddba('0x4d')]=function(){var _0x2736c7=this;return function(_0x2606f4){if(_0x2606f4){freeIsNotKey(_0x2606f4,_0x2736c7[_0xddba('0x1e')],'id');for(var _0x3854a0=0x0,_0x40c02e={},_0x50d250={};_0x3854a0<_0x2606f4[_0xddba('0x3d')];_0x3854a0+=0x1){_0x40c02e=_0x2606f4[_0x3854a0];if(_[_0xddba('0x3e')](_0x2736c7[_0xddba('0x1e')][_0x40c02e['id']])){_0x2736c7['dynamics365Accounts'][_0x40c02e['id']]=new Dynamics365Account(_0x40c02e);}else{_0x2736c7['mergeFromDatabase'](_0x2736c7[_0xddba('0x1e')][_0x40c02e['id']],_0x40c02e);}}}return _0x2736c7[_0xddba('0x1e')];};};Realtime[_0xddba('0x3a')][_0xddba('0x4e')]=function(){var _0x4953b6=this;return function(_0x5cb27a){if(_0x5cb27a){freeIsNotKey(_0x5cb27a,_0x4953b6['freshsalesAccounts'],'id');for(var _0x2ed297=0x0,_0x3336b6={},_0x39bfe8={};_0x2ed297<_0x5cb27a[_0xddba('0x3d')];_0x2ed297+=0x1){_0x3336b6=_0x5cb27a[_0x2ed297];if(_[_0xddba('0x3e')](_0x4953b6['freshsalesAccounts'][_0x3336b6['id']])){_0x4953b6[_0xddba('0x4f')][_0x3336b6['id']]=new FreshsalesAccount(_0x3336b6);}else{_0x4953b6['mergeFromDatabase'](_0x4953b6['freshsalesAccounts'][_0x3336b6['id']],_0x3336b6);}}}return _0x4953b6[_0xddba('0x4f')];};};Realtime[_0xddba('0x3a')][_0xddba('0x50')]=function(){var _0x2d0c0b=this;return function(_0x38a1c2){for(var _0x5ba1b5=0x0;_0x5ba1b5<_0x38a1c2[_0xddba('0x3d')];_0x5ba1b5+=0x1){_[_0xddba('0x51')](_0x2d0c0b['voiceQueues'][_0x38a1c2[_0x5ba1b5][_0xddba('0x26')]],_0x38a1c2[_0x5ba1b5]);}return _0x2d0c0b[_0xddba('0x10')];};};Realtime[_0xddba('0x3a')][_0xddba('0x52')]=function(){var _0x573e1e=this;return function(_0x221de5){clearVoiceQueues(_0x573e1e[_0xddba('0x10')]);if(_0x221de5){_0x221de5=_['groupBy'](_0x221de5,'uniqueid');for(var _0xbc3c49 in _0x221de5){if(_0x221de5['hasOwnProperty'](_0xbc3c49)){var _0xb3f887={};for(var _0x787ad2=0x0;_0x787ad2<_0x221de5[_0xbc3c49][_0xddba('0x3d')];_0x787ad2+=0x1){var _0x31a47d=_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x53')];if(_0x573e1e[_0xddba('0x10')][_0x31a47d]){if(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x54')]){_0x573e1e[_0xddba('0x10')][_0x31a47d][_0xddba('0x2f')]+=0x1;}if(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x55')]){_0x573e1e['voiceQueues'][_0x31a47d][_0xddba('0x30')]+=0x1;}_0x573e1e['voiceQueues'][_0x31a47d]['sumHoldTime']+=moment(_0x221de5[_0xbc3c49][_0x787ad2]['queuecallerleaveAt'])[_0xddba('0x56')](moment(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x57')]),_0xddba('0x58'))||0x0;if(_0x787ad2===_0x221de5[_0xbc3c49][_0xddba('0x3d')]-0x1){_0x573e1e[_0xddba('0x10')][_0x31a47d]['sumDuration']+=moment(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x59')]||_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x5a')]||_0x221de5[_0xbc3c49][_0x787ad2]['queuecallerexitAt'])[_0xddba('0x56')](moment(_0x221de5[_0xbc3c49][_0x787ad2]['queuecallerjoinAt']),_0xddba('0x58'))||0x0;_0x573e1e[_0xddba('0x10')][_0x31a47d][_0xddba('0x27')]+=0x1;if(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x5b')]){_0x573e1e['voiceQueues'][_0x31a47d][_0xddba('0x2e')]+=0x1;_0x573e1e['voiceQueues'][_0x31a47d][_0xddba('0x2a')]+=moment(_0x221de5[_0xbc3c49][_0x787ad2][_0xddba('0x59')])[_0xddba('0x56')](moment(_0x221de5[_0xbc3c49][_0x787ad2]['queuecallerleaveAt']),'seconds')||0x0;}}else{_0x573e1e[_0xddba('0x10')][_0x31a47d][_0xddba('0x29')]+=_0x573e1e[_0xddba('0x10')][_0x31a47d]['sumHoldTime']||0x0;}}}}}}return _0x573e1e['voiceQueues'];};};Realtime[_0xddba('0x3a')][_0xddba('0x5c')]=function(){var _0x2befd7=this;return function(_0x181829){clearVoiceCallReports(_0x2befd7[_0xddba('0x14')]);if(_0x181829){for(var _0x401d1a=0x0;_0x401d1a<_0x181829[_0xddba('0x3d')];_0x401d1a+=0x1){_0x2befd7[_0xddba('0x14')]['total']+=0x1;_0x2befd7['outbound'][_0xddba('0x29')]+=_0x181829[_0x401d1a][_0xddba('0x5d')];if(_0x181829[_0x401d1a]['disposition']===_0xddba('0x5e')){_0x2befd7['outbound'][_0xddba('0x2e')]+=0x1;_0x2befd7['outbound']['sumHoldTime']+=_0x181829[_0x401d1a][_0xddba('0x5d')]-_0x181829[_0x401d1a]['billableseconds']||0x0;_0x2befd7['outbound'][_0xddba('0x2a')]+=_0x181829[_0x401d1a][_0xddba('0x5f')];}}}return _0x2befd7['outbound'];};};Realtime[_0xddba('0x3a')][_0xddba('0x60')]=function(){var _0x4c74c1=this;return function(_0x51a546){if(_0x51a546){freeIsNotKey(_0x51a546,_0x4c74c1['campaigns'],_0xddba('0x26'));for(var _0x576b78=0x0,_0x9595f6={};_0x576b78<_0x51a546[_0xddba('0x3d')];_0x576b78+=0x1){_0x9595f6=_0x51a546[_0x576b78];if(_[_0xddba('0x3e')](_0x4c74c1[_0xddba('0x12')][_0x9595f6[_0xddba('0x26')]])){_0x4c74c1[_0xddba('0x12')][_0x9595f6[_0xddba('0x26')]]=new Campaign(_0x9595f6);}else{_0x4c74c1[_0xddba('0x3b')](_0x4c74c1[_0xddba('0x12')][_0x9595f6[_0xddba('0x26')]],_0x9595f6);_0x4c74c1['campaigns'][_0x9595f6[_0xddba('0x26')]][_0xddba('0x61')]=_0x9595f6[_0xddba('0x62')]?_0x9595f6[_0xddba('0x62')][_0xddba('0x26')]:undefined;}}}return _0x4c74c1[_0xddba('0x12')];};};Realtime[_0xddba('0x3a')][_0xddba('0x63')]=function(){var _0x92fc0d=this;return function(_0x3822ca){if(_0x3822ca){freeIsNotKey(_0x3822ca,_0x92fc0d[_0xddba('0x64')],'id');for(var _0x85a327=0x0,_0x16e001={};_0x85a327<_0x3822ca[_0xddba('0x3d')];_0x85a327+=0x1){_0x16e001=_0x3822ca[_0x85a327];if(_[_0xddba('0x3e')](_0x92fc0d[_0xddba('0x64')][_0x16e001['id']])){_0x92fc0d['voiceExtensions'][_0x16e001['id']]=new VoiceExtension(_0x16e001);}else{_0x92fc0d[_0xddba('0x3b')](_0x92fc0d[_0xddba('0x64')][_0x16e001['id']],_0x16e001);}}}return _0x92fc0d['voiceExtensions'];};};Realtime['prototype'][_0xddba('0x65')]=function(){var _0x261bc4=this;return function(_0x83123){clearCampaigns(_0x261bc4[_0xddba('0x12')]);for(var _0x2cc8ae=0x0;_0x2cc8ae<_0x83123[_0xddba('0x3d')];_0x2cc8ae+=0x1){_[_0xddba('0x51')](_0x261bc4[_0xddba('0x12')][_0x83123[_0x2cc8ae]['name']],_0x83123[_0x2cc8ae]);}return _0x261bc4[_0xddba('0x12')];};};Realtime['prototype'][_0xddba('0x66')]=function(){var _0x182f63=this;return function(_0x3ba8e7){if(_0x3ba8e7){freeIsNotKey(_0x3ba8e7,_0x182f63['faxAccounts'],'id');for(var _0xec9594=0x0,_0x13941f={},_0x26a349={};_0xec9594<_0x3ba8e7[_0xddba('0x3d')];_0xec9594+=0x1){_0x13941f=_0x3ba8e7[_0xec9594];if(_[_0xddba('0x3e')](_0x182f63['faxAccounts'][_0x13941f['id']])){_0x182f63[_0xddba('0x1f')][_0x13941f['id']]=new FaxAccount(_0x13941f);}else{_0x182f63['mergeFromDatabase'](_0x182f63[_0xddba('0x1f')][_0x13941f['id']],_0x13941f);}}}return _0x182f63[_0xddba('0x1f')];};};module[_0xddba('0x67')]=Realtime;