7f8262409377c096555faf31e18de4ee1352d1ea
[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 _0x516a=['../model/faxAccount','agents','telephones','trunks','voiceQueues','triggers','templates','outbound','voiceExtensions','channels','queueChannels','timers','zendeskAccounts','salesforceAccounts','sugarcrmAccounts','freshdeskAccounts','vtigerAccounts','freshsalesAccounts','faxAccounts','mapKeys','hasOwnProperty','format','SIP/%s','isNil','interface','name','total','sumHoldTime','sumDuration','sumBillable','ivrTotalCallsDays','ivrAnswerCallsDay','isEmpty','answered','unmanaged','abandoned','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundNoSuchCallsDay','outboundUnknownCallsDay','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','outboundOriginateFailureCallsDay','outboundRejectCallsDay','outboundReCallsDay','queueStatusComplete','prototype','mergeFromDatabase','initAgents','isUndefined','length','initTrunks','initTriggers','initTemplates','initSalesforceAccounts','initFreshdeskAccounts','zohoAccounts','initDeskAccounts','deskAccounts','initSugarcrmAccounts','initVtigerAccounts','initServicenowAccounts','servicenowAccounts','dynamics365Accounts','initFreshsalesAccounts','initVoiceQueueHopperHistory','merge','initVoiceQueueReports','groupBy','uniqueid','queuecallerexit','queuecallerabandon','diff','seconds','queuecallercompleteAt','queuecallerabandonAt','queuecallerjoinAt','queuecallercomplete','queuecallerleaveAt','initVoiceCallReports','duration','disposition','ANSWERED','billableseconds','initCampaigns','campaigns','dialQueueProject','SquareProject','initVoiceExtensions','initCampaignHopperHistory','initFaxAccounts','bluebird','util','../model/agent','../model/telephone','../model/trunk','../model/template','../model/campaign','../model/zendeskAccount','../model/freshdeskAccount','../model/zohoAccount','../model/deskAccount','../model/vtigerAccount','../model/servicenowAccount','../model/freshsalesAccount'];(function(_0x153c6c,_0x5aa22f){var _0x3c85d3=function(_0x5a5d85){while(--_0x5a5d85){_0x153c6c['push'](_0x153c6c['shift']());}};_0x3c85d3(++_0x5aa22f);}(_0x516a,0xc8));var _0xa516=function(_0x4ed1e6,_0x10ae73){_0x4ed1e6=_0x4ed1e6-0x0;var _0x4e063c=_0x516a[_0x4ed1e6];return _0x4e063c;};'use strict';var BPromise=require(_0xa516('0x0'));var util=require(_0xa516('0x1'));var _=require('lodash');var moment=require('moment');var Agent=require(_0xa516('0x2'));var Telephone=require(_0xa516('0x3'));var Trunk=require(_0xa516('0x4'));var VoiceQueue=require('../model/voiceQueue');var Trigger=require('../model/trigger');var Template=require(_0xa516('0x5'));var Campaign=require(_0xa516('0x6'));var VoiceExtension=require('../model/voiceExtension');var ZendeskAccount=require(_0xa516('0x7'));var SalesforceAccount=require('../model/salesforceAccount');var FreshdeskAccount=require(_0xa516('0x8'));var SugarcrmAccount=require('../model/sugarcrmAccount');var ZohoAccount=require(_0xa516('0x9'));var DeskAccount=require(_0xa516('0xa'));var VtigerAccount=require(_0xa516('0xb'));var ServicenowAccount=require(_0xa516('0xc'));var Dynamics365Account=require('../model/dynamics365Account');var FreshsalesAccount=require(_0xa516('0xd'));var FaxAccount=require(_0xa516('0xe'));var Realtime=function(){this[_0xa516('0xf')]={};this[_0xa516('0x10')]={};this[_0xa516('0x11')]={};this[_0xa516('0x12')]={};this[_0xa516('0x13')]={};this['campaigns']={};this[_0xa516('0x14')]={};this[_0xa516('0x15')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this[_0xa516('0x16')]={};this[_0xa516('0x17')]={};this[_0xa516('0x18')]={};this['outboundChannels']={};this[_0xa516('0x19')]={};this[_0xa516('0x1a')]={};this[_0xa516('0x1b')]={};this[_0xa516('0x1c')]={};this[_0xa516('0x1d')]={};this['zohoAccounts']={};this['deskAccounts']={};this[_0xa516('0x1e')]={};this['servicenowAccounts']={};this['dynamics365Accounts']={};this[_0xa516('0x1f')]={};this[_0xa516('0x20')]={};};function freeIsNotKey(_0xfb5197,_0x3ba1e2,_0xe1bc58){var _0x392bd9=_[_0xa516('0x21')](_0xfb5197,function(_0x8979ea,_0x1a0ebd){return _0x8979ea[_0xe1bc58];});for(var _0x47fd14 in _0x3ba1e2){if(_0x3ba1e2[_0xa516('0x22')](_0x47fd14)){if(!_0x392bd9[_0x47fd14]){delete _0x3ba1e2[_0x47fd14];}}}}function freeIsNotKeySip(_0x79d1cc,_0xacdf16){var _0x587ac9=_['mapKeys'](_0x79d1cc,function(_0x460882,_0x10a3b8){return util[_0xa516('0x23')](_0xa516('0x24'),_0x460882['name']);});for(var _0xfa436e in _0xacdf16){if(_0xacdf16[_0xa516('0x22')](_0xfa436e)){if(!_0x587ac9[_0xfa436e]){delete _0xacdf16[_0xfa436e];}}}}function freeIsNotKeyAgent(_0x45b240,_0x68fbe7){var _0x299c6b=_[_0xa516('0x21')](_0x45b240,function(_0x8f4de3,_0x3c01c0){var _0x1ffe5f=_[_0xa516('0x25')](_0x8f4de3[_0xa516('0x26')])?util['format'](_0xa516('0x24'),_0x8f4de3[_0xa516('0x27')]):_0x8f4de3[_0xa516('0x26')];return _0x1ffe5f;});for(var _0x2d9be6 in _0x68fbe7){if(_0x68fbe7[_0xa516('0x22')](_0x2d9be6)){if(!_0x299c6b[_0x2d9be6]){delete _0x68fbe7[_0x2d9be6];}}}}function clearVoiceCallReports(_0x3204ec){_0x3204ec[_0xa516('0x28')]=0x0;_0x3204ec['answered']=0x0;_0x3204ec[_0xa516('0x29')]=0x0;_0x3204ec[_0xa516('0x2a')]=0x0;_0x3204ec[_0xa516('0x2b')]=0x0;}function clearCampaigns(_0x5b5fc9){if(!_['isEmpty'](_0x5b5fc9)){for(var _0x4db76a in _0x5b5fc9){if(_0x5b5fc9[_0xa516('0x22')](_0x4db76a)){_0x5b5fc9[_0x4db76a][_0xa516('0x2c')]=0x0;_0x5b5fc9[_0x4db76a][_0xa516('0x2d')]=0x0;}}}}function clearVoiceQueues(_0x22534f){if(!_[_0xa516('0x2e')](_0x22534f)){for(var _0x22837e in _0x22534f){if(_0x22534f['hasOwnProperty'](_0x22837e)){_0x22534f[_0x22837e][_0xa516('0x28')]=0x0;_0x22534f[_0x22837e][_0xa516('0x2f')]=0x0;_0x22534f[_0x22837e][_0xa516('0x30')]=0x0;_0x22534f[_0x22837e][_0xa516('0x31')]=0x0;_0x22534f[_0x22837e][_0xa516('0x29')]=0x0;_0x22534f[_0x22837e][_0xa516('0x2a')]=0x0;_0x22534f[_0x22837e][_0xa516('0x2b')]=0x0;_0x22534f[_0x22837e][_0xa516('0x32')]=0x0;_0x22534f[_0x22837e][_0xa516('0x33')]=0x0;_0x22534f[_0x22837e][_0xa516('0x34')]=0x0;_0x22534f[_0x22837e][_0xa516('0x35')]=0x0;_0x22534f[_0x22837e][_0xa516('0x36')]=0x0;_0x22534f[_0x22837e][_0xa516('0x37')]=0x0;_0x22534f[_0x22837e][_0xa516('0x38')]=0x0;_0x22534f[_0x22837e][_0xa516('0x39')]=0x0;_0x22534f[_0x22837e]['outboundBlacklistCallsDay']=0x0;_0x22534f[_0x22837e][_0xa516('0x3a')]=0x0;_0x22534f[_0x22837e][_0xa516('0x3b')]=0x0;_0x22534f[_0x22837e][_0xa516('0x3c')]=0x0;_0x22534f[_0x22837e][_0xa516('0x32')]=0x0;_0x22534f[_0x22837e]['outboundAnswerCallsDay']=0x0;_0x22534f[_0x22837e][_0xa516('0x3d')]=!![];}}}}Realtime[_0xa516('0x3e')][_0xa516('0x3f')]=function(_0x2e54a3,_0x486a41){for(var _0xe6e94a in _0x486a41){if(_0x2e54a3[_0xa516('0x22')](_0xe6e94a)){_0x2e54a3[_0xe6e94a]=_0x486a41[_0xe6e94a];}}};Realtime['prototype'][_0xa516('0x40')]=function(){var _0x49f11c=this;return function(_0x1904dd){if(_0x1904dd){freeIsNotKeyAgent(_0x1904dd,_0x49f11c[_0xa516('0xf')]);for(var _0x1a7406=0x0,_0x4b9f21={},_0x126a3b={};_0x1a7406<_0x1904dd['length'];_0x1a7406+=0x1){_0x4b9f21=_0x1904dd[_0x1a7406];var _0x56460e=_[_0xa516('0x25')](_0x4b9f21[_0xa516('0x26')])?util[_0xa516('0x23')](_0xa516('0x24'),_0x4b9f21[_0xa516('0x27')]):_0x4b9f21[_0xa516('0x26')];if(_[_0xa516('0x41')](_0x49f11c[_0xa516('0xf')][_0x56460e])){_0x49f11c[_0xa516('0xf')][_0x56460e]=new Agent(_0x4b9f21);}else{_0x49f11c[_0xa516('0x3f')](_0x49f11c[_0xa516('0xf')][_0x56460e],_0x4b9f21);}}}return _0x49f11c[_0xa516('0xf')];};};Realtime[_0xa516('0x3e')]['initTelephones']=function(){var _0x139674=this;return function(_0x3438f1){if(_0x3438f1){freeIsNotKeySip(_0x3438f1,_0x139674['telephones']);for(var _0x2b0285=0x0,_0x3d13a6={},_0xc16198={};_0x2b0285<_0x3438f1[_0xa516('0x42')];_0x2b0285+=0x1){_0x3d13a6=_0x3438f1[_0x2b0285];if(_['isUndefined'](_0x139674['telephones'][util[_0xa516('0x23')]('SIP/%s',_0x3d13a6['name'])])){_0x139674['telephones'][util[_0xa516('0x23')]('SIP/%s',_0x3d13a6[_0xa516('0x27')])]=new Telephone(_0x3d13a6);}else{_0x139674[_0xa516('0x3f')](_0x139674[_0xa516('0x10')][util[_0xa516('0x23')]('SIP/%s',_0x3d13a6[_0xa516('0x27')])],_0x3d13a6);}}}return _0x139674[_0xa516('0x10')];};};Realtime[_0xa516('0x3e')][_0xa516('0x43')]=function(){var _0x2c238e=this;return function(_0x2d1c9c){if(_0x2d1c9c){freeIsNotKeySip(_0x2d1c9c,_0x2c238e[_0xa516('0x11')]);for(var _0xe43565=0x0,_0x4a7f86={},_0xa70634={};_0xe43565<_0x2d1c9c['length'];_0xe43565+=0x1){_0x4a7f86=_0x2d1c9c[_0xe43565];if(_[_0xa516('0x41')](_0x2c238e[_0xa516('0x11')][util[_0xa516('0x23')](_0xa516('0x24'),_0x4a7f86['name'])])){_0x2c238e[_0xa516('0x11')][util[_0xa516('0x23')](_0xa516('0x24'),_0x4a7f86[_0xa516('0x27')])]=new Trunk(_0x4a7f86);}else{_0x2c238e[_0xa516('0x3f')](_0x2c238e['trunks'][util[_0xa516('0x23')](_0xa516('0x24'),_0x4a7f86[_0xa516('0x27')])],_0x4a7f86);}}}return _0x2c238e['trunks'];};};Realtime[_0xa516('0x3e')]['initVoiceQueues']=function(){var _0x3b6eb1=this;return function(_0x38b1c8){if(_0x38b1c8){freeIsNotKey(_0x38b1c8,_0x3b6eb1[_0xa516('0x12')],_0xa516('0x27'));for(var _0x524a36=0x0,_0x383a87={},_0x56aa95={};_0x524a36<_0x38b1c8[_0xa516('0x42')];_0x524a36+=0x1){_0x383a87=_0x38b1c8[_0x524a36];if(_[_0xa516('0x41')](_0x3b6eb1[_0xa516('0x12')][_0x383a87[_0xa516('0x27')]])){_0x3b6eb1[_0xa516('0x12')][_0x383a87['name']]=new VoiceQueue(_0x383a87);}else{_0x3b6eb1[_0xa516('0x3f')](_0x3b6eb1['voiceQueues'][_0x383a87[_0xa516('0x27')]],_0x383a87);}}}return _0x3b6eb1['voiceQueues'];};};Realtime[_0xa516('0x3e')][_0xa516('0x44')]=function(){var _0x4627a1=this;return function(_0x1c5914){if(_0x1c5914){freeIsNotKey(_0x1c5914,_0x4627a1['triggers'],'id');for(var _0x19de04=0x0,_0x18cd94={},_0x241a45={};_0x19de04<_0x1c5914[_0xa516('0x42')];_0x19de04+=0x1){_0x18cd94=_0x1c5914[_0x19de04];if(_['isUndefined'](_0x4627a1['triggers'][_0x18cd94['id']])){_0x4627a1[_0xa516('0x13')][_0x18cd94['id']]=new Trigger(_0x18cd94);}else{_0x4627a1['mergeFromDatabase'](_0x4627a1[_0xa516('0x13')][_0x18cd94['id']],_0x18cd94);}}}return _0x4627a1[_0xa516('0x13')];};};Realtime[_0xa516('0x3e')][_0xa516('0x45')]=function(){var _0x37aedc=this;return function(_0x549de5){if(_0x549de5){freeIsNotKey(_0x549de5,_0x37aedc[_0xa516('0x14')],'id');for(var _0x5cf22c=0x0,_0x9a40ca={},_0x1ea21a={};_0x5cf22c<_0x549de5[_0xa516('0x42')];_0x5cf22c+=0x1){_0x9a40ca=_0x549de5[_0x5cf22c];if(_[_0xa516('0x41')](_0x37aedc['templates'][_0x9a40ca['id']])){_0x37aedc[_0xa516('0x14')][_0x9a40ca['id']]=new Template(_0x9a40ca);}else{_0x37aedc[_0xa516('0x3f')](_0x37aedc['templates'][_0x9a40ca['id']],_0x9a40ca);}}}return _0x37aedc[_0xa516('0x14')];};};Realtime[_0xa516('0x3e')]['initZendeskAccounts']=function(){var _0x5b3714=this;return function(_0x2c49b3){if(_0x2c49b3){freeIsNotKey(_0x2c49b3,_0x5b3714[_0xa516('0x1a')],'id');for(var _0x120b71=0x0,_0x992ff={},_0x41f202={};_0x120b71<_0x2c49b3['length'];_0x120b71+=0x1){_0x992ff=_0x2c49b3[_0x120b71];if(_[_0xa516('0x41')](_0x5b3714[_0xa516('0x1a')][_0x992ff['id']])){_0x5b3714[_0xa516('0x1a')][_0x992ff['id']]=new ZendeskAccount(_0x992ff);}else{_0x5b3714['mergeFromDatabase'](_0x5b3714[_0xa516('0x1a')][_0x992ff['id']],_0x992ff);}}}return _0x5b3714[_0xa516('0x1a')];};};Realtime[_0xa516('0x3e')][_0xa516('0x46')]=function(){var _0x487d5a=this;return function(_0x2ce4e4){if(_0x2ce4e4){freeIsNotKey(_0x2ce4e4,_0x487d5a['salesforceAccounts'],'id');for(var _0x1b9fcd=0x0,_0x56a935={},_0x425e16={};_0x1b9fcd<_0x2ce4e4['length'];_0x1b9fcd+=0x1){_0x56a935=_0x2ce4e4[_0x1b9fcd];if(_[_0xa516('0x41')](_0x487d5a[_0xa516('0x1b')][_0x56a935['id']])){_0x487d5a['salesforceAccounts'][_0x56a935['id']]=new SalesforceAccount(_0x56a935);}else{_0x487d5a[_0xa516('0x3f')](_0x487d5a[_0xa516('0x1b')][_0x56a935['id']],_0x56a935);}}}return _0x487d5a['salesforceAccounts'];};};Realtime[_0xa516('0x3e')][_0xa516('0x47')]=function(){var _0x4c30c0=this;return function(_0x53b77a){if(_0x53b77a){freeIsNotKey(_0x53b77a,_0x4c30c0[_0xa516('0x1d')],'id');for(var _0x474beb=0x0,_0x541a46={},_0x3f1340={};_0x474beb<_0x53b77a['length'];_0x474beb+=0x1){_0x541a46=_0x53b77a[_0x474beb];if(_[_0xa516('0x41')](_0x4c30c0[_0xa516('0x1d')][_0x541a46['id']])){_0x4c30c0[_0xa516('0x1d')][_0x541a46['id']]=new FreshdeskAccount(_0x541a46);}else{_0x4c30c0[_0xa516('0x3f')](_0x4c30c0[_0xa516('0x1d')][_0x541a46['id']],_0x541a46);}}}return _0x4c30c0[_0xa516('0x1d')];};};Realtime[_0xa516('0x3e')]['initZohoAccounts']=function(){var _0x14b187=this;return function(_0x11d824){if(_0x11d824){freeIsNotKey(_0x11d824,_0x14b187[_0xa516('0x48')],'id');for(var _0x47f917=0x0,_0x2b85d0={},_0xe6c748={};_0x47f917<_0x11d824['length'];_0x47f917+=0x1){_0x2b85d0=_0x11d824[_0x47f917];if(_['isUndefined'](_0x14b187[_0xa516('0x48')][_0x2b85d0['id']])){_0x14b187[_0xa516('0x48')][_0x2b85d0['id']]=new ZohoAccount(_0x2b85d0);}else{_0x14b187[_0xa516('0x3f')](_0x14b187[_0xa516('0x48')][_0x2b85d0['id']],_0x2b85d0);}}}return _0x14b187[_0xa516('0x48')];};};Realtime[_0xa516('0x3e')][_0xa516('0x49')]=function(){var _0x4fca1c=this;return function(_0x2bde14){if(_0x2bde14){freeIsNotKey(_0x2bde14,_0x4fca1c[_0xa516('0x4a')],'id');for(var _0x404732=0x0,_0x3612ac={},_0x18b170={};_0x404732<_0x2bde14[_0xa516('0x42')];_0x404732+=0x1){_0x3612ac=_0x2bde14[_0x404732];if(_[_0xa516('0x41')](_0x4fca1c[_0xa516('0x4a')][_0x3612ac['id']])){_0x4fca1c[_0xa516('0x4a')][_0x3612ac['id']]=new DeskAccount(_0x3612ac);}else{_0x4fca1c[_0xa516('0x3f')](_0x4fca1c[_0xa516('0x4a')][_0x3612ac['id']],_0x3612ac);}}}return _0x4fca1c[_0xa516('0x4a')];};};Realtime[_0xa516('0x3e')][_0xa516('0x4b')]=function(){var _0x1e29d7=this;return function(_0x382dda){if(_0x382dda){freeIsNotKey(_0x382dda,_0x1e29d7['sugarcrmAccounts'],'id');for(var _0x502a3b=0x0,_0x1fac8f={},_0xc131b3={};_0x502a3b<_0x382dda[_0xa516('0x42')];_0x502a3b+=0x1){_0x1fac8f=_0x382dda[_0x502a3b];if(_['isUndefined'](_0x1e29d7[_0xa516('0x1c')][_0x1fac8f['id']])){_0x1e29d7['sugarcrmAccounts'][_0x1fac8f['id']]=new SugarcrmAccount(_0x1fac8f);}else{_0x1e29d7[_0xa516('0x3f')](_0x1e29d7['sugarcrmAccounts'][_0x1fac8f['id']],_0x1fac8f);}}}return _0x1e29d7[_0xa516('0x1c')];};};Realtime[_0xa516('0x3e')][_0xa516('0x4c')]=function(){var _0x1568f5=this;return function(_0x6e3c27){if(_0x6e3c27){freeIsNotKey(_0x6e3c27,_0x1568f5[_0xa516('0x1e')],'id');for(var _0x1cfa76=0x0,_0x1034c0={},_0x3bebfa={};_0x1cfa76<_0x6e3c27['length'];_0x1cfa76+=0x1){_0x1034c0=_0x6e3c27[_0x1cfa76];if(_[_0xa516('0x41')](_0x1568f5[_0xa516('0x1e')][_0x1034c0['id']])){_0x1568f5[_0xa516('0x1e')][_0x1034c0['id']]=new VtigerAccount(_0x1034c0);}else{_0x1568f5[_0xa516('0x3f')](_0x1568f5[_0xa516('0x1e')][_0x1034c0['id']],_0x1034c0);}}}return _0x1568f5['vtigerAccounts'];};};Realtime[_0xa516('0x3e')][_0xa516('0x4d')]=function(){var _0x45f4c8=this;return function(_0x5248a4){if(_0x5248a4){freeIsNotKey(_0x5248a4,_0x45f4c8[_0xa516('0x4e')],'id');for(var _0x4ba7aa=0x0,_0x336552={},_0x22d56c={};_0x4ba7aa<_0x5248a4[_0xa516('0x42')];_0x4ba7aa+=0x1){_0x336552=_0x5248a4[_0x4ba7aa];if(_['isUndefined'](_0x45f4c8[_0xa516('0x4e')][_0x336552['id']])){_0x45f4c8[_0xa516('0x4e')][_0x336552['id']]=new ServicenowAccount(_0x336552);}else{_0x45f4c8[_0xa516('0x3f')](_0x45f4c8[_0xa516('0x4e')][_0x336552['id']],_0x336552);}}}return _0x45f4c8[_0xa516('0x4e')];};};Realtime[_0xa516('0x3e')]['initDynamics365Accounts']=function(){var _0x34f6a7=this;return function(_0x2f978a){if(_0x2f978a){freeIsNotKey(_0x2f978a,_0x34f6a7['dynamics365Accounts'],'id');for(var _0x497ebc=0x0,_0x2c96c0={},_0x3fa5a2={};_0x497ebc<_0x2f978a[_0xa516('0x42')];_0x497ebc+=0x1){_0x2c96c0=_0x2f978a[_0x497ebc];if(_[_0xa516('0x41')](_0x34f6a7['dynamics365Accounts'][_0x2c96c0['id']])){_0x34f6a7[_0xa516('0x4f')][_0x2c96c0['id']]=new Dynamics365Account(_0x2c96c0);}else{_0x34f6a7[_0xa516('0x3f')](_0x34f6a7['dynamics365Accounts'][_0x2c96c0['id']],_0x2c96c0);}}}return _0x34f6a7['dynamics365Accounts'];};};Realtime[_0xa516('0x3e')][_0xa516('0x50')]=function(){var _0x2b9c8c=this;return function(_0x5a0841){if(_0x5a0841){freeIsNotKey(_0x5a0841,_0x2b9c8c[_0xa516('0x1f')],'id');for(var _0x1e7dfa=0x0,_0x2ea5e2={},_0x506ed2={};_0x1e7dfa<_0x5a0841[_0xa516('0x42')];_0x1e7dfa+=0x1){_0x2ea5e2=_0x5a0841[_0x1e7dfa];if(_[_0xa516('0x41')](_0x2b9c8c['freshsalesAccounts'][_0x2ea5e2['id']])){_0x2b9c8c[_0xa516('0x1f')][_0x2ea5e2['id']]=new FreshsalesAccount(_0x2ea5e2);}else{_0x2b9c8c[_0xa516('0x3f')](_0x2b9c8c[_0xa516('0x1f')][_0x2ea5e2['id']],_0x2ea5e2);}}}return _0x2b9c8c[_0xa516('0x1f')];};};Realtime[_0xa516('0x3e')][_0xa516('0x51')]=function(){var _0x39a85e=this;return function(_0x5427ed){for(var _0x28cb8c=0x0;_0x28cb8c<_0x5427ed[_0xa516('0x42')];_0x28cb8c+=0x1){_[_0xa516('0x52')](_0x39a85e[_0xa516('0x12')][_0x5427ed[_0x28cb8c][_0xa516('0x27')]],_0x5427ed[_0x28cb8c]);}return _0x39a85e[_0xa516('0x12')];};};Realtime['prototype'][_0xa516('0x53')]=function(){var _0x4b7451=this;return function(_0x31d8f7){clearVoiceQueues(_0x4b7451[_0xa516('0x12')]);if(_0x31d8f7){_0x31d8f7=_[_0xa516('0x54')](_0x31d8f7,_0xa516('0x55'));for(var _0x41de68 in _0x31d8f7){if(_0x31d8f7['hasOwnProperty'](_0x41de68)){var _0x26ec31={};for(var _0xff96c9=0x0;_0xff96c9<_0x31d8f7[_0x41de68][_0xa516('0x42')];_0xff96c9+=0x1){var _0x150e54=_0x31d8f7[_0x41de68][_0xff96c9]['queue'];if(_0x4b7451['voiceQueues'][_0x150e54]){if(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x56')]){_0x4b7451['voiceQueues'][_0x150e54]['unmanaged']+=0x1;}if(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x57')]){_0x4b7451[_0xa516('0x12')][_0x150e54][_0xa516('0x31')]+=0x1;}_0x4b7451['voiceQueues'][_0x150e54][_0xa516('0x29')]+=moment(_0x31d8f7[_0x41de68][_0xff96c9]['queuecallerleaveAt'])[_0xa516('0x58')](moment(_0x31d8f7[_0x41de68][_0xff96c9]['queuecallerjoinAt']),_0xa516('0x59'))||0x0;if(_0xff96c9===_0x31d8f7[_0x41de68][_0xa516('0x42')]-0x1){_0x4b7451[_0xa516('0x12')][_0x150e54][_0xa516('0x2a')]+=moment(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x5a')]||_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x5b')]||_0x31d8f7[_0x41de68][_0xff96c9]['queuecallerexitAt'])['diff'](moment(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x5c')]),'seconds')||0x0;_0x4b7451[_0xa516('0x12')][_0x150e54][_0xa516('0x28')]+=0x1;if(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x5d')]){_0x4b7451[_0xa516('0x12')][_0x150e54][_0xa516('0x2f')]+=0x1;_0x4b7451[_0xa516('0x12')][_0x150e54][_0xa516('0x2b')]+=moment(_0x31d8f7[_0x41de68][_0xff96c9]['queuecallercompleteAt'])[_0xa516('0x58')](moment(_0x31d8f7[_0x41de68][_0xff96c9][_0xa516('0x5e')]),'seconds')||0x0;}}else{_0x4b7451[_0xa516('0x12')][_0x150e54]['sumDuration']+=_0x4b7451['voiceQueues'][_0x150e54]['sumHoldTime']||0x0;}}}}}}return _0x4b7451[_0xa516('0x12')];};};Realtime[_0xa516('0x3e')][_0xa516('0x5f')]=function(){var _0x9b8ec4=this;return function(_0x32fb36){clearVoiceCallReports(_0x9b8ec4['outbound']);if(_0x32fb36){for(var _0x302426=0x0;_0x302426<_0x32fb36[_0xa516('0x42')];_0x302426+=0x1){_0x9b8ec4[_0xa516('0x15')][_0xa516('0x28')]+=0x1;_0x9b8ec4[_0xa516('0x15')]['sumDuration']+=_0x32fb36[_0x302426][_0xa516('0x60')];if(_0x32fb36[_0x302426][_0xa516('0x61')]===_0xa516('0x62')){_0x9b8ec4['outbound'][_0xa516('0x2f')]+=0x1;_0x9b8ec4[_0xa516('0x15')][_0xa516('0x29')]+=_0x32fb36[_0x302426][_0xa516('0x60')]-_0x32fb36[_0x302426][_0xa516('0x63')]||0x0;_0x9b8ec4[_0xa516('0x15')][_0xa516('0x2b')]+=_0x32fb36[_0x302426][_0xa516('0x63')];}}}return _0x9b8ec4[_0xa516('0x15')];};};Realtime['prototype'][_0xa516('0x64')]=function(){var _0x106d63=this;return function(_0xe5ad95){if(_0xe5ad95){freeIsNotKey(_0xe5ad95,_0x106d63[_0xa516('0x65')],_0xa516('0x27'));for(var _0x28e14e=0x0,_0x500aab={};_0x28e14e<_0xe5ad95[_0xa516('0x42')];_0x28e14e+=0x1){_0x500aab=_0xe5ad95[_0x28e14e];if(_[_0xa516('0x41')](_0x106d63['campaigns'][_0x500aab['name']])){_0x106d63[_0xa516('0x65')][_0x500aab[_0xa516('0x27')]]=new Campaign(_0x500aab);}else{_0x106d63['mergeFromDatabase'](_0x106d63[_0xa516('0x65')][_0x500aab['name']],_0x500aab);_0x106d63[_0xa516('0x65')][_0x500aab[_0xa516('0x27')]][_0xa516('0x66')]=_0x500aab['SquareProject']?_0x500aab[_0xa516('0x67')][_0xa516('0x27')]:undefined;}}}return _0x106d63[_0xa516('0x65')];};};Realtime[_0xa516('0x3e')][_0xa516('0x68')]=function(){var _0x2a1590=this;return function(_0x601e2a){if(_0x601e2a){freeIsNotKey(_0x601e2a,_0x2a1590['voiceExtensions'],'id');for(var _0x501c2c=0x0,_0x1c80e7={};_0x501c2c<_0x601e2a[_0xa516('0x42')];_0x501c2c+=0x1){_0x1c80e7=_0x601e2a[_0x501c2c];if(_[_0xa516('0x41')](_0x2a1590['voiceExtensions'][_0x1c80e7['id']])){_0x2a1590[_0xa516('0x16')][_0x1c80e7['id']]=new VoiceExtension(_0x1c80e7);}else{_0x2a1590[_0xa516('0x3f')](_0x2a1590[_0xa516('0x16')][_0x1c80e7['id']],_0x1c80e7);}}}return _0x2a1590['voiceExtensions'];};};Realtime[_0xa516('0x3e')][_0xa516('0x69')]=function(){var _0x3e4c54=this;return function(_0x80be84){clearCampaigns(_0x3e4c54['campaigns']);for(var _0x16c23b=0x0;_0x16c23b<_0x80be84[_0xa516('0x42')];_0x16c23b+=0x1){_[_0xa516('0x52')](_0x3e4c54[_0xa516('0x65')][_0x80be84[_0x16c23b][_0xa516('0x27')]],_0x80be84[_0x16c23b]);}return _0x3e4c54['campaigns'];};};Realtime[_0xa516('0x3e')][_0xa516('0x6a')]=function(){var _0xe8ad1d=this;return function(_0x3775cd){if(_0x3775cd){freeIsNotKey(_0x3775cd,_0xe8ad1d['faxAccounts'],'id');for(var _0x14d05f=0x0,_0x2981d6={},_0x286b30={};_0x14d05f<_0x3775cd[_0xa516('0x42')];_0x14d05f+=0x1){_0x2981d6=_0x3775cd[_0x14d05f];if(_['isUndefined'](_0xe8ad1d['faxAccounts'][_0x2981d6['id']])){_0xe8ad1d[_0xa516('0x20')][_0x2981d6['id']]=new FaxAccount(_0x2981d6);}else{_0xe8ad1d['mergeFromDatabase'](_0xe8ad1d[_0xa516('0x20')][_0x2981d6['id']],_0x2981d6);}}}return _0xe8ad1d[_0xa516('0x20')];};};module['exports']=Realtime;