Built motion from commit 19a84241.|2.5.34
[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 _0x20f1=['queuecallerexit','queuecallerleaveAt','diff','seconds','queuecallerexitAt','queuecallerjoinAt','queuecallercomplete','outbound','duration','disposition','ANSWERED','billableseconds','initCampaigns','campaigns','SquareProject','initVoiceExtensions','initCampaignHopperHistory','bluebird','util','lodash','../model/telephone','../model/trunk','../model/voiceQueue','../model/template','../model/voiceExtension','../model/salesforceAccount','../model/freshdeskAccount','../model/sugarcrmAccount','../model/zohoAccount','../model/vtigerAccount','../model/dynamics365Account','../model/faxAccount','agents','voiceQueues','templates','voiceExtensions','channels','queueChannels','outboundChannels','zendeskAccounts','sugarcrmAccounts','vtigerAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','faxAccounts','mapKeys','hasOwnProperty','SIP/%s','name','isNil','interface','format','total','answered','sumHoldTime','sumDuration','isEmpty','ivrTotalCallsDays','unmanaged','abandoned','sumBillable','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundDropCallsDayTimeout','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundOriginateFailureCallsDay','outboundRejectCallsDay','outboundReCallsDay','outboundAnswerCallsDay','prototype','length','isUndefined','mergeFromDatabase','telephones','initTrunks','trunks','initVoiceQueues','triggers','initTemplates','initZendeskAccounts','initSalesforceAccounts','salesforceAccounts','initFreshdeskAccounts','freshdeskAccounts','initZohoAccounts','zohoAccounts','initDeskAccounts','deskAccounts','initSugarcrmAccounts','initVtigerAccounts','initServicenowAccounts','initFreshsalesAccounts','initVoiceQueueReports','queue'];(function(_0x339ec8,_0x10c64c){var _0x56a11f=function(_0x9ea856){while(--_0x9ea856){_0x339ec8['push'](_0x339ec8['shift']());}};_0x56a11f(++_0x10c64c);}(_0x20f1,0x73));var _0x120f=function(_0x5ad556,_0x4225cf){_0x5ad556=_0x5ad556-0x0;var _0x1b3a01=_0x20f1[_0x5ad556];return _0x1b3a01;};'use strict';var BPromise=require(_0x120f('0x0'));var util=require(_0x120f('0x1'));var _=require(_0x120f('0x2'));var moment=require('moment');var Agent=require('../model/agent');var Telephone=require(_0x120f('0x3'));var Trunk=require(_0x120f('0x4'));var VoiceQueue=require(_0x120f('0x5'));var Trigger=require('../model/trigger');var Template=require(_0x120f('0x6'));var Campaign=require('../model/campaign');var VoiceExtension=require(_0x120f('0x7'));var ZendeskAccount=require('../model/zendeskAccount');var SalesforceAccount=require(_0x120f('0x8'));var FreshdeskAccount=require(_0x120f('0x9'));var SugarcrmAccount=require(_0x120f('0xa'));var ZohoAccount=require(_0x120f('0xb'));var DeskAccount=require('../model/deskAccount');var VtigerAccount=require(_0x120f('0xc'));var ServicenowAccount=require('../model/servicenowAccount');var Dynamics365Account=require(_0x120f('0xd'));var FreshsalesAccount=require('../model/freshsalesAccount');var FaxAccount=require(_0x120f('0xe'));var Realtime=function(){this[_0x120f('0xf')]={};this['telephones']={};this['trunks']={};this[_0x120f('0x10')]={};this['triggers']={};this['campaigns']={};this[_0x120f('0x11')]={};this['outbound']={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this[_0x120f('0x12')]={};this[_0x120f('0x13')]={};this[_0x120f('0x14')]={};this[_0x120f('0x15')]={};this['timers']={};this['settings']={};this[_0x120f('0x16')]={};this['salesforceAccounts']={};this[_0x120f('0x17')]={};this['freshdeskAccounts']={};this['zohoAccounts']={};this['deskAccounts']={};this[_0x120f('0x18')]={};this[_0x120f('0x19')]={};this[_0x120f('0x1a')]={};this[_0x120f('0x1b')]={};this[_0x120f('0x1c')]={};};function freeIsNotKey(_0x511b86,_0x3169c0,_0x307fb3){var _0x545f87=_[_0x120f('0x1d')](_0x511b86,function(_0x35616c,_0x5ca8cb){return _0x35616c[_0x307fb3];});for(var _0x33845b in _0x3169c0){if(_0x3169c0[_0x120f('0x1e')](_0x33845b)){if(!_0x545f87[_0x33845b]){delete _0x3169c0[_0x33845b];}}}}function freeIsNotKeySip(_0x555307,_0x43961b){var _0x42716c=_[_0x120f('0x1d')](_0x555307,function(_0x4dbcd1,_0x9155db){return util['format'](_0x120f('0x1f'),_0x4dbcd1[_0x120f('0x20')]);});for(var _0x16ee3a in _0x43961b){if(_0x43961b[_0x120f('0x1e')](_0x16ee3a)){if(!_0x42716c[_0x16ee3a]){delete _0x43961b[_0x16ee3a];}}}}function freeIsNotKeyAgent(_0x263e95,_0x9e4d6b){var _0x3c3c0d=_[_0x120f('0x1d')](_0x263e95,function(_0x5d96d0,_0x24eb6d){var _0x1d7b6f=_[_0x120f('0x21')](_0x5d96d0[_0x120f('0x22')])?util[_0x120f('0x23')]('SIP/%s',_0x5d96d0['name']):_0x5d96d0[_0x120f('0x22')];return _0x1d7b6f;});for(var _0x239e79 in _0x9e4d6b){if(_0x9e4d6b['hasOwnProperty'](_0x239e79)){if(!_0x3c3c0d[_0x239e79]){delete _0x9e4d6b[_0x239e79];}}}}function clearVoiceCallReports(_0x51c6ee){_0x51c6ee[_0x120f('0x24')]=0x0;_0x51c6ee[_0x120f('0x25')]=0x0;_0x51c6ee[_0x120f('0x26')]=0x0;_0x51c6ee[_0x120f('0x27')]=0x0;_0x51c6ee['sumBillable']=0x0;}function clearCampaigns(_0x17b579){if(!_[_0x120f('0x28')](_0x17b579)){for(var _0x306af2 in _0x17b579){if(_0x17b579[_0x120f('0x1e')](_0x306af2)){_0x17b579[_0x306af2][_0x120f('0x29')]=0x0;_0x17b579[_0x306af2]['ivrAnswerCallsDay']=0x0;}}}}function clearVoiceQueues(_0x518ea7){if(!_['isEmpty'](_0x518ea7)){for(var _0x3448b7 in _0x518ea7){if(_0x518ea7[_0x120f('0x1e')](_0x3448b7)){_0x518ea7[_0x3448b7][_0x120f('0x24')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x25')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2a')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2b')]=0x0;_0x518ea7[_0x3448b7]['sumHoldTime']=0x0;_0x518ea7[_0x3448b7][_0x120f('0x27')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2c')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2d')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2e')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2f')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x30')]=0x0;_0x518ea7[_0x3448b7]['outboundNoSuchCallsDay']=0x0;_0x518ea7[_0x3448b7]['outboundUnknownCallsDay']=0x0;_0x518ea7[_0x3448b7][_0x120f('0x31')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x32')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x33')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x34')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x35')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x36')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x2d')]=0x0;_0x518ea7[_0x3448b7][_0x120f('0x37')]=0x0;_0x518ea7[_0x3448b7]['queueStatusComplete']=!![];}}}}Realtime[_0x120f('0x38')]['mergeFromDatabase']=function(_0x42b7d6,_0x156263){for(var _0x2df0be in _0x156263){if(_0x42b7d6[_0x120f('0x1e')](_0x2df0be)){_0x42b7d6[_0x2df0be]=_0x156263[_0x2df0be];}}};Realtime[_0x120f('0x38')]['initAgents']=function(){var _0x3d2c71=this;return function(_0x15620a){if(_0x15620a){freeIsNotKeyAgent(_0x15620a,_0x3d2c71[_0x120f('0xf')]);for(var _0x1ccd05=0x0,_0x2149dd={},_0x4b6537={};_0x1ccd05<_0x15620a[_0x120f('0x39')];_0x1ccd05+=0x1){_0x2149dd=_0x15620a[_0x1ccd05];var _0x4d6914=_[_0x120f('0x21')](_0x2149dd[_0x120f('0x22')])?util['format'](_0x120f('0x1f'),_0x2149dd['name']):_0x2149dd['interface'];if(_[_0x120f('0x3a')](_0x3d2c71[_0x120f('0xf')][_0x4d6914])){_0x3d2c71[_0x120f('0xf')][_0x4d6914]=new Agent(_0x2149dd);}else{_0x3d2c71[_0x120f('0x3b')](_0x3d2c71[_0x120f('0xf')][_0x4d6914],_0x2149dd);}}}return _0x3d2c71[_0x120f('0xf')];};};Realtime[_0x120f('0x38')]['initTelephones']=function(){var _0x1a0ed3=this;return function(_0x237a17){if(_0x237a17){freeIsNotKeySip(_0x237a17,_0x1a0ed3['telephones']);for(var _0x55aa2c=0x0,_0x13ba3d={},_0x43c1b7={};_0x55aa2c<_0x237a17[_0x120f('0x39')];_0x55aa2c+=0x1){_0x13ba3d=_0x237a17[_0x55aa2c];if(_[_0x120f('0x3a')](_0x1a0ed3[_0x120f('0x3c')][util[_0x120f('0x23')](_0x120f('0x1f'),_0x13ba3d[_0x120f('0x20')])])){_0x1a0ed3[_0x120f('0x3c')][util[_0x120f('0x23')](_0x120f('0x1f'),_0x13ba3d[_0x120f('0x20')])]=new Telephone(_0x13ba3d);}else{_0x1a0ed3[_0x120f('0x3b')](_0x1a0ed3['telephones'][util['format'](_0x120f('0x1f'),_0x13ba3d['name'])],_0x13ba3d);}}}return _0x1a0ed3[_0x120f('0x3c')];};};Realtime[_0x120f('0x38')][_0x120f('0x3d')]=function(){var _0x47e3c9=this;return function(_0x15cd20){if(_0x15cd20){freeIsNotKeySip(_0x15cd20,_0x47e3c9[_0x120f('0x3e')]);for(var _0x55c645=0x0,_0x48b805={},_0x393e99={};_0x55c645<_0x15cd20[_0x120f('0x39')];_0x55c645+=0x1){_0x48b805=_0x15cd20[_0x55c645];if(_['isUndefined'](_0x47e3c9[_0x120f('0x3e')][util[_0x120f('0x23')]('SIP/%s',_0x48b805[_0x120f('0x20')])])){_0x47e3c9[_0x120f('0x3e')][util['format'](_0x120f('0x1f'),_0x48b805[_0x120f('0x20')])]=new Trunk(_0x48b805);}else{_0x47e3c9[_0x120f('0x3b')](_0x47e3c9[_0x120f('0x3e')][util[_0x120f('0x23')](_0x120f('0x1f'),_0x48b805['name'])],_0x48b805);}}}return _0x47e3c9[_0x120f('0x3e')];};};Realtime['prototype'][_0x120f('0x3f')]=function(){var _0x2adf9a=this;return function(_0x3931fa){if(_0x3931fa){freeIsNotKey(_0x3931fa,_0x2adf9a[_0x120f('0x10')],'name');for(var _0x3df692=0x0,_0x5228e7={},_0x294a44={};_0x3df692<_0x3931fa[_0x120f('0x39')];_0x3df692+=0x1){_0x5228e7=_0x3931fa[_0x3df692];if(_[_0x120f('0x3a')](_0x2adf9a[_0x120f('0x10')][_0x5228e7[_0x120f('0x20')]])){_0x2adf9a[_0x120f('0x10')][_0x5228e7[_0x120f('0x20')]]=new VoiceQueue(_0x5228e7);}else{_0x2adf9a[_0x120f('0x3b')](_0x2adf9a['voiceQueues'][_0x5228e7[_0x120f('0x20')]],_0x5228e7);}}}return _0x2adf9a['voiceQueues'];};};Realtime[_0x120f('0x38')]['initTriggers']=function(){var _0x59583f=this;return function(_0x20fe7d){if(_0x20fe7d){freeIsNotKey(_0x20fe7d,_0x59583f[_0x120f('0x40')],'id');for(var _0xcd7f9=0x0,_0x3efca6={},_0x5119c9={};_0xcd7f9<_0x20fe7d['length'];_0xcd7f9+=0x1){_0x3efca6=_0x20fe7d[_0xcd7f9];if(_[_0x120f('0x3a')](_0x59583f[_0x120f('0x40')][_0x3efca6['id']])){_0x59583f['triggers'][_0x3efca6['id']]=new Trigger(_0x3efca6);}else{_0x59583f[_0x120f('0x3b')](_0x59583f[_0x120f('0x40')][_0x3efca6['id']],_0x3efca6);}}}return _0x59583f['triggers'];};};Realtime[_0x120f('0x38')][_0x120f('0x41')]=function(){var _0x1dafc9=this;return function(_0x2a8a12){if(_0x2a8a12){freeIsNotKey(_0x2a8a12,_0x1dafc9['templates'],'id');for(var _0x144839=0x0,_0x108ee7={},_0x5da107={};_0x144839<_0x2a8a12[_0x120f('0x39')];_0x144839+=0x1){_0x108ee7=_0x2a8a12[_0x144839];if(_[_0x120f('0x3a')](_0x1dafc9['templates'][_0x108ee7['id']])){_0x1dafc9[_0x120f('0x11')][_0x108ee7['id']]=new Template(_0x108ee7);}else{_0x1dafc9[_0x120f('0x3b')](_0x1dafc9[_0x120f('0x11')][_0x108ee7['id']],_0x108ee7);}}}return _0x1dafc9[_0x120f('0x11')];};};Realtime[_0x120f('0x38')][_0x120f('0x42')]=function(){var _0x615249=this;return function(_0x44945c){if(_0x44945c){freeIsNotKey(_0x44945c,_0x615249[_0x120f('0x16')],'id');for(var _0x16f396=0x0,_0x3b2e3f={},_0x43934d={};_0x16f396<_0x44945c['length'];_0x16f396+=0x1){_0x3b2e3f=_0x44945c[_0x16f396];if(_[_0x120f('0x3a')](_0x615249[_0x120f('0x16')][_0x3b2e3f['id']])){_0x615249[_0x120f('0x16')][_0x3b2e3f['id']]=new ZendeskAccount(_0x3b2e3f);}else{_0x615249[_0x120f('0x3b')](_0x615249[_0x120f('0x16')][_0x3b2e3f['id']],_0x3b2e3f);}}}return _0x615249['zendeskAccounts'];};};Realtime[_0x120f('0x38')][_0x120f('0x43')]=function(){var _0x1076f6=this;return function(_0x3ee78f){if(_0x3ee78f){freeIsNotKey(_0x3ee78f,_0x1076f6['salesforceAccounts'],'id');for(var _0x4c96b7=0x0,_0x4e1be4={},_0x50cbcb={};_0x4c96b7<_0x3ee78f[_0x120f('0x39')];_0x4c96b7+=0x1){_0x4e1be4=_0x3ee78f[_0x4c96b7];if(_[_0x120f('0x3a')](_0x1076f6[_0x120f('0x44')][_0x4e1be4['id']])){_0x1076f6[_0x120f('0x44')][_0x4e1be4['id']]=new SalesforceAccount(_0x4e1be4);}else{_0x1076f6[_0x120f('0x3b')](_0x1076f6[_0x120f('0x44')][_0x4e1be4['id']],_0x4e1be4);}}}return _0x1076f6[_0x120f('0x44')];};};Realtime[_0x120f('0x38')][_0x120f('0x45')]=function(){var _0x458151=this;return function(_0x2d8c3b){if(_0x2d8c3b){freeIsNotKey(_0x2d8c3b,_0x458151[_0x120f('0x46')],'id');for(var _0xe2f0f4=0x0,_0x166fcd={},_0x2b71c9={};_0xe2f0f4<_0x2d8c3b[_0x120f('0x39')];_0xe2f0f4+=0x1){_0x166fcd=_0x2d8c3b[_0xe2f0f4];if(_[_0x120f('0x3a')](_0x458151['freshdeskAccounts'][_0x166fcd['id']])){_0x458151[_0x120f('0x46')][_0x166fcd['id']]=new FreshdeskAccount(_0x166fcd);}else{_0x458151['mergeFromDatabase'](_0x458151['freshdeskAccounts'][_0x166fcd['id']],_0x166fcd);}}}return _0x458151[_0x120f('0x46')];};};Realtime[_0x120f('0x38')][_0x120f('0x47')]=function(){var _0x3b518e=this;return function(_0x206d10){if(_0x206d10){freeIsNotKey(_0x206d10,_0x3b518e[_0x120f('0x48')],'id');for(var _0x348e84=0x0,_0x5a2544={},_0x2abcb8={};_0x348e84<_0x206d10[_0x120f('0x39')];_0x348e84+=0x1){_0x5a2544=_0x206d10[_0x348e84];if(_['isUndefined'](_0x3b518e['zohoAccounts'][_0x5a2544['id']])){_0x3b518e['zohoAccounts'][_0x5a2544['id']]=new ZohoAccount(_0x5a2544);}else{_0x3b518e['mergeFromDatabase'](_0x3b518e[_0x120f('0x48')][_0x5a2544['id']],_0x5a2544);}}}return _0x3b518e[_0x120f('0x48')];};};Realtime['prototype'][_0x120f('0x49')]=function(){var _0x1ed94b=this;return function(_0x4f03fc){if(_0x4f03fc){freeIsNotKey(_0x4f03fc,_0x1ed94b['deskAccounts'],'id');for(var _0x2b25f6=0x0,_0x2bf6ed={},_0xed0c22={};_0x2b25f6<_0x4f03fc[_0x120f('0x39')];_0x2b25f6+=0x1){_0x2bf6ed=_0x4f03fc[_0x2b25f6];if(_[_0x120f('0x3a')](_0x1ed94b[_0x120f('0x4a')][_0x2bf6ed['id']])){_0x1ed94b[_0x120f('0x4a')][_0x2bf6ed['id']]=new DeskAccount(_0x2bf6ed);}else{_0x1ed94b[_0x120f('0x3b')](_0x1ed94b[_0x120f('0x4a')][_0x2bf6ed['id']],_0x2bf6ed);}}}return _0x1ed94b['deskAccounts'];};};Realtime[_0x120f('0x38')][_0x120f('0x4b')]=function(){var _0x36186d=this;return function(_0x3f52df){if(_0x3f52df){freeIsNotKey(_0x3f52df,_0x36186d[_0x120f('0x17')],'id');for(var _0x2f7cc8=0x0,_0x5dcc09={},_0x19cd69={};_0x2f7cc8<_0x3f52df[_0x120f('0x39')];_0x2f7cc8+=0x1){_0x5dcc09=_0x3f52df[_0x2f7cc8];if(_['isUndefined'](_0x36186d[_0x120f('0x17')][_0x5dcc09['id']])){_0x36186d[_0x120f('0x17')][_0x5dcc09['id']]=new SugarcrmAccount(_0x5dcc09);}else{_0x36186d[_0x120f('0x3b')](_0x36186d[_0x120f('0x17')][_0x5dcc09['id']],_0x5dcc09);}}}return _0x36186d[_0x120f('0x17')];};};Realtime[_0x120f('0x38')][_0x120f('0x4c')]=function(){var _0x300fec=this;return function(_0x471e79){if(_0x471e79){freeIsNotKey(_0x471e79,_0x300fec[_0x120f('0x18')],'id');for(var _0x298e89=0x0,_0x287ab5={},_0x2628ee={};_0x298e89<_0x471e79['length'];_0x298e89+=0x1){_0x287ab5=_0x471e79[_0x298e89];if(_['isUndefined'](_0x300fec[_0x120f('0x18')][_0x287ab5['id']])){_0x300fec['vtigerAccounts'][_0x287ab5['id']]=new VtigerAccount(_0x287ab5);}else{_0x300fec[_0x120f('0x3b')](_0x300fec['vtigerAccounts'][_0x287ab5['id']],_0x287ab5);}}}return _0x300fec[_0x120f('0x18')];};};Realtime[_0x120f('0x38')][_0x120f('0x4d')]=function(){var _0x348a87=this;return function(_0x1c13bf){if(_0x1c13bf){freeIsNotKey(_0x1c13bf,_0x348a87['servicenowAccounts'],'id');for(var _0xfc805=0x0,_0x2825fe={},_0x1871c3={};_0xfc805<_0x1c13bf[_0x120f('0x39')];_0xfc805+=0x1){_0x2825fe=_0x1c13bf[_0xfc805];if(_[_0x120f('0x3a')](_0x348a87['servicenowAccounts'][_0x2825fe['id']])){_0x348a87['servicenowAccounts'][_0x2825fe['id']]=new ServicenowAccount(_0x2825fe);}else{_0x348a87[_0x120f('0x3b')](_0x348a87[_0x120f('0x19')][_0x2825fe['id']],_0x2825fe);}}}return _0x348a87[_0x120f('0x19')];};};Realtime['prototype']['initDynamics365Accounts']=function(){var _0x3d4a54=this;return function(_0x47e3ee){if(_0x47e3ee){freeIsNotKey(_0x47e3ee,_0x3d4a54[_0x120f('0x1a')],'id');for(var _0x509ee7=0x0,_0x52183c={},_0x2d16fe={};_0x509ee7<_0x47e3ee[_0x120f('0x39')];_0x509ee7+=0x1){_0x52183c=_0x47e3ee[_0x509ee7];if(_[_0x120f('0x3a')](_0x3d4a54[_0x120f('0x1a')][_0x52183c['id']])){_0x3d4a54[_0x120f('0x1a')][_0x52183c['id']]=new Dynamics365Account(_0x52183c);}else{_0x3d4a54[_0x120f('0x3b')](_0x3d4a54[_0x120f('0x1a')][_0x52183c['id']],_0x52183c);}}}return _0x3d4a54[_0x120f('0x1a')];};};Realtime['prototype'][_0x120f('0x4e')]=function(){var _0x534f18=this;return function(_0x10b6bb){if(_0x10b6bb){freeIsNotKey(_0x10b6bb,_0x534f18[_0x120f('0x1b')],'id');for(var _0x4c2963=0x0,_0xc2ca88={},_0x37b44c={};_0x4c2963<_0x10b6bb['length'];_0x4c2963+=0x1){_0xc2ca88=_0x10b6bb[_0x4c2963];if(_[_0x120f('0x3a')](_0x534f18['freshsalesAccounts'][_0xc2ca88['id']])){_0x534f18[_0x120f('0x1b')][_0xc2ca88['id']]=new FreshsalesAccount(_0xc2ca88);}else{_0x534f18['mergeFromDatabase'](_0x534f18['freshsalesAccounts'][_0xc2ca88['id']],_0xc2ca88);}}}return _0x534f18[_0x120f('0x1b')];};};Realtime[_0x120f('0x38')]['initVoiceQueueHopperHistory']=function(){var _0x69f361=this;return function(_0x4f748d){for(var _0x165d39=0x0;_0x165d39<_0x4f748d[_0x120f('0x39')];_0x165d39+=0x1){_['merge'](_0x69f361[_0x120f('0x10')][_0x4f748d[_0x165d39]['name']],_0x4f748d[_0x165d39]);}return _0x69f361['voiceQueues'];};};Realtime[_0x120f('0x38')][_0x120f('0x4f')]=function(){var _0x19a513=this;return function(_0x30d2ca){clearVoiceQueues(_0x19a513[_0x120f('0x10')]);if(_0x30d2ca){_0x30d2ca=_['groupBy'](_0x30d2ca,'uniqueid');for(var _0x41c40a in _0x30d2ca){if(_0x30d2ca[_0x120f('0x1e')](_0x41c40a)){var _0x53c1ed={};for(var _0x55c16d=0x0;_0x55c16d<_0x30d2ca[_0x41c40a][_0x120f('0x39')];_0x55c16d+=0x1){var _0x58e159=_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x50')];if(_0x19a513['voiceQueues'][_0x58e159]){if(_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x51')]){_0x19a513[_0x120f('0x10')][_0x58e159]['unmanaged']+=0x1;}if(_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallerabandon']){_0x19a513[_0x120f('0x10')][_0x58e159][_0x120f('0x2b')]+=0x1;}_0x19a513[_0x120f('0x10')][_0x58e159][_0x120f('0x26')]+=moment(_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x52')])[_0x120f('0x53')](moment(_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallerjoinAt']),_0x120f('0x54'))||0x0;if(_0x55c16d===_0x30d2ca[_0x41c40a][_0x120f('0x39')]-0x1){_0x19a513[_0x120f('0x10')][_0x58e159][_0x120f('0x27')]+=moment(_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallercompleteAt']||_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallerabandonAt']||_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x55')])[_0x120f('0x53')](moment(_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x56')]),_0x120f('0x54'))||0x0;_0x19a513[_0x120f('0x10')][_0x58e159]['total']+=0x1;if(_0x30d2ca[_0x41c40a][_0x55c16d][_0x120f('0x57')]){_0x19a513['voiceQueues'][_0x58e159]['answered']+=0x1;_0x19a513[_0x120f('0x10')][_0x58e159][_0x120f('0x2c')]+=moment(_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallercompleteAt'])[_0x120f('0x53')](moment(_0x30d2ca[_0x41c40a][_0x55c16d]['queuecallerleaveAt']),_0x120f('0x54'))||0x0;}}else{_0x19a513[_0x120f('0x10')][_0x58e159][_0x120f('0x27')]+=_0x19a513[_0x120f('0x10')][_0x58e159]['sumHoldTime']||0x0;}}}}}}return _0x19a513[_0x120f('0x10')];};};Realtime['prototype']['initVoiceCallReports']=function(){var _0x766b8f=this;return function(_0x3a7310){clearVoiceCallReports(_0x766b8f['outbound']);if(_0x3a7310){for(var _0x4260ba=0x0;_0x4260ba<_0x3a7310[_0x120f('0x39')];_0x4260ba+=0x1){_0x766b8f['outbound'][_0x120f('0x24')]+=0x1;_0x766b8f[_0x120f('0x58')][_0x120f('0x27')]+=_0x3a7310[_0x4260ba][_0x120f('0x59')];if(_0x3a7310[_0x4260ba][_0x120f('0x5a')]===_0x120f('0x5b')){_0x766b8f[_0x120f('0x58')][_0x120f('0x25')]+=0x1;_0x766b8f['outbound'][_0x120f('0x26')]+=_0x3a7310[_0x4260ba][_0x120f('0x59')]-_0x3a7310[_0x4260ba][_0x120f('0x5c')]||0x0;_0x766b8f[_0x120f('0x58')][_0x120f('0x2c')]+=_0x3a7310[_0x4260ba][_0x120f('0x5c')];}}}return _0x766b8f['outbound'];};};Realtime['prototype'][_0x120f('0x5d')]=function(){var _0x4539fb=this;return function(_0x48a39f){if(_0x48a39f){freeIsNotKey(_0x48a39f,_0x4539fb[_0x120f('0x5e')],_0x120f('0x20'));for(var _0x492837=0x0,_0x490e96={};_0x492837<_0x48a39f[_0x120f('0x39')];_0x492837+=0x1){_0x490e96=_0x48a39f[_0x492837];if(_[_0x120f('0x3a')](_0x4539fb[_0x120f('0x5e')][_0x490e96['name']])){_0x4539fb[_0x120f('0x5e')][_0x490e96[_0x120f('0x20')]]=new Campaign(_0x490e96);}else{_0x4539fb[_0x120f('0x3b')](_0x4539fb[_0x120f('0x5e')][_0x490e96[_0x120f('0x20')]],_0x490e96);_0x4539fb[_0x120f('0x5e')][_0x490e96[_0x120f('0x20')]]['dialQueueProject']=_0x490e96['SquareProject']?_0x490e96[_0x120f('0x5f')][_0x120f('0x20')]:undefined;}}}return _0x4539fb[_0x120f('0x5e')];};};Realtime['prototype'][_0x120f('0x60')]=function(){var _0x30abe1=this;return function(_0x1e223c){if(_0x1e223c){freeIsNotKey(_0x1e223c,_0x30abe1['voiceExtensions'],'id');for(var _0x4c0056=0x0,_0x49210e={};_0x4c0056<_0x1e223c['length'];_0x4c0056+=0x1){_0x49210e=_0x1e223c[_0x4c0056];if(_[_0x120f('0x3a')](_0x30abe1[_0x120f('0x12')][_0x49210e['id']])){_0x30abe1[_0x120f('0x12')][_0x49210e['id']]=new VoiceExtension(_0x49210e);}else{_0x30abe1['mergeFromDatabase'](_0x30abe1[_0x120f('0x12')][_0x49210e['id']],_0x49210e);}}}return _0x30abe1[_0x120f('0x12')];};};Realtime[_0x120f('0x38')][_0x120f('0x61')]=function(){var _0x3d5afc=this;return function(_0xa7a8fc){clearCampaigns(_0x3d5afc['campaigns']);for(var _0x10a798=0x0;_0x10a798<_0xa7a8fc[_0x120f('0x39')];_0x10a798+=0x1){_['merge'](_0x3d5afc[_0x120f('0x5e')][_0xa7a8fc[_0x10a798][_0x120f('0x20')]],_0xa7a8fc[_0x10a798]);}return _0x3d5afc['campaigns'];};};Realtime[_0x120f('0x38')]['initFaxAccounts']=function(){var _0x35c858=this;return function(_0x4c6e17){if(_0x4c6e17){freeIsNotKey(_0x4c6e17,_0x35c858[_0x120f('0x1c')],'id');for(var _0x4bb101=0x0,_0xbdae16={},_0x5a8051={};_0x4bb101<_0x4c6e17[_0x120f('0x39')];_0x4bb101+=0x1){_0xbdae16=_0x4c6e17[_0x4bb101];if(_[_0x120f('0x3a')](_0x35c858[_0x120f('0x1c')][_0xbdae16['id']])){_0x35c858[_0x120f('0x1c')][_0xbdae16['id']]=new FaxAccount(_0xbdae16);}else{_0x35c858[_0x120f('0x3b')](_0x35c858[_0x120f('0x1c')][_0xbdae16['id']],_0xbdae16);}}}return _0x35c858[_0x120f('0x1c')];};};module['exports']=Realtime;