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 _0xa446=['../model/deskAccount','../model/vtigerAccount','../model/servicenowAccount','../model/dynamics365Account','../model/faxAccount','agents','telephones','trunks','voiceQueues','triggers','campaigns','outbound','voiceExtensions','queueChannels','outboundChannels','timers','salesforceAccounts','sugarcrmAccounts','freshdeskAccounts','zohoAccounts','deskAccounts','vtigerAccounts','freshsalesAccounts','faxAccounts','mapKeys','hasOwnProperty','isNil','interface','format','SIP/%s','name','total','answered','sumHoldTime','sumDuration','ivrTotalCallsDays','ivrAnswerCallsDay','isEmpty','abandoned','outboundNoAnswerCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundUnknownCallsDay','outboundDropCallsDayCallersExit','outboundBlacklistCallsDay','outboundReCallsDay','outboundAnswerAgiCallsDay','outboundAnswerCallsDay','mergeFromDatabase','prototype','initAgents','length','isUndefined','initTrunks','initVoiceQueues','initTriggers','initTemplates','templates','initZendeskAccounts','zendeskAccounts','initSalesforceAccounts','initZohoAccounts','initSugarcrmAccounts','servicenowAccounts','dynamics365Accounts','initFreshsalesAccounts','initVoiceQueueHopperHistory','merge','initVoiceQueueReports','uniqueid','unmanaged','queuecallerabandon','queuecallerleaveAt','diff','queuecallerjoinAt','queuecallercompleteAt','queuecallerabandonAt','queuecallerexitAt','seconds','queuecallercomplete','sumBillable','initVoiceCallReports','duration','disposition','ANSWERED','billableseconds','initCampaigns','dialQueueProject','SquareProject','initVoiceExtensions','initCampaignHopperHistory','initFaxAccounts','exports','bluebird','util','moment','../model/telephone','../model/voiceQueue','../model/template','../model/campaign','../model/voiceExtension','../model/zendeskAccount','../model/salesforceAccount','../model/freshdeskAccount','../model/zohoAccount'];(function(_0x4eea72,_0x31fa1d){var _0x40947e=function(_0xb5d9cf){while(--_0xb5d9cf){_0x4eea72['push'](_0x4eea72['shift']());}};_0x40947e(++_0x31fa1d);}(_0xa446,0xc6));var _0x6a44=function(_0x3f0c32,_0x282ddc){_0x3f0c32=_0x3f0c32-0x0;var _0x50e19c=_0xa446[_0x3f0c32];return _0x50e19c;};'use strict';var BPromise=require(_0x6a44('0x0'));var util=require(_0x6a44('0x1'));var _=require('lodash');var moment=require(_0x6a44('0x2'));var Agent=require('../model/agent');var Telephone=require(_0x6a44('0x3'));var Trunk=require('../model/trunk');var VoiceQueue=require(_0x6a44('0x4'));var Trigger=require('../model/trigger');var Template=require(_0x6a44('0x5'));var Campaign=require(_0x6a44('0x6'));var VoiceExtension=require(_0x6a44('0x7'));var ZendeskAccount=require(_0x6a44('0x8'));var SalesforceAccount=require(_0x6a44('0x9'));var FreshdeskAccount=require(_0x6a44('0xa'));var SugarcrmAccount=require('../model/sugarcrmAccount');var ZohoAccount=require(_0x6a44('0xb'));var DeskAccount=require(_0x6a44('0xc'));var VtigerAccount=require(_0x6a44('0xd'));var ServicenowAccount=require(_0x6a44('0xe'));var Dynamics365Account=require(_0x6a44('0xf'));var FreshsalesAccount=require('../model/freshsalesAccount');var FaxAccount=require(_0x6a44('0x10'));var Realtime=function(){this[_0x6a44('0x11')]={};this[_0x6a44('0x12')]={};this[_0x6a44('0x13')]={};this[_0x6a44('0x14')]={};this[_0x6a44('0x15')]={};this[_0x6a44('0x16')]={};this['templates']={};this[_0x6a44('0x17')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this[_0x6a44('0x18')]={};this['channels']={};this[_0x6a44('0x19')]={};this[_0x6a44('0x1a')]={};this[_0x6a44('0x1b')]={};this['zendeskAccounts']={};this[_0x6a44('0x1c')]={};this[_0x6a44('0x1d')]={};this[_0x6a44('0x1e')]={};this[_0x6a44('0x1f')]={};this[_0x6a44('0x20')]={};this[_0x6a44('0x21')]={};this['servicenowAccounts']={};this['dynamics365Accounts']={};this[_0x6a44('0x22')]={};this[_0x6a44('0x23')]={};};function freeIsNotKey(_0x577275,_0xa665c0,_0x38f796){var _0x41af8f=_[_0x6a44('0x24')](_0x577275,function(_0x2ff2a0,_0x1e1de0){return _0x2ff2a0[_0x38f796];});for(var _0x3dde7f in _0xa665c0){if(_0xa665c0[_0x6a44('0x25')](_0x3dde7f)){if(!_0x41af8f[_0x3dde7f]){delete _0xa665c0[_0x3dde7f];}}}}function freeIsNotKeySip(_0xc0997e,_0x25a47c){var _0xcc9136=_[_0x6a44('0x24')](_0xc0997e,function(_0x1b8920,_0x108c4b){return util['format']('SIP/%s',_0x1b8920['name']);});for(var _0x2d279b in _0x25a47c){if(_0x25a47c[_0x6a44('0x25')](_0x2d279b)){if(!_0xcc9136[_0x2d279b]){delete _0x25a47c[_0x2d279b];}}}}function freeIsNotKeyAgent(_0x2ef3cf,_0x1a7990){var _0x4bde4d=_[_0x6a44('0x24')](_0x2ef3cf,function(_0x24ba62,_0x528afe){var _0xebf7d6=_[_0x6a44('0x26')](_0x24ba62[_0x6a44('0x27')])?util[_0x6a44('0x28')](_0x6a44('0x29'),_0x24ba62[_0x6a44('0x2a')]):_0x24ba62[_0x6a44('0x27')];return _0xebf7d6;});for(var _0x1650fe in _0x1a7990){if(_0x1a7990[_0x6a44('0x25')](_0x1650fe)){if(!_0x4bde4d[_0x1650fe]){delete _0x1a7990[_0x1650fe];}}}}function clearVoiceCallReports(_0x4b5762){_0x4b5762[_0x6a44('0x2b')]=0x0;_0x4b5762[_0x6a44('0x2c')]=0x0;_0x4b5762[_0x6a44('0x2d')]=0x0;_0x4b5762[_0x6a44('0x2e')]=0x0;_0x4b5762['sumBillable']=0x0;}function clearCampaigns(_0x14141d){if(!_['isEmpty'](_0x14141d)){for(var _0x3ad23e in _0x14141d){if(_0x14141d[_0x6a44('0x25')](_0x3ad23e)){_0x14141d[_0x3ad23e][_0x6a44('0x2f')]=0x0;_0x14141d[_0x3ad23e][_0x6a44('0x30')]=0x0;}}}}function clearVoiceQueues(_0x60e38f){if(!_[_0x6a44('0x31')](_0x60e38f)){for(var _0x22a625 in _0x60e38f){if(_0x60e38f[_0x6a44('0x25')](_0x22a625)){_0x60e38f[_0x22a625][_0x6a44('0x2b')]=0x0;_0x60e38f[_0x22a625]['answered']=0x0;_0x60e38f[_0x22a625]['unmanaged']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x32')]=0x0;_0x60e38f[_0x22a625]['sumHoldTime']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x2e')]=0x0;_0x60e38f[_0x22a625]['sumBillable']=0x0;_0x60e38f[_0x22a625]['outboundAnswerAgiCallsDay']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x33')]=0x0;_0x60e38f[_0x22a625][_0x6a44('0x34')]=0x0;_0x60e38f[_0x22a625][_0x6a44('0x35')]=0x0;_0x60e38f[_0x22a625]['outboundNoSuchCallsDay']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x36')]=0x0;_0x60e38f[_0x22a625]['outboundDropCallsDayTimeout']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x37')]=0x0;_0x60e38f[_0x22a625][_0x6a44('0x38')]=0x0;_0x60e38f[_0x22a625]['outboundOriginateFailureCallsDay']=0x0;_0x60e38f[_0x22a625]['outboundRejectCallsDay']=0x0;_0x60e38f[_0x22a625][_0x6a44('0x39')]=0x0;_0x60e38f[_0x22a625][_0x6a44('0x3a')]=0x0;_0x60e38f[_0x22a625][_0x6a44('0x3b')]=0x0;_0x60e38f[_0x22a625]['queueStatusComplete']=!![];}}}}Realtime['prototype'][_0x6a44('0x3c')]=function(_0x2692cb,_0x70e134){for(var _0x5ab510 in _0x70e134){if(_0x2692cb[_0x6a44('0x25')](_0x5ab510)){_0x2692cb[_0x5ab510]=_0x70e134[_0x5ab510];}}};Realtime[_0x6a44('0x3d')][_0x6a44('0x3e')]=function(){var _0x163a92=this;return function(_0x3a2e5f){if(_0x3a2e5f){freeIsNotKeyAgent(_0x3a2e5f,_0x163a92[_0x6a44('0x11')]);for(var _0x413648=0x0,_0x3a67fe={},_0x410afd={};_0x413648<_0x3a2e5f[_0x6a44('0x3f')];_0x413648+=0x1){_0x3a67fe=_0x3a2e5f[_0x413648];var _0x4c48ce=_[_0x6a44('0x26')](_0x3a67fe['interface'])?util[_0x6a44('0x28')]('SIP/%s',_0x3a67fe['name']):_0x3a67fe['interface'];if(_['isUndefined'](_0x163a92[_0x6a44('0x11')][_0x4c48ce])){_0x163a92['agents'][_0x4c48ce]=new Agent(_0x3a67fe);}else{_0x163a92[_0x6a44('0x3c')](_0x163a92['agents'][_0x4c48ce],_0x3a67fe);}}}return _0x163a92[_0x6a44('0x11')];};};Realtime[_0x6a44('0x3d')]['initTelephones']=function(){var _0x500833=this;return function(_0x2cbdb9){if(_0x2cbdb9){freeIsNotKeySip(_0x2cbdb9,_0x500833[_0x6a44('0x12')]);for(var _0x2c509e=0x0,_0x4a0611={},_0x48d4bb={};_0x2c509e<_0x2cbdb9[_0x6a44('0x3f')];_0x2c509e+=0x1){_0x4a0611=_0x2cbdb9[_0x2c509e];if(_[_0x6a44('0x40')](_0x500833[_0x6a44('0x12')][util[_0x6a44('0x28')](_0x6a44('0x29'),_0x4a0611[_0x6a44('0x2a')])])){_0x500833['telephones'][util[_0x6a44('0x28')](_0x6a44('0x29'),_0x4a0611['name'])]=new Telephone(_0x4a0611);}else{_0x500833[_0x6a44('0x3c')](_0x500833['telephones'][util[_0x6a44('0x28')]('SIP/%s',_0x4a0611[_0x6a44('0x2a')])],_0x4a0611);}}}return _0x500833[_0x6a44('0x12')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x41')]=function(){var _0x220b00=this;return function(_0x4d6be4){if(_0x4d6be4){freeIsNotKeySip(_0x4d6be4,_0x220b00[_0x6a44('0x13')]);for(var _0x2eb2a0=0x0,_0x12327f={},_0x55a95a={};_0x2eb2a0<_0x4d6be4[_0x6a44('0x3f')];_0x2eb2a0+=0x1){_0x12327f=_0x4d6be4[_0x2eb2a0];if(_[_0x6a44('0x40')](_0x220b00['trunks'][util['format']('SIP/%s',_0x12327f['name'])])){_0x220b00[_0x6a44('0x13')][util[_0x6a44('0x28')](_0x6a44('0x29'),_0x12327f[_0x6a44('0x2a')])]=new Trunk(_0x12327f);}else{_0x220b00[_0x6a44('0x3c')](_0x220b00['trunks'][util['format'](_0x6a44('0x29'),_0x12327f[_0x6a44('0x2a')])],_0x12327f);}}}return _0x220b00[_0x6a44('0x13')];};};Realtime['prototype'][_0x6a44('0x42')]=function(){var _0x3d88ae=this;return function(_0x2c44b4){if(_0x2c44b4){freeIsNotKey(_0x2c44b4,_0x3d88ae['voiceQueues'],_0x6a44('0x2a'));for(var _0x3e809f=0x0,_0x36dac5={},_0x1055aa={};_0x3e809f<_0x2c44b4[_0x6a44('0x3f')];_0x3e809f+=0x1){_0x36dac5=_0x2c44b4[_0x3e809f];if(_[_0x6a44('0x40')](_0x3d88ae[_0x6a44('0x14')][_0x36dac5[_0x6a44('0x2a')]])){_0x3d88ae['voiceQueues'][_0x36dac5[_0x6a44('0x2a')]]=new VoiceQueue(_0x36dac5);}else{_0x3d88ae[_0x6a44('0x3c')](_0x3d88ae[_0x6a44('0x14')][_0x36dac5[_0x6a44('0x2a')]],_0x36dac5);}}}return _0x3d88ae[_0x6a44('0x14')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x43')]=function(){var _0xbce76=this;return function(_0x146926){if(_0x146926){freeIsNotKey(_0x146926,_0xbce76['triggers'],'id');for(var _0x33fe92=0x0,_0x154212={},_0x2cb131={};_0x33fe92<_0x146926[_0x6a44('0x3f')];_0x33fe92+=0x1){_0x154212=_0x146926[_0x33fe92];if(_[_0x6a44('0x40')](_0xbce76[_0x6a44('0x15')][_0x154212['id']])){_0xbce76[_0x6a44('0x15')][_0x154212['id']]=new Trigger(_0x154212);}else{_0xbce76[_0x6a44('0x3c')](_0xbce76['triggers'][_0x154212['id']],_0x154212);}}}return _0xbce76[_0x6a44('0x15')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x44')]=function(){var _0x4dce0f=this;return function(_0x151681){if(_0x151681){freeIsNotKey(_0x151681,_0x4dce0f['templates'],'id');for(var _0x5beef0=0x0,_0xfec319={},_0x1d18d4={};_0x5beef0<_0x151681['length'];_0x5beef0+=0x1){_0xfec319=_0x151681[_0x5beef0];if(_['isUndefined'](_0x4dce0f[_0x6a44('0x45')][_0xfec319['id']])){_0x4dce0f[_0x6a44('0x45')][_0xfec319['id']]=new Template(_0xfec319);}else{_0x4dce0f['mergeFromDatabase'](_0x4dce0f[_0x6a44('0x45')][_0xfec319['id']],_0xfec319);}}}return _0x4dce0f['templates'];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x46')]=function(){var _0xba5ba3=this;return function(_0x4c0eb8){if(_0x4c0eb8){freeIsNotKey(_0x4c0eb8,_0xba5ba3['zendeskAccounts'],'id');for(var _0x531bbc=0x0,_0x5ac2b0={},_0x267fe8={};_0x531bbc<_0x4c0eb8[_0x6a44('0x3f')];_0x531bbc+=0x1){_0x5ac2b0=_0x4c0eb8[_0x531bbc];if(_[_0x6a44('0x40')](_0xba5ba3[_0x6a44('0x47')][_0x5ac2b0['id']])){_0xba5ba3[_0x6a44('0x47')][_0x5ac2b0['id']]=new ZendeskAccount(_0x5ac2b0);}else{_0xba5ba3['mergeFromDatabase'](_0xba5ba3[_0x6a44('0x47')][_0x5ac2b0['id']],_0x5ac2b0);}}}return _0xba5ba3['zendeskAccounts'];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x48')]=function(){var _0x4a33d0=this;return function(_0x23cdf3){if(_0x23cdf3){freeIsNotKey(_0x23cdf3,_0x4a33d0[_0x6a44('0x1c')],'id');for(var _0x51c2a6=0x0,_0x39774a={},_0xd37b5d={};_0x51c2a6<_0x23cdf3[_0x6a44('0x3f')];_0x51c2a6+=0x1){_0x39774a=_0x23cdf3[_0x51c2a6];if(_[_0x6a44('0x40')](_0x4a33d0[_0x6a44('0x1c')][_0x39774a['id']])){_0x4a33d0[_0x6a44('0x1c')][_0x39774a['id']]=new SalesforceAccount(_0x39774a);}else{_0x4a33d0[_0x6a44('0x3c')](_0x4a33d0[_0x6a44('0x1c')][_0x39774a['id']],_0x39774a);}}}return _0x4a33d0[_0x6a44('0x1c')];};};Realtime[_0x6a44('0x3d')]['initFreshdeskAccounts']=function(){var _0xad43fa=this;return function(_0x4eb833){if(_0x4eb833){freeIsNotKey(_0x4eb833,_0xad43fa[_0x6a44('0x1e')],'id');for(var _0x2eb803=0x0,_0x224d7c={},_0x11d9b2={};_0x2eb803<_0x4eb833[_0x6a44('0x3f')];_0x2eb803+=0x1){_0x224d7c=_0x4eb833[_0x2eb803];if(_['isUndefined'](_0xad43fa[_0x6a44('0x1e')][_0x224d7c['id']])){_0xad43fa[_0x6a44('0x1e')][_0x224d7c['id']]=new FreshdeskAccount(_0x224d7c);}else{_0xad43fa[_0x6a44('0x3c')](_0xad43fa[_0x6a44('0x1e')][_0x224d7c['id']],_0x224d7c);}}}return _0xad43fa[_0x6a44('0x1e')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x49')]=function(){var _0x2ff7da=this;return function(_0x200944){if(_0x200944){freeIsNotKey(_0x200944,_0x2ff7da[_0x6a44('0x1f')],'id');for(var _0x450c72=0x0,_0x51e7df={},_0x668d2a={};_0x450c72<_0x200944[_0x6a44('0x3f')];_0x450c72+=0x1){_0x51e7df=_0x200944[_0x450c72];if(_[_0x6a44('0x40')](_0x2ff7da[_0x6a44('0x1f')][_0x51e7df['id']])){_0x2ff7da[_0x6a44('0x1f')][_0x51e7df['id']]=new ZohoAccount(_0x51e7df);}else{_0x2ff7da[_0x6a44('0x3c')](_0x2ff7da[_0x6a44('0x1f')][_0x51e7df['id']],_0x51e7df);}}}return _0x2ff7da[_0x6a44('0x1f')];};};Realtime[_0x6a44('0x3d')]['initDeskAccounts']=function(){var _0x1d6d70=this;return function(_0x15ff59){if(_0x15ff59){freeIsNotKey(_0x15ff59,_0x1d6d70[_0x6a44('0x20')],'id');for(var _0x800265=0x0,_0x5ae6fc={},_0x199c57={};_0x800265<_0x15ff59[_0x6a44('0x3f')];_0x800265+=0x1){_0x5ae6fc=_0x15ff59[_0x800265];if(_[_0x6a44('0x40')](_0x1d6d70['deskAccounts'][_0x5ae6fc['id']])){_0x1d6d70[_0x6a44('0x20')][_0x5ae6fc['id']]=new DeskAccount(_0x5ae6fc);}else{_0x1d6d70['mergeFromDatabase'](_0x1d6d70['deskAccounts'][_0x5ae6fc['id']],_0x5ae6fc);}}}return _0x1d6d70[_0x6a44('0x20')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x4a')]=function(){var _0x1c125f=this;return function(_0x1651ea){if(_0x1651ea){freeIsNotKey(_0x1651ea,_0x1c125f['sugarcrmAccounts'],'id');for(var _0x5b8d44=0x0,_0x362607={},_0x50c12b={};_0x5b8d44<_0x1651ea['length'];_0x5b8d44+=0x1){_0x362607=_0x1651ea[_0x5b8d44];if(_[_0x6a44('0x40')](_0x1c125f[_0x6a44('0x1d')][_0x362607['id']])){_0x1c125f[_0x6a44('0x1d')][_0x362607['id']]=new SugarcrmAccount(_0x362607);}else{_0x1c125f[_0x6a44('0x3c')](_0x1c125f['sugarcrmAccounts'][_0x362607['id']],_0x362607);}}}return _0x1c125f[_0x6a44('0x1d')];};};Realtime[_0x6a44('0x3d')]['initVtigerAccounts']=function(){var _0x4be2e2=this;return function(_0x17e1e3){if(_0x17e1e3){freeIsNotKey(_0x17e1e3,_0x4be2e2[_0x6a44('0x21')],'id');for(var _0x418a7e=0x0,_0x4eeeab={},_0x252ea4={};_0x418a7e<_0x17e1e3[_0x6a44('0x3f')];_0x418a7e+=0x1){_0x4eeeab=_0x17e1e3[_0x418a7e];if(_[_0x6a44('0x40')](_0x4be2e2[_0x6a44('0x21')][_0x4eeeab['id']])){_0x4be2e2[_0x6a44('0x21')][_0x4eeeab['id']]=new VtigerAccount(_0x4eeeab);}else{_0x4be2e2[_0x6a44('0x3c')](_0x4be2e2['vtigerAccounts'][_0x4eeeab['id']],_0x4eeeab);}}}return _0x4be2e2[_0x6a44('0x21')];};};Realtime[_0x6a44('0x3d')]['initServicenowAccounts']=function(){var _0x3d6dc6=this;return function(_0x3fdddf){if(_0x3fdddf){freeIsNotKey(_0x3fdddf,_0x3d6dc6[_0x6a44('0x4b')],'id');for(var _0x4bbcc5=0x0,_0x579ddd={},_0x5868c7={};_0x4bbcc5<_0x3fdddf[_0x6a44('0x3f')];_0x4bbcc5+=0x1){_0x579ddd=_0x3fdddf[_0x4bbcc5];if(_['isUndefined'](_0x3d6dc6[_0x6a44('0x4b')][_0x579ddd['id']])){_0x3d6dc6['servicenowAccounts'][_0x579ddd['id']]=new ServicenowAccount(_0x579ddd);}else{_0x3d6dc6[_0x6a44('0x3c')](_0x3d6dc6[_0x6a44('0x4b')][_0x579ddd['id']],_0x579ddd);}}}return _0x3d6dc6[_0x6a44('0x4b')];};};Realtime[_0x6a44('0x3d')]['initDynamics365Accounts']=function(){var _0x4cf4c4=this;return function(_0x1d202c){if(_0x1d202c){freeIsNotKey(_0x1d202c,_0x4cf4c4[_0x6a44('0x4c')],'id');for(var _0x46a77a=0x0,_0x229bc4={},_0x230932={};_0x46a77a<_0x1d202c[_0x6a44('0x3f')];_0x46a77a+=0x1){_0x229bc4=_0x1d202c[_0x46a77a];if(_[_0x6a44('0x40')](_0x4cf4c4[_0x6a44('0x4c')][_0x229bc4['id']])){_0x4cf4c4[_0x6a44('0x4c')][_0x229bc4['id']]=new Dynamics365Account(_0x229bc4);}else{_0x4cf4c4[_0x6a44('0x3c')](_0x4cf4c4[_0x6a44('0x4c')][_0x229bc4['id']],_0x229bc4);}}}return _0x4cf4c4[_0x6a44('0x4c')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x4d')]=function(){var _0x1490be=this;return function(_0xfee628){if(_0xfee628){freeIsNotKey(_0xfee628,_0x1490be[_0x6a44('0x22')],'id');for(var _0x38238e=0x0,_0x566c17={},_0x35459e={};_0x38238e<_0xfee628['length'];_0x38238e+=0x1){_0x566c17=_0xfee628[_0x38238e];if(_[_0x6a44('0x40')](_0x1490be[_0x6a44('0x22')][_0x566c17['id']])){_0x1490be[_0x6a44('0x22')][_0x566c17['id']]=new FreshsalesAccount(_0x566c17);}else{_0x1490be[_0x6a44('0x3c')](_0x1490be['freshsalesAccounts'][_0x566c17['id']],_0x566c17);}}}return _0x1490be[_0x6a44('0x22')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x4e')]=function(){var _0x1958bb=this;return function(_0x436833){for(var _0x3c1561=0x0;_0x3c1561<_0x436833['length'];_0x3c1561+=0x1){_[_0x6a44('0x4f')](_0x1958bb[_0x6a44('0x14')][_0x436833[_0x3c1561][_0x6a44('0x2a')]],_0x436833[_0x3c1561]);}return _0x1958bb[_0x6a44('0x14')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x50')]=function(){var _0x57fd0b=this;return function(_0x1c813c){clearVoiceQueues(_0x57fd0b[_0x6a44('0x14')]);if(_0x1c813c){_0x1c813c=_['groupBy'](_0x1c813c,_0x6a44('0x51'));for(var _0x463126 in _0x1c813c){if(_0x1c813c[_0x6a44('0x25')](_0x463126)){var _0x4cd9f5={};for(var _0xafa519=0x0;_0xafa519<_0x1c813c[_0x463126]['length'];_0xafa519+=0x1){var _0x159db1=_0x1c813c[_0x463126][_0xafa519]['queue'];if(_0x57fd0b[_0x6a44('0x14')][_0x159db1]){if(_0x1c813c[_0x463126][_0xafa519]['queuecallerexit']){_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x52')]+=0x1;}if(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x53')]){_0x57fd0b['voiceQueues'][_0x159db1]['abandoned']+=0x1;}_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x2d')]+=moment(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x54')])[_0x6a44('0x55')](moment(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x56')]),'seconds')||0x0;if(_0xafa519===_0x1c813c[_0x463126][_0x6a44('0x3f')]-0x1){_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x2e')]+=moment(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x57')]||_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x58')]||_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x59')])[_0x6a44('0x55')](moment(_0x1c813c[_0x463126][_0xafa519]['queuecallerjoinAt']),_0x6a44('0x5a'))||0x0;_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x2b')]+=0x1;if(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x5b')]){_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x2c')]+=0x1;_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x5c')]+=moment(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x57')])['diff'](moment(_0x1c813c[_0x463126][_0xafa519][_0x6a44('0x54')]),_0x6a44('0x5a'))||0x0;}}else{_0x57fd0b['voiceQueues'][_0x159db1]['sumDuration']+=_0x57fd0b[_0x6a44('0x14')][_0x159db1][_0x6a44('0x2d')]||0x0;}}}}}}return _0x57fd0b[_0x6a44('0x14')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x5d')]=function(){var _0x4f8341=this;return function(_0x1e221b){clearVoiceCallReports(_0x4f8341['outbound']);if(_0x1e221b){for(var _0x14096b=0x0;_0x14096b<_0x1e221b[_0x6a44('0x3f')];_0x14096b+=0x1){_0x4f8341[_0x6a44('0x17')]['total']+=0x1;_0x4f8341[_0x6a44('0x17')][_0x6a44('0x2e')]+=_0x1e221b[_0x14096b][_0x6a44('0x5e')];if(_0x1e221b[_0x14096b][_0x6a44('0x5f')]===_0x6a44('0x60')){_0x4f8341[_0x6a44('0x17')]['answered']+=0x1;_0x4f8341[_0x6a44('0x17')]['sumHoldTime']+=_0x1e221b[_0x14096b]['duration']-_0x1e221b[_0x14096b][_0x6a44('0x61')]||0x0;_0x4f8341[_0x6a44('0x17')]['sumBillable']+=_0x1e221b[_0x14096b]['billableseconds'];}}}return _0x4f8341[_0x6a44('0x17')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x62')]=function(){var _0x12f8a7=this;return function(_0x1d312c){if(_0x1d312c){freeIsNotKey(_0x1d312c,_0x12f8a7[_0x6a44('0x16')],_0x6a44('0x2a'));for(var _0x110922=0x0,_0x43e7f3={};_0x110922<_0x1d312c[_0x6a44('0x3f')];_0x110922+=0x1){_0x43e7f3=_0x1d312c[_0x110922];if(_[_0x6a44('0x40')](_0x12f8a7[_0x6a44('0x16')][_0x43e7f3[_0x6a44('0x2a')]])){_0x12f8a7[_0x6a44('0x16')][_0x43e7f3[_0x6a44('0x2a')]]=new Campaign(_0x43e7f3);}else{_0x12f8a7[_0x6a44('0x3c')](_0x12f8a7['campaigns'][_0x43e7f3[_0x6a44('0x2a')]],_0x43e7f3);_0x12f8a7[_0x6a44('0x16')][_0x43e7f3['name']][_0x6a44('0x63')]=_0x43e7f3[_0x6a44('0x64')]?_0x43e7f3['SquareProject'][_0x6a44('0x2a')]:undefined;}}}return _0x12f8a7['campaigns'];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x65')]=function(){var _0x350915=this;return function(_0x2b22f3){if(_0x2b22f3){freeIsNotKey(_0x2b22f3,_0x350915[_0x6a44('0x18')],'id');for(var _0x159c82=0x0,_0x4aac1c={};_0x159c82<_0x2b22f3[_0x6a44('0x3f')];_0x159c82+=0x1){_0x4aac1c=_0x2b22f3[_0x159c82];if(_[_0x6a44('0x40')](_0x350915[_0x6a44('0x18')][_0x4aac1c['id']])){_0x350915[_0x6a44('0x18')][_0x4aac1c['id']]=new VoiceExtension(_0x4aac1c);}else{_0x350915['mergeFromDatabase'](_0x350915[_0x6a44('0x18')][_0x4aac1c['id']],_0x4aac1c);}}}return _0x350915[_0x6a44('0x18')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x66')]=function(){var _0x570e1c=this;return function(_0x3cfd45){clearCampaigns(_0x570e1c[_0x6a44('0x16')]);for(var _0x2e4944=0x0;_0x2e4944<_0x3cfd45[_0x6a44('0x3f')];_0x2e4944+=0x1){_[_0x6a44('0x4f')](_0x570e1c[_0x6a44('0x16')][_0x3cfd45[_0x2e4944][_0x6a44('0x2a')]],_0x3cfd45[_0x2e4944]);}return _0x570e1c[_0x6a44('0x16')];};};Realtime[_0x6a44('0x3d')][_0x6a44('0x67')]=function(){var _0x27599c=this;return function(_0x33931c){if(_0x33931c){freeIsNotKey(_0x33931c,_0x27599c['faxAccounts'],'id');for(var _0x39473a=0x0,_0xc8315e={},_0x5909c8={};_0x39473a<_0x33931c[_0x6a44('0x3f')];_0x39473a+=0x1){_0xc8315e=_0x33931c[_0x39473a];if(_[_0x6a44('0x40')](_0x27599c['faxAccounts'][_0xc8315e['id']])){_0x27599c[_0x6a44('0x23')][_0xc8315e['id']]=new FaxAccount(_0xc8315e);}else{_0x27599c[_0x6a44('0x3c')](_0x27599c[_0x6a44('0x23')][_0xc8315e['id']],_0xc8315e);}}}return _0x27599c[_0x6a44('0x23')];};};module[_0x6a44('0x68')]=Realtime;