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 _0xc35b=['sumDuration','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundCongestionCallsDay','outboundNoSuchCallsDay','outboundUnknownCallsDay','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundRejectCallsDay','prototype','mergeFromDatabase','initAgents','length','isUndefined','initTelephones','initTrunks','trunks','initVoiceQueues','initTriggers','initTemplates','zendeskAccounts','initSalesforceAccounts','initZohoAccounts','initDeskAccounts','deskAccounts','initSugarcrmAccounts','sugarcrmAccounts','initVtigerAccounts','initServicenowAccounts','initDynamics365Accounts','initFreshsalesAccounts','initVoiceQueueHopperHistory','merge','initVoiceQueueReports','uniqueid','queue','queuecallerexit','queuecallerabandon','diff','queuecallerjoinAt','seconds','queuecallercompleteAt','queuecallerexitAt','queuecallercomplete','queuecallerleaveAt','sumHoldTime','initVoiceCallReports','duration','ANSWERED','billableseconds','initCampaigns','dialQueueProject','SquareProject','initVoiceExtensions','voiceExtensions','initCampaignHopperHistory','initFaxAccounts','faxAccounts','util','lodash','../model/agent','../model/trigger','../model/template','../model/zendeskAccount','../model/salesforceAccount','../model/freshdeskAccount','../model/sugarcrmAccount','../model/zohoAccount','../model/deskAccount','../model/dynamics365Account','../model/faxAccount','agents','telephones','voiceQueues','triggers','campaigns','templates','outbound','channels','queueChannels','outboundChannels','salesforceAccounts','freshdeskAccounts','zohoAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','hasOwnProperty','mapKeys','format','isNil','SIP/%s','name','interface','total','answered','sumBillable','isEmpty','ivrTotalCallsDays','ivrAnswerCallsDay','unmanaged','abandoned'];(function(_0x4d8392,_0x32986a){var _0x2cc00a=function(_0x2719dd){while(--_0x2719dd){_0x4d8392['push'](_0x4d8392['shift']());}};_0x2cc00a(++_0x32986a);}(_0xc35b,0xa3));var _0xbc35=function(_0x4baae2,_0x487ab6){_0x4baae2=_0x4baae2-0x0;var _0x1a2285=_0xc35b[_0x4baae2];return _0x1a2285;};'use strict';var BPromise=require('bluebird');var util=require(_0xbc35('0x0'));var _=require(_0xbc35('0x1'));var moment=require('moment');var Agent=require(_0xbc35('0x2'));var Telephone=require('../model/telephone');var Trunk=require('../model/trunk');var VoiceQueue=require('../model/voiceQueue');var Trigger=require(_0xbc35('0x3'));var Template=require(_0xbc35('0x4'));var Campaign=require('../model/campaign');var VoiceExtension=require('../model/voiceExtension');var ZendeskAccount=require(_0xbc35('0x5'));var SalesforceAccount=require(_0xbc35('0x6'));var FreshdeskAccount=require(_0xbc35('0x7'));var SugarcrmAccount=require(_0xbc35('0x8'));var ZohoAccount=require(_0xbc35('0x9'));var DeskAccount=require(_0xbc35('0xa'));var VtigerAccount=require('../model/vtigerAccount');var ServicenowAccount=require('../model/servicenowAccount');var Dynamics365Account=require(_0xbc35('0xb'));var FreshsalesAccount=require('../model/freshsalesAccount');var FaxAccount=require(_0xbc35('0xc'));var Realtime=function(){this[_0xbc35('0xd')]={};this[_0xbc35('0xe')]={};this['trunks']={};this[_0xbc35('0xf')]={};this[_0xbc35('0x10')]={};this[_0xbc35('0x11')]={};this[_0xbc35('0x12')]={};this[_0xbc35('0x13')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this['voiceExtensions']={};this[_0xbc35('0x14')]={};this[_0xbc35('0x15')]={};this[_0xbc35('0x16')]={};this['timers']={};this['zendeskAccounts']={};this[_0xbc35('0x17')]={};this['sugarcrmAccounts']={};this[_0xbc35('0x18')]={};this[_0xbc35('0x19')]={};this['deskAccounts']={};this[_0xbc35('0x1a')]={};this[_0xbc35('0x1b')]={};this[_0xbc35('0x1c')]={};this[_0xbc35('0x1d')]={};this['faxAccounts']={};};function freeIsNotKey(_0x4575a2,_0x13d906,_0x596cda){var _0x3166f1=_['mapKeys'](_0x4575a2,function(_0x1582ff,_0x110754){return _0x1582ff[_0x596cda];});for(var _0x219c25 in _0x13d906){if(_0x13d906[_0xbc35('0x1e')](_0x219c25)){if(!_0x3166f1[_0x219c25]){delete _0x13d906[_0x219c25];}}}}function freeIsNotKeySip(_0x2ae91c,_0x1f9ffd){var _0x4a95e3=_[_0xbc35('0x1f')](_0x2ae91c,function(_0x10ad4a,_0x42d75b){return util[_0xbc35('0x20')]('SIP/%s',_0x10ad4a['name']);});for(var _0x11ec73 in _0x1f9ffd){if(_0x1f9ffd['hasOwnProperty'](_0x11ec73)){if(!_0x4a95e3[_0x11ec73]){delete _0x1f9ffd[_0x11ec73];}}}}function freeIsNotKeyAgent(_0x3b2877,_0x138350){var _0x53d546=_['mapKeys'](_0x3b2877,function(_0x45e91d,_0x100f72){var _0x5993db=_[_0xbc35('0x21')](_0x45e91d['interface'])?util['format'](_0xbc35('0x22'),_0x45e91d[_0xbc35('0x23')]):_0x45e91d[_0xbc35('0x24')];return _0x5993db;});for(var _0x45eb9c in _0x138350){if(_0x138350[_0xbc35('0x1e')](_0x45eb9c)){if(!_0x53d546[_0x45eb9c]){delete _0x138350[_0x45eb9c];}}}}function clearVoiceCallReports(_0x1050f5){_0x1050f5[_0xbc35('0x25')]=0x0;_0x1050f5[_0xbc35('0x26')]=0x0;_0x1050f5['sumHoldTime']=0x0;_0x1050f5['sumDuration']=0x0;_0x1050f5[_0xbc35('0x27')]=0x0;}function clearCampaigns(_0x510ae1){if(!_[_0xbc35('0x28')](_0x510ae1)){for(var _0x7e3f77 in _0x510ae1){if(_0x510ae1['hasOwnProperty'](_0x7e3f77)){_0x510ae1[_0x7e3f77][_0xbc35('0x29')]=0x0;_0x510ae1[_0x7e3f77][_0xbc35('0x2a')]=0x0;}}}}function clearVoiceQueues(_0x3e7fbd){if(!_[_0xbc35('0x28')](_0x3e7fbd)){for(var _0x134a60 in _0x3e7fbd){if(_0x3e7fbd['hasOwnProperty'](_0x134a60)){_0x3e7fbd[_0x134a60][_0xbc35('0x25')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x26')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2b')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2c')]=0x0;_0x3e7fbd[_0x134a60]['sumHoldTime']=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2d')]=0x0;_0x3e7fbd[_0x134a60]['sumBillable']=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2e')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2f')]=0x0;_0x3e7fbd[_0x134a60]['outboundBusyCallsDay']=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x30')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x31')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x32')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x33')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x34')]=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x35')]=0x0;_0x3e7fbd[_0x134a60]['outboundOriginateFailureCallsDay']=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x36')]=0x0;_0x3e7fbd[_0x134a60]['outboundReCallsDay']=0x0;_0x3e7fbd[_0x134a60][_0xbc35('0x2e')]=0x0;_0x3e7fbd[_0x134a60]['outboundAnswerCallsDay']=0x0;_0x3e7fbd[_0x134a60]['queueStatusComplete']=!![];}}}}Realtime[_0xbc35('0x37')][_0xbc35('0x38')]=function(_0x284871,_0x25edb6){for(var _0x174ce9 in _0x25edb6){if(_0x284871['hasOwnProperty'](_0x174ce9)){_0x284871[_0x174ce9]=_0x25edb6[_0x174ce9];}}};Realtime[_0xbc35('0x37')][_0xbc35('0x39')]=function(){var _0x276f10=this;return function(_0x488ea1){if(_0x488ea1){freeIsNotKeyAgent(_0x488ea1,_0x276f10[_0xbc35('0xd')]);for(var _0x140d8d=0x0,_0xe7385b={},_0x10faa8={};_0x140d8d<_0x488ea1[_0xbc35('0x3a')];_0x140d8d+=0x1){_0xe7385b=_0x488ea1[_0x140d8d];var _0x4c6d92=_[_0xbc35('0x21')](_0xe7385b[_0xbc35('0x24')])?util['format'](_0xbc35('0x22'),_0xe7385b[_0xbc35('0x23')]):_0xe7385b[_0xbc35('0x24')];if(_[_0xbc35('0x3b')](_0x276f10['agents'][_0x4c6d92])){_0x276f10[_0xbc35('0xd')][_0x4c6d92]=new Agent(_0xe7385b);}else{_0x276f10[_0xbc35('0x38')](_0x276f10[_0xbc35('0xd')][_0x4c6d92],_0xe7385b);}}}return _0x276f10[_0xbc35('0xd')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x3c')]=function(){var _0x1107b5=this;return function(_0x32105f){if(_0x32105f){freeIsNotKeySip(_0x32105f,_0x1107b5[_0xbc35('0xe')]);for(var _0x167728=0x0,_0x120d39={},_0x1ea212={};_0x167728<_0x32105f[_0xbc35('0x3a')];_0x167728+=0x1){_0x120d39=_0x32105f[_0x167728];if(_[_0xbc35('0x3b')](_0x1107b5[_0xbc35('0xe')][util['format']('SIP/%s',_0x120d39['name'])])){_0x1107b5[_0xbc35('0xe')][util[_0xbc35('0x20')](_0xbc35('0x22'),_0x120d39[_0xbc35('0x23')])]=new Telephone(_0x120d39);}else{_0x1107b5['mergeFromDatabase'](_0x1107b5[_0xbc35('0xe')][util[_0xbc35('0x20')]('SIP/%s',_0x120d39[_0xbc35('0x23')])],_0x120d39);}}}return _0x1107b5[_0xbc35('0xe')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x3d')]=function(){var _0x36bb8a=this;return function(_0x2d645e){if(_0x2d645e){freeIsNotKeySip(_0x2d645e,_0x36bb8a[_0xbc35('0x3e')]);for(var _0x483d3c=0x0,_0x212485={},_0x433df6={};_0x483d3c<_0x2d645e[_0xbc35('0x3a')];_0x483d3c+=0x1){_0x212485=_0x2d645e[_0x483d3c];if(_['isUndefined'](_0x36bb8a[_0xbc35('0x3e')][util[_0xbc35('0x20')](_0xbc35('0x22'),_0x212485['name'])])){_0x36bb8a['trunks'][util[_0xbc35('0x20')](_0xbc35('0x22'),_0x212485['name'])]=new Trunk(_0x212485);}else{_0x36bb8a[_0xbc35('0x38')](_0x36bb8a[_0xbc35('0x3e')][util['format'](_0xbc35('0x22'),_0x212485['name'])],_0x212485);}}}return _0x36bb8a[_0xbc35('0x3e')];};};Realtime['prototype'][_0xbc35('0x3f')]=function(){var _0x2df980=this;return function(_0xa2fd26){if(_0xa2fd26){freeIsNotKey(_0xa2fd26,_0x2df980['voiceQueues'],_0xbc35('0x23'));for(var _0x49b6c2=0x0,_0x117131={},_0x11911a={};_0x49b6c2<_0xa2fd26[_0xbc35('0x3a')];_0x49b6c2+=0x1){_0x117131=_0xa2fd26[_0x49b6c2];if(_['isUndefined'](_0x2df980['voiceQueues'][_0x117131[_0xbc35('0x23')]])){_0x2df980[_0xbc35('0xf')][_0x117131[_0xbc35('0x23')]]=new VoiceQueue(_0x117131);}else{_0x2df980[_0xbc35('0x38')](_0x2df980[_0xbc35('0xf')][_0x117131[_0xbc35('0x23')]],_0x117131);}}}return _0x2df980[_0xbc35('0xf')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x40')]=function(){var _0x2abf1f=this;return function(_0x3bfb6f){if(_0x3bfb6f){freeIsNotKey(_0x3bfb6f,_0x2abf1f['triggers'],'id');for(var _0xbde9=0x0,_0x2da164={},_0x565d27={};_0xbde9<_0x3bfb6f['length'];_0xbde9+=0x1){_0x2da164=_0x3bfb6f[_0xbde9];if(_['isUndefined'](_0x2abf1f[_0xbc35('0x10')][_0x2da164['id']])){_0x2abf1f[_0xbc35('0x10')][_0x2da164['id']]=new Trigger(_0x2da164);}else{_0x2abf1f[_0xbc35('0x38')](_0x2abf1f[_0xbc35('0x10')][_0x2da164['id']],_0x2da164);}}}return _0x2abf1f[_0xbc35('0x10')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x41')]=function(){var _0x1f34e1=this;return function(_0x5439de){if(_0x5439de){freeIsNotKey(_0x5439de,_0x1f34e1[_0xbc35('0x12')],'id');for(var _0x37d932=0x0,_0x49e1dd={},_0x20b8bf={};_0x37d932<_0x5439de[_0xbc35('0x3a')];_0x37d932+=0x1){_0x49e1dd=_0x5439de[_0x37d932];if(_['isUndefined'](_0x1f34e1[_0xbc35('0x12')][_0x49e1dd['id']])){_0x1f34e1[_0xbc35('0x12')][_0x49e1dd['id']]=new Template(_0x49e1dd);}else{_0x1f34e1[_0xbc35('0x38')](_0x1f34e1[_0xbc35('0x12')][_0x49e1dd['id']],_0x49e1dd);}}}return _0x1f34e1['templates'];};};Realtime[_0xbc35('0x37')]['initZendeskAccounts']=function(){var _0x47fbd4=this;return function(_0x414d22){if(_0x414d22){freeIsNotKey(_0x414d22,_0x47fbd4[_0xbc35('0x42')],'id');for(var _0x27be55=0x0,_0x2faf50={},_0x10b9db={};_0x27be55<_0x414d22[_0xbc35('0x3a')];_0x27be55+=0x1){_0x2faf50=_0x414d22[_0x27be55];if(_[_0xbc35('0x3b')](_0x47fbd4['zendeskAccounts'][_0x2faf50['id']])){_0x47fbd4[_0xbc35('0x42')][_0x2faf50['id']]=new ZendeskAccount(_0x2faf50);}else{_0x47fbd4['mergeFromDatabase'](_0x47fbd4[_0xbc35('0x42')][_0x2faf50['id']],_0x2faf50);}}}return _0x47fbd4[_0xbc35('0x42')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x43')]=function(){var _0x5a928a=this;return function(_0x481957){if(_0x481957){freeIsNotKey(_0x481957,_0x5a928a[_0xbc35('0x17')],'id');for(var _0x4f87f0=0x0,_0x309af1={},_0x13e587={};_0x4f87f0<_0x481957[_0xbc35('0x3a')];_0x4f87f0+=0x1){_0x309af1=_0x481957[_0x4f87f0];if(_[_0xbc35('0x3b')](_0x5a928a[_0xbc35('0x17')][_0x309af1['id']])){_0x5a928a[_0xbc35('0x17')][_0x309af1['id']]=new SalesforceAccount(_0x309af1);}else{_0x5a928a[_0xbc35('0x38')](_0x5a928a[_0xbc35('0x17')][_0x309af1['id']],_0x309af1);}}}return _0x5a928a[_0xbc35('0x17')];};};Realtime[_0xbc35('0x37')]['initFreshdeskAccounts']=function(){var _0x4a5490=this;return function(_0x52d246){if(_0x52d246){freeIsNotKey(_0x52d246,_0x4a5490[_0xbc35('0x18')],'id');for(var _0x29ad03=0x0,_0x3db58e={},_0x505a1b={};_0x29ad03<_0x52d246[_0xbc35('0x3a')];_0x29ad03+=0x1){_0x3db58e=_0x52d246[_0x29ad03];if(_[_0xbc35('0x3b')](_0x4a5490[_0xbc35('0x18')][_0x3db58e['id']])){_0x4a5490[_0xbc35('0x18')][_0x3db58e['id']]=new FreshdeskAccount(_0x3db58e);}else{_0x4a5490[_0xbc35('0x38')](_0x4a5490[_0xbc35('0x18')][_0x3db58e['id']],_0x3db58e);}}}return _0x4a5490[_0xbc35('0x18')];};};Realtime['prototype'][_0xbc35('0x44')]=function(){var _0x2ed830=this;return function(_0x38da92){if(_0x38da92){freeIsNotKey(_0x38da92,_0x2ed830['zohoAccounts'],'id');for(var _0x1d1292=0x0,_0xddd0cb={},_0x1be965={};_0x1d1292<_0x38da92[_0xbc35('0x3a')];_0x1d1292+=0x1){_0xddd0cb=_0x38da92[_0x1d1292];if(_[_0xbc35('0x3b')](_0x2ed830[_0xbc35('0x19')][_0xddd0cb['id']])){_0x2ed830['zohoAccounts'][_0xddd0cb['id']]=new ZohoAccount(_0xddd0cb);}else{_0x2ed830[_0xbc35('0x38')](_0x2ed830[_0xbc35('0x19')][_0xddd0cb['id']],_0xddd0cb);}}}return _0x2ed830[_0xbc35('0x19')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x45')]=function(){var _0x1030b4=this;return function(_0x1b7bc5){if(_0x1b7bc5){freeIsNotKey(_0x1b7bc5,_0x1030b4[_0xbc35('0x46')],'id');for(var _0x2b0ec5=0x0,_0x1aecd1={},_0x3ea6cf={};_0x2b0ec5<_0x1b7bc5[_0xbc35('0x3a')];_0x2b0ec5+=0x1){_0x1aecd1=_0x1b7bc5[_0x2b0ec5];if(_[_0xbc35('0x3b')](_0x1030b4[_0xbc35('0x46')][_0x1aecd1['id']])){_0x1030b4['deskAccounts'][_0x1aecd1['id']]=new DeskAccount(_0x1aecd1);}else{_0x1030b4[_0xbc35('0x38')](_0x1030b4[_0xbc35('0x46')][_0x1aecd1['id']],_0x1aecd1);}}}return _0x1030b4[_0xbc35('0x46')];};};Realtime['prototype'][_0xbc35('0x47')]=function(){var _0x29cec0=this;return function(_0x40f96f){if(_0x40f96f){freeIsNotKey(_0x40f96f,_0x29cec0[_0xbc35('0x48')],'id');for(var _0x4fd8b2=0x0,_0x199509={},_0x3baf16={};_0x4fd8b2<_0x40f96f[_0xbc35('0x3a')];_0x4fd8b2+=0x1){_0x199509=_0x40f96f[_0x4fd8b2];if(_[_0xbc35('0x3b')](_0x29cec0[_0xbc35('0x48')][_0x199509['id']])){_0x29cec0['sugarcrmAccounts'][_0x199509['id']]=new SugarcrmAccount(_0x199509);}else{_0x29cec0[_0xbc35('0x38')](_0x29cec0['sugarcrmAccounts'][_0x199509['id']],_0x199509);}}}return _0x29cec0['sugarcrmAccounts'];};};Realtime['prototype'][_0xbc35('0x49')]=function(){var _0x3f5374=this;return function(_0x3ad4eb){if(_0x3ad4eb){freeIsNotKey(_0x3ad4eb,_0x3f5374[_0xbc35('0x1a')],'id');for(var _0x515f9c=0x0,_0x1ccda7={},_0x419fd7={};_0x515f9c<_0x3ad4eb[_0xbc35('0x3a')];_0x515f9c+=0x1){_0x1ccda7=_0x3ad4eb[_0x515f9c];if(_[_0xbc35('0x3b')](_0x3f5374[_0xbc35('0x1a')][_0x1ccda7['id']])){_0x3f5374['vtigerAccounts'][_0x1ccda7['id']]=new VtigerAccount(_0x1ccda7);}else{_0x3f5374[_0xbc35('0x38')](_0x3f5374[_0xbc35('0x1a')][_0x1ccda7['id']],_0x1ccda7);}}}return _0x3f5374[_0xbc35('0x1a')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x4a')]=function(){var _0x2e5fc6=this;return function(_0x41aecf){if(_0x41aecf){freeIsNotKey(_0x41aecf,_0x2e5fc6['servicenowAccounts'],'id');for(var _0x5abaf3=0x0,_0x21d7a4={},_0x1dcf34={};_0x5abaf3<_0x41aecf[_0xbc35('0x3a')];_0x5abaf3+=0x1){_0x21d7a4=_0x41aecf[_0x5abaf3];if(_['isUndefined'](_0x2e5fc6[_0xbc35('0x1b')][_0x21d7a4['id']])){_0x2e5fc6['servicenowAccounts'][_0x21d7a4['id']]=new ServicenowAccount(_0x21d7a4);}else{_0x2e5fc6[_0xbc35('0x38')](_0x2e5fc6['servicenowAccounts'][_0x21d7a4['id']],_0x21d7a4);}}}return _0x2e5fc6[_0xbc35('0x1b')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x4b')]=function(){var _0x9084be=this;return function(_0x2bef14){if(_0x2bef14){freeIsNotKey(_0x2bef14,_0x9084be['dynamics365Accounts'],'id');for(var _0x32b49a=0x0,_0xecca29={},_0x3b05ff={};_0x32b49a<_0x2bef14['length'];_0x32b49a+=0x1){_0xecca29=_0x2bef14[_0x32b49a];if(_[_0xbc35('0x3b')](_0x9084be[_0xbc35('0x1c')][_0xecca29['id']])){_0x9084be['dynamics365Accounts'][_0xecca29['id']]=new Dynamics365Account(_0xecca29);}else{_0x9084be[_0xbc35('0x38')](_0x9084be['dynamics365Accounts'][_0xecca29['id']],_0xecca29);}}}return _0x9084be[_0xbc35('0x1c')];};};Realtime['prototype'][_0xbc35('0x4c')]=function(){var _0x244d0f=this;return function(_0x143056){if(_0x143056){freeIsNotKey(_0x143056,_0x244d0f[_0xbc35('0x1d')],'id');for(var _0x214a8c=0x0,_0x36b268={},_0x41ae9d={};_0x214a8c<_0x143056['length'];_0x214a8c+=0x1){_0x36b268=_0x143056[_0x214a8c];if(_[_0xbc35('0x3b')](_0x244d0f[_0xbc35('0x1d')][_0x36b268['id']])){_0x244d0f['freshsalesAccounts'][_0x36b268['id']]=new FreshsalesAccount(_0x36b268);}else{_0x244d0f[_0xbc35('0x38')](_0x244d0f[_0xbc35('0x1d')][_0x36b268['id']],_0x36b268);}}}return _0x244d0f[_0xbc35('0x1d')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x4d')]=function(){var _0x5250e2=this;return function(_0x169ff3){for(var _0x4ca5ba=0x0;_0x4ca5ba<_0x169ff3[_0xbc35('0x3a')];_0x4ca5ba+=0x1){_[_0xbc35('0x4e')](_0x5250e2[_0xbc35('0xf')][_0x169ff3[_0x4ca5ba]['name']],_0x169ff3[_0x4ca5ba]);}return _0x5250e2[_0xbc35('0xf')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x4f')]=function(){var _0x85715c=this;return function(_0xf71b03){clearVoiceQueues(_0x85715c[_0xbc35('0xf')]);if(_0xf71b03){_0xf71b03=_['groupBy'](_0xf71b03,_0xbc35('0x50'));for(var _0x5ea882 in _0xf71b03){if(_0xf71b03[_0xbc35('0x1e')](_0x5ea882)){var _0x5e7bb1={};for(var _0x5a1767=0x0;_0x5a1767<_0xf71b03[_0x5ea882]['length'];_0x5a1767+=0x1){var _0x51d239=_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x51')];if(_0x85715c[_0xbc35('0xf')][_0x51d239]){if(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x52')]){_0x85715c['voiceQueues'][_0x51d239]['unmanaged']+=0x1;}if(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x53')]){_0x85715c[_0xbc35('0xf')][_0x51d239][_0xbc35('0x2c')]+=0x1;}_0x85715c[_0xbc35('0xf')][_0x51d239]['sumHoldTime']+=moment(_0xf71b03[_0x5ea882][_0x5a1767]['queuecallerleaveAt'])[_0xbc35('0x54')](moment(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x55')]),_0xbc35('0x56'))||0x0;if(_0x5a1767===_0xf71b03[_0x5ea882][_0xbc35('0x3a')]-0x1){_0x85715c['voiceQueues'][_0x51d239][_0xbc35('0x2d')]+=moment(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x57')]||_0xf71b03[_0x5ea882][_0x5a1767]['queuecallerabandonAt']||_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x58')])[_0xbc35('0x54')](moment(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x55')]),_0xbc35('0x56'))||0x0;_0x85715c[_0xbc35('0xf')][_0x51d239][_0xbc35('0x25')]+=0x1;if(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x59')]){_0x85715c[_0xbc35('0xf')][_0x51d239]['answered']+=0x1;_0x85715c[_0xbc35('0xf')][_0x51d239][_0xbc35('0x27')]+=moment(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x57')])[_0xbc35('0x54')](moment(_0xf71b03[_0x5ea882][_0x5a1767][_0xbc35('0x5a')]),'seconds')||0x0;}}else{_0x85715c['voiceQueues'][_0x51d239][_0xbc35('0x2d')]+=_0x85715c[_0xbc35('0xf')][_0x51d239][_0xbc35('0x5b')]||0x0;}}}}}}return _0x85715c['voiceQueues'];};};Realtime['prototype'][_0xbc35('0x5c')]=function(){var _0x5576cf=this;return function(_0x57c418){clearVoiceCallReports(_0x5576cf[_0xbc35('0x13')]);if(_0x57c418){for(var _0x2e6014=0x0;_0x2e6014<_0x57c418['length'];_0x2e6014+=0x1){_0x5576cf[_0xbc35('0x13')][_0xbc35('0x25')]+=0x1;_0x5576cf[_0xbc35('0x13')]['sumDuration']+=_0x57c418[_0x2e6014][_0xbc35('0x5d')];if(_0x57c418[_0x2e6014]['disposition']===_0xbc35('0x5e')){_0x5576cf[_0xbc35('0x13')]['answered']+=0x1;_0x5576cf['outbound'][_0xbc35('0x5b')]+=_0x57c418[_0x2e6014][_0xbc35('0x5d')]-_0x57c418[_0x2e6014][_0xbc35('0x5f')]||0x0;_0x5576cf[_0xbc35('0x13')][_0xbc35('0x27')]+=_0x57c418[_0x2e6014]['billableseconds'];}}}return _0x5576cf[_0xbc35('0x13')];};};Realtime['prototype'][_0xbc35('0x60')]=function(){var _0x1504f6=this;return function(_0x2afed6){if(_0x2afed6){freeIsNotKey(_0x2afed6,_0x1504f6[_0xbc35('0x11')],_0xbc35('0x23'));for(var _0x3a814c=0x0,_0x5710b6={};_0x3a814c<_0x2afed6[_0xbc35('0x3a')];_0x3a814c+=0x1){_0x5710b6=_0x2afed6[_0x3a814c];if(_[_0xbc35('0x3b')](_0x1504f6['campaigns'][_0x5710b6[_0xbc35('0x23')]])){_0x1504f6[_0xbc35('0x11')][_0x5710b6[_0xbc35('0x23')]]=new Campaign(_0x5710b6);}else{_0x1504f6['mergeFromDatabase'](_0x1504f6[_0xbc35('0x11')][_0x5710b6[_0xbc35('0x23')]],_0x5710b6);_0x1504f6[_0xbc35('0x11')][_0x5710b6[_0xbc35('0x23')]][_0xbc35('0x61')]=_0x5710b6[_0xbc35('0x62')]?_0x5710b6[_0xbc35('0x62')]['name']:undefined;}}}return _0x1504f6[_0xbc35('0x11')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x63')]=function(){var _0x37198a=this;return function(_0x1a5f35){if(_0x1a5f35){freeIsNotKey(_0x1a5f35,_0x37198a[_0xbc35('0x64')],'id');for(var _0x20a301=0x0,_0x15e683={};_0x20a301<_0x1a5f35[_0xbc35('0x3a')];_0x20a301+=0x1){_0x15e683=_0x1a5f35[_0x20a301];if(_[_0xbc35('0x3b')](_0x37198a[_0xbc35('0x64')][_0x15e683['id']])){_0x37198a[_0xbc35('0x64')][_0x15e683['id']]=new VoiceExtension(_0x15e683);}else{_0x37198a[_0xbc35('0x38')](_0x37198a['voiceExtensions'][_0x15e683['id']],_0x15e683);}}}return _0x37198a[_0xbc35('0x64')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x65')]=function(){var _0x4febf5=this;return function(_0x89d513){clearCampaigns(_0x4febf5[_0xbc35('0x11')]);for(var _0x1475e4=0x0;_0x1475e4<_0x89d513[_0xbc35('0x3a')];_0x1475e4+=0x1){_['merge'](_0x4febf5['campaigns'][_0x89d513[_0x1475e4][_0xbc35('0x23')]],_0x89d513[_0x1475e4]);}return _0x4febf5[_0xbc35('0x11')];};};Realtime[_0xbc35('0x37')][_0xbc35('0x66')]=function(){var _0x594de0=this;return function(_0x5e6280){if(_0x5e6280){freeIsNotKey(_0x5e6280,_0x594de0['faxAccounts'],'id');for(var _0x44edff=0x0,_0x5a15bf={},_0x2533a5={};_0x44edff<_0x5e6280[_0xbc35('0x3a')];_0x44edff+=0x1){_0x5a15bf=_0x5e6280[_0x44edff];if(_[_0xbc35('0x3b')](_0x594de0[_0xbc35('0x67')][_0x5a15bf['id']])){_0x594de0[_0xbc35('0x67')][_0x5a15bf['id']]=new FaxAccount(_0x5a15bf);}else{_0x594de0[_0xbc35('0x38')](_0x594de0['faxAccounts'][_0x5a15bf['id']],_0x5a15bf);}}}return _0x594de0[_0xbc35('0x67')];};};module['exports']=Realtime;