6e99785aa2fd2940b4ba69fd0a74f2c76bccc123
[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 _0x5d6f=['initVoiceQueueHopperHistory','merge','initVoiceQueueReports','groupBy','queue','queuecallerexit','queuecallerleaveAt','queuecallerjoinAt','seconds','queuecallerabandonAt','queuecallerexitAt','diff','queuecallercomplete','initVoiceCallReports','disposition','ANSWERED','duration','billableseconds','dialQueueProject','SquareProject','initVoiceExtensions','initFaxAccounts','faxAccounts','exports','bluebird','util','lodash','moment','../model/agent','../model/telephone','../model/trunk','../model/voiceQueue','../model/campaign','../model/voiceExtension','../model/zendeskAccount','../model/freshdeskAccount','../model/sugarcrmAccount','../model/zohoAccount','../model/deskAccount','../model/vtigerAccount','../model/servicenowAccount','../model/dynamics365Account','../model/freshsalesAccount','../model/faxAccount','telephones','trunks','voiceQueues','campaigns','templates','outbound','voiceExtensions','channels','queueChannels','outboundChannels','timers','zendeskAccounts','sugarcrmAccounts','freshdeskAccounts','deskAccounts','servicenowAccounts','dynamics365Accounts','freshsalesAccounts','mapKeys','hasOwnProperty','SIP/%s','name','isNil','interface','format','total','answered','isEmpty','ivrAnswerCallsDay','unmanaged','abandoned','sumHoldTime','sumDuration','sumBillable','outboundAnswerAgiCallsDay','outboundNoAnswerCallsDay','outboundBusyCallsDay','outboundCongestionCallsDay','outboundNoSuchCallsDay','outboundUnknownCallsDay','outboundDropCallsDayTimeout','outboundOriginateFailureCallsDay','outboundReCallsDay','outboundAnswerCallsDay','queueStatusComplete','prototype','mergeFromDatabase','agents','length','isUndefined','initTrunks','initVoiceQueues','initTriggers','triggers','salesforceAccounts','initFreshdeskAccounts','initZohoAccounts','zohoAccounts','initDeskAccounts','initSugarcrmAccounts','initVtigerAccounts','vtigerAccounts','initFreshsalesAccounts'];(function(_0x84ada4,_0x4b6de9){var _0x136066=function(_0x2656ce){while(--_0x2656ce){_0x84ada4['push'](_0x84ada4['shift']());}};_0x136066(++_0x4b6de9);}(_0x5d6f,0x1c4));var _0xf5d6=function(_0x4fabd8,_0x3be1df){_0x4fabd8=_0x4fabd8-0x0;var _0x245b41=_0x5d6f[_0x4fabd8];return _0x245b41;};'use strict';var BPromise=require(_0xf5d6('0x0'));var util=require(_0xf5d6('0x1'));var _=require(_0xf5d6('0x2'));var moment=require(_0xf5d6('0x3'));var Agent=require(_0xf5d6('0x4'));var Telephone=require(_0xf5d6('0x5'));var Trunk=require(_0xf5d6('0x6'));var VoiceQueue=require(_0xf5d6('0x7'));var Trigger=require('../model/trigger');var Template=require('../model/template');var Campaign=require(_0xf5d6('0x8'));var VoiceExtension=require(_0xf5d6('0x9'));var ZendeskAccount=require(_0xf5d6('0xa'));var SalesforceAccount=require('../model/salesforceAccount');var FreshdeskAccount=require(_0xf5d6('0xb'));var SugarcrmAccount=require(_0xf5d6('0xc'));var ZohoAccount=require(_0xf5d6('0xd'));var DeskAccount=require(_0xf5d6('0xe'));var VtigerAccount=require(_0xf5d6('0xf'));var ServicenowAccount=require(_0xf5d6('0x10'));var Dynamics365Account=require(_0xf5d6('0x11'));var FreshsalesAccount=require(_0xf5d6('0x12'));var FaxAccount=require(_0xf5d6('0x13'));var Realtime=function(){this['agents']={};this[_0xf5d6('0x14')]={};this[_0xf5d6('0x15')]={};this[_0xf5d6('0x16')]={};this['triggers']={};this[_0xf5d6('0x17')]={};this[_0xf5d6('0x18')]={};this[_0xf5d6('0x19')]={'total':0x0,'answered':0x0,'sumHoldTime':0x0,'sumDuration':0x0,'sumBillable':0x0};this[_0xf5d6('0x1a')]={};this[_0xf5d6('0x1b')]={};this[_0xf5d6('0x1c')]={};this[_0xf5d6('0x1d')]={};this[_0xf5d6('0x1e')]={};this[_0xf5d6('0x1f')]={};this['salesforceAccounts']={};this[_0xf5d6('0x20')]={};this[_0xf5d6('0x21')]={};this['zohoAccounts']={};this[_0xf5d6('0x22')]={};this['vtigerAccounts']={};this[_0xf5d6('0x23')]={};this[_0xf5d6('0x24')]={};this[_0xf5d6('0x25')]={};this['faxAccounts']={};};function freeIsNotKey(_0x2d670d,_0x434f0a,_0x111f79){var _0x309ca9=_[_0xf5d6('0x26')](_0x2d670d,function(_0x49f3eb,_0x27f40a){return _0x49f3eb[_0x111f79];});for(var _0x22f6c0 in _0x434f0a){if(_0x434f0a[_0xf5d6('0x27')](_0x22f6c0)){if(!_0x309ca9[_0x22f6c0]){delete _0x434f0a[_0x22f6c0];}}}}function freeIsNotKeySip(_0x755664,_0xa69206){var _0x4fd1ac=_[_0xf5d6('0x26')](_0x755664,function(_0x517105,_0x13dc3e){return util['format'](_0xf5d6('0x28'),_0x517105[_0xf5d6('0x29')]);});for(var _0x13ffe1 in _0xa69206){if(_0xa69206[_0xf5d6('0x27')](_0x13ffe1)){if(!_0x4fd1ac[_0x13ffe1]){delete _0xa69206[_0x13ffe1];}}}}function freeIsNotKeyAgent(_0x1f9da3,_0x40e6df){var _0x2a4656=_[_0xf5d6('0x26')](_0x1f9da3,function(_0x5da7ee,_0x7f660d){var _0x43e7fd=_[_0xf5d6('0x2a')](_0x5da7ee[_0xf5d6('0x2b')])?util[_0xf5d6('0x2c')]('SIP/%s',_0x5da7ee[_0xf5d6('0x29')]):_0x5da7ee[_0xf5d6('0x2b')];return _0x43e7fd;});for(var _0x3624e1 in _0x40e6df){if(_0x40e6df[_0xf5d6('0x27')](_0x3624e1)){if(!_0x2a4656[_0x3624e1]){delete _0x40e6df[_0x3624e1];}}}}function clearVoiceCallReports(_0x5bba9f){_0x5bba9f[_0xf5d6('0x2d')]=0x0;_0x5bba9f[_0xf5d6('0x2e')]=0x0;_0x5bba9f['sumHoldTime']=0x0;_0x5bba9f['sumDuration']=0x0;_0x5bba9f['sumBillable']=0x0;}function clearCampaigns(_0xd81818){if(!_[_0xf5d6('0x2f')](_0xd81818)){for(var _0x4b597d in _0xd81818){if(_0xd81818['hasOwnProperty'](_0x4b597d)){_0xd81818[_0x4b597d]['ivrTotalCallsDays']=0x0;_0xd81818[_0x4b597d][_0xf5d6('0x30')]=0x0;}}}}function clearVoiceQueues(_0x1b0641){if(!_[_0xf5d6('0x2f')](_0x1b0641)){for(var _0x5e9902 in _0x1b0641){if(_0x1b0641[_0xf5d6('0x27')](_0x5e9902)){_0x1b0641[_0x5e9902][_0xf5d6('0x2d')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x2e')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x31')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x32')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x33')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x34')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x35')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x36')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x37')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x38')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x39')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3a')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3b')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3c')]=0x0;_0x1b0641[_0x5e9902]['outboundDropCallsDayCallersExit']=0x0;_0x1b0641[_0x5e9902]['outboundBlacklistCallsDay']=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3d')]=0x0;_0x1b0641[_0x5e9902]['outboundRejectCallsDay']=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3e')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x36')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x3f')]=0x0;_0x1b0641[_0x5e9902][_0xf5d6('0x40')]=!![];}}}}Realtime[_0xf5d6('0x41')][_0xf5d6('0x42')]=function(_0x4bb3d5,_0x5b049c){for(var _0x4bc73d in _0x5b049c){if(_0x4bb3d5[_0xf5d6('0x27')](_0x4bc73d)){_0x4bb3d5[_0x4bc73d]=_0x5b049c[_0x4bc73d];}}};Realtime[_0xf5d6('0x41')]['initAgents']=function(){var _0x3aad1f=this;return function(_0x36b465){if(_0x36b465){freeIsNotKeyAgent(_0x36b465,_0x3aad1f[_0xf5d6('0x43')]);for(var _0x4d422b=0x0,_0x304123={},_0x38403a={};_0x4d422b<_0x36b465[_0xf5d6('0x44')];_0x4d422b+=0x1){_0x304123=_0x36b465[_0x4d422b];var _0x185a3e=_['isNil'](_0x304123[_0xf5d6('0x2b')])?util[_0xf5d6('0x2c')](_0xf5d6('0x28'),_0x304123['name']):_0x304123[_0xf5d6('0x2b')];if(_[_0xf5d6('0x45')](_0x3aad1f['agents'][_0x185a3e])){_0x3aad1f[_0xf5d6('0x43')][_0x185a3e]=new Agent(_0x304123);}else{_0x3aad1f['mergeFromDatabase'](_0x3aad1f[_0xf5d6('0x43')][_0x185a3e],_0x304123);}}}return _0x3aad1f[_0xf5d6('0x43')];};};Realtime[_0xf5d6('0x41')]['initTelephones']=function(){var _0x2c0754=this;return function(_0x46623d){if(_0x46623d){freeIsNotKeySip(_0x46623d,_0x2c0754[_0xf5d6('0x14')]);for(var _0x3c37a4=0x0,_0x41aed6={},_0x12e433={};_0x3c37a4<_0x46623d[_0xf5d6('0x44')];_0x3c37a4+=0x1){_0x41aed6=_0x46623d[_0x3c37a4];if(_[_0xf5d6('0x45')](_0x2c0754[_0xf5d6('0x14')][util[_0xf5d6('0x2c')](_0xf5d6('0x28'),_0x41aed6[_0xf5d6('0x29')])])){_0x2c0754[_0xf5d6('0x14')][util[_0xf5d6('0x2c')]('SIP/%s',_0x41aed6[_0xf5d6('0x29')])]=new Telephone(_0x41aed6);}else{_0x2c0754[_0xf5d6('0x42')](_0x2c0754[_0xf5d6('0x14')][util[_0xf5d6('0x2c')](_0xf5d6('0x28'),_0x41aed6[_0xf5d6('0x29')])],_0x41aed6);}}}return _0x2c0754[_0xf5d6('0x14')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x46')]=function(){var _0x4013c6=this;return function(_0x583873){if(_0x583873){freeIsNotKeySip(_0x583873,_0x4013c6[_0xf5d6('0x15')]);for(var _0x333b14=0x0,_0x34f198={},_0x2dbf88={};_0x333b14<_0x583873[_0xf5d6('0x44')];_0x333b14+=0x1){_0x34f198=_0x583873[_0x333b14];if(_['isUndefined'](_0x4013c6[_0xf5d6('0x15')][util['format'](_0xf5d6('0x28'),_0x34f198[_0xf5d6('0x29')])])){_0x4013c6[_0xf5d6('0x15')][util[_0xf5d6('0x2c')]('SIP/%s',_0x34f198['name'])]=new Trunk(_0x34f198);}else{_0x4013c6[_0xf5d6('0x42')](_0x4013c6['trunks'][util[_0xf5d6('0x2c')](_0xf5d6('0x28'),_0x34f198[_0xf5d6('0x29')])],_0x34f198);}}}return _0x4013c6[_0xf5d6('0x15')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x47')]=function(){var _0x39d9b8=this;return function(_0x3bc49c){if(_0x3bc49c){freeIsNotKey(_0x3bc49c,_0x39d9b8['voiceQueues'],_0xf5d6('0x29'));for(var _0x304dba=0x0,_0x1c9e6d={},_0x4299ae={};_0x304dba<_0x3bc49c[_0xf5d6('0x44')];_0x304dba+=0x1){_0x1c9e6d=_0x3bc49c[_0x304dba];if(_[_0xf5d6('0x45')](_0x39d9b8[_0xf5d6('0x16')][_0x1c9e6d[_0xf5d6('0x29')]])){_0x39d9b8['voiceQueues'][_0x1c9e6d['name']]=new VoiceQueue(_0x1c9e6d);}else{_0x39d9b8['mergeFromDatabase'](_0x39d9b8[_0xf5d6('0x16')][_0x1c9e6d['name']],_0x1c9e6d);}}}return _0x39d9b8['voiceQueues'];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x48')]=function(){var _0x5cefe8=this;return function(_0x1c3d49){if(_0x1c3d49){freeIsNotKey(_0x1c3d49,_0x5cefe8['triggers'],'id');for(var _0x563e20=0x0,_0x326ae2={},_0x581ef7={};_0x563e20<_0x1c3d49[_0xf5d6('0x44')];_0x563e20+=0x1){_0x326ae2=_0x1c3d49[_0x563e20];if(_[_0xf5d6('0x45')](_0x5cefe8[_0xf5d6('0x49')][_0x326ae2['id']])){_0x5cefe8['triggers'][_0x326ae2['id']]=new Trigger(_0x326ae2);}else{_0x5cefe8['mergeFromDatabase'](_0x5cefe8[_0xf5d6('0x49')][_0x326ae2['id']],_0x326ae2);}}}return _0x5cefe8[_0xf5d6('0x49')];};};Realtime[_0xf5d6('0x41')]['initTemplates']=function(){var _0x2d2054=this;return function(_0x12f81c){if(_0x12f81c){freeIsNotKey(_0x12f81c,_0x2d2054[_0xf5d6('0x18')],'id');for(var _0x35765c=0x0,_0x1b9339={},_0x5168d9={};_0x35765c<_0x12f81c['length'];_0x35765c+=0x1){_0x1b9339=_0x12f81c[_0x35765c];if(_[_0xf5d6('0x45')](_0x2d2054[_0xf5d6('0x18')][_0x1b9339['id']])){_0x2d2054[_0xf5d6('0x18')][_0x1b9339['id']]=new Template(_0x1b9339);}else{_0x2d2054[_0xf5d6('0x42')](_0x2d2054[_0xf5d6('0x18')][_0x1b9339['id']],_0x1b9339);}}}return _0x2d2054[_0xf5d6('0x18')];};};Realtime['prototype']['initZendeskAccounts']=function(){var _0x123fc8=this;return function(_0x693fdf){if(_0x693fdf){freeIsNotKey(_0x693fdf,_0x123fc8['zendeskAccounts'],'id');for(var _0x1cc4af=0x0,_0x48f303={},_0x1d080c={};_0x1cc4af<_0x693fdf[_0xf5d6('0x44')];_0x1cc4af+=0x1){_0x48f303=_0x693fdf[_0x1cc4af];if(_['isUndefined'](_0x123fc8[_0xf5d6('0x1f')][_0x48f303['id']])){_0x123fc8[_0xf5d6('0x1f')][_0x48f303['id']]=new ZendeskAccount(_0x48f303);}else{_0x123fc8['mergeFromDatabase'](_0x123fc8['zendeskAccounts'][_0x48f303['id']],_0x48f303);}}}return _0x123fc8[_0xf5d6('0x1f')];};};Realtime[_0xf5d6('0x41')]['initSalesforceAccounts']=function(){var _0x41bb8b=this;return function(_0x46dcee){if(_0x46dcee){freeIsNotKey(_0x46dcee,_0x41bb8b[_0xf5d6('0x4a')],'id');for(var _0x1fdea2=0x0,_0x559519={},_0x19e228={};_0x1fdea2<_0x46dcee[_0xf5d6('0x44')];_0x1fdea2+=0x1){_0x559519=_0x46dcee[_0x1fdea2];if(_[_0xf5d6('0x45')](_0x41bb8b['salesforceAccounts'][_0x559519['id']])){_0x41bb8b[_0xf5d6('0x4a')][_0x559519['id']]=new SalesforceAccount(_0x559519);}else{_0x41bb8b[_0xf5d6('0x42')](_0x41bb8b[_0xf5d6('0x4a')][_0x559519['id']],_0x559519);}}}return _0x41bb8b[_0xf5d6('0x4a')];};};Realtime['prototype'][_0xf5d6('0x4b')]=function(){var _0x2c5de6=this;return function(_0x2dad13){if(_0x2dad13){freeIsNotKey(_0x2dad13,_0x2c5de6[_0xf5d6('0x21')],'id');for(var _0x2f4278=0x0,_0x3e4f50={},_0x140264={};_0x2f4278<_0x2dad13[_0xf5d6('0x44')];_0x2f4278+=0x1){_0x3e4f50=_0x2dad13[_0x2f4278];if(_[_0xf5d6('0x45')](_0x2c5de6[_0xf5d6('0x21')][_0x3e4f50['id']])){_0x2c5de6[_0xf5d6('0x21')][_0x3e4f50['id']]=new FreshdeskAccount(_0x3e4f50);}else{_0x2c5de6['mergeFromDatabase'](_0x2c5de6[_0xf5d6('0x21')][_0x3e4f50['id']],_0x3e4f50);}}}return _0x2c5de6[_0xf5d6('0x21')];};};Realtime['prototype'][_0xf5d6('0x4c')]=function(){var _0x1412fc=this;return function(_0x176114){if(_0x176114){freeIsNotKey(_0x176114,_0x1412fc['zohoAccounts'],'id');for(var _0x31a21b=0x0,_0x136099={},_0x38338b={};_0x31a21b<_0x176114[_0xf5d6('0x44')];_0x31a21b+=0x1){_0x136099=_0x176114[_0x31a21b];if(_[_0xf5d6('0x45')](_0x1412fc[_0xf5d6('0x4d')][_0x136099['id']])){_0x1412fc[_0xf5d6('0x4d')][_0x136099['id']]=new ZohoAccount(_0x136099);}else{_0x1412fc[_0xf5d6('0x42')](_0x1412fc['zohoAccounts'][_0x136099['id']],_0x136099);}}}return _0x1412fc['zohoAccounts'];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x4e')]=function(){var _0x1401c1=this;return function(_0x2ffb00){if(_0x2ffb00){freeIsNotKey(_0x2ffb00,_0x1401c1[_0xf5d6('0x22')],'id');for(var _0x3c51db=0x0,_0x5c4989={},_0x23d0c9={};_0x3c51db<_0x2ffb00[_0xf5d6('0x44')];_0x3c51db+=0x1){_0x5c4989=_0x2ffb00[_0x3c51db];if(_[_0xf5d6('0x45')](_0x1401c1[_0xf5d6('0x22')][_0x5c4989['id']])){_0x1401c1[_0xf5d6('0x22')][_0x5c4989['id']]=new DeskAccount(_0x5c4989);}else{_0x1401c1[_0xf5d6('0x42')](_0x1401c1[_0xf5d6('0x22')][_0x5c4989['id']],_0x5c4989);}}}return _0x1401c1[_0xf5d6('0x22')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x4f')]=function(){var _0x47d0e2=this;return function(_0x5621ce){if(_0x5621ce){freeIsNotKey(_0x5621ce,_0x47d0e2[_0xf5d6('0x20')],'id');for(var _0x7268d7=0x0,_0xed75dc={},_0x48607a={};_0x7268d7<_0x5621ce[_0xf5d6('0x44')];_0x7268d7+=0x1){_0xed75dc=_0x5621ce[_0x7268d7];if(_[_0xf5d6('0x45')](_0x47d0e2[_0xf5d6('0x20')][_0xed75dc['id']])){_0x47d0e2[_0xf5d6('0x20')][_0xed75dc['id']]=new SugarcrmAccount(_0xed75dc);}else{_0x47d0e2[_0xf5d6('0x42')](_0x47d0e2[_0xf5d6('0x20')][_0xed75dc['id']],_0xed75dc);}}}return _0x47d0e2[_0xf5d6('0x20')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x50')]=function(){var _0x24df6f=this;return function(_0x4f8237){if(_0x4f8237){freeIsNotKey(_0x4f8237,_0x24df6f[_0xf5d6('0x51')],'id');for(var _0x5a0616=0x0,_0x26e382={},_0x2299b5={};_0x5a0616<_0x4f8237[_0xf5d6('0x44')];_0x5a0616+=0x1){_0x26e382=_0x4f8237[_0x5a0616];if(_['isUndefined'](_0x24df6f['vtigerAccounts'][_0x26e382['id']])){_0x24df6f[_0xf5d6('0x51')][_0x26e382['id']]=new VtigerAccount(_0x26e382);}else{_0x24df6f[_0xf5d6('0x42')](_0x24df6f[_0xf5d6('0x51')][_0x26e382['id']],_0x26e382);}}}return _0x24df6f[_0xf5d6('0x51')];};};Realtime[_0xf5d6('0x41')]['initServicenowAccounts']=function(){var _0x2b749e=this;return function(_0x5a66c8){if(_0x5a66c8){freeIsNotKey(_0x5a66c8,_0x2b749e[_0xf5d6('0x23')],'id');for(var _0x4fad4a=0x0,_0x49b7c1={},_0x3ed373={};_0x4fad4a<_0x5a66c8[_0xf5d6('0x44')];_0x4fad4a+=0x1){_0x49b7c1=_0x5a66c8[_0x4fad4a];if(_['isUndefined'](_0x2b749e[_0xf5d6('0x23')][_0x49b7c1['id']])){_0x2b749e['servicenowAccounts'][_0x49b7c1['id']]=new ServicenowAccount(_0x49b7c1);}else{_0x2b749e[_0xf5d6('0x42')](_0x2b749e['servicenowAccounts'][_0x49b7c1['id']],_0x49b7c1);}}}return _0x2b749e[_0xf5d6('0x23')];};};Realtime[_0xf5d6('0x41')]['initDynamics365Accounts']=function(){var _0x1b2888=this;return function(_0x42190b){if(_0x42190b){freeIsNotKey(_0x42190b,_0x1b2888['dynamics365Accounts'],'id');for(var _0x4e0539=0x0,_0x17cc53={},_0x73a40a={};_0x4e0539<_0x42190b['length'];_0x4e0539+=0x1){_0x17cc53=_0x42190b[_0x4e0539];if(_[_0xf5d6('0x45')](_0x1b2888[_0xf5d6('0x24')][_0x17cc53['id']])){_0x1b2888[_0xf5d6('0x24')][_0x17cc53['id']]=new Dynamics365Account(_0x17cc53);}else{_0x1b2888[_0xf5d6('0x42')](_0x1b2888['dynamics365Accounts'][_0x17cc53['id']],_0x17cc53);}}}return _0x1b2888[_0xf5d6('0x24')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x52')]=function(){var _0x393b9=this;return function(_0x294bd3){if(_0x294bd3){freeIsNotKey(_0x294bd3,_0x393b9[_0xf5d6('0x25')],'id');for(var _0x71d0ca=0x0,_0x27d186={},_0x5b2f14={};_0x71d0ca<_0x294bd3[_0xf5d6('0x44')];_0x71d0ca+=0x1){_0x27d186=_0x294bd3[_0x71d0ca];if(_['isUndefined'](_0x393b9[_0xf5d6('0x25')][_0x27d186['id']])){_0x393b9[_0xf5d6('0x25')][_0x27d186['id']]=new FreshsalesAccount(_0x27d186);}else{_0x393b9[_0xf5d6('0x42')](_0x393b9[_0xf5d6('0x25')][_0x27d186['id']],_0x27d186);}}}return _0x393b9[_0xf5d6('0x25')];};};Realtime['prototype'][_0xf5d6('0x53')]=function(){var _0x582f61=this;return function(_0x531d9f){for(var _0x1fc169=0x0;_0x1fc169<_0x531d9f[_0xf5d6('0x44')];_0x1fc169+=0x1){_[_0xf5d6('0x54')](_0x582f61[_0xf5d6('0x16')][_0x531d9f[_0x1fc169]['name']],_0x531d9f[_0x1fc169]);}return _0x582f61[_0xf5d6('0x16')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x55')]=function(){var _0xd4aa2=this;return function(_0x15f710){clearVoiceQueues(_0xd4aa2[_0xf5d6('0x16')]);if(_0x15f710){_0x15f710=_[_0xf5d6('0x56')](_0x15f710,'uniqueid');for(var _0x26f784 in _0x15f710){if(_0x15f710[_0xf5d6('0x27')](_0x26f784)){var _0x1a2536={};for(var _0x12c489=0x0;_0x12c489<_0x15f710[_0x26f784][_0xf5d6('0x44')];_0x12c489+=0x1){var _0xcef4e1=_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x57')];if(_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1]){if(_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x58')]){_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x31')]+=0x1;}if(_0x15f710[_0x26f784][_0x12c489]['queuecallerabandon']){_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x32')]+=0x1;}_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x33')]+=moment(_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x59')])['diff'](moment(_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x5a')]),_0xf5d6('0x5b'))||0x0;if(_0x12c489===_0x15f710[_0x26f784]['length']-0x1){_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x34')]+=moment(_0x15f710[_0x26f784][_0x12c489]['queuecallercompleteAt']||_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x5c')]||_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x5d')])[_0xf5d6('0x5e')](moment(_0x15f710[_0x26f784][_0x12c489]['queuecallerjoinAt']),_0xf5d6('0x5b'))||0x0;_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x2d')]+=0x1;if(_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x5f')]){_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1]['answered']+=0x1;_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x35')]+=moment(_0x15f710[_0x26f784][_0x12c489]['queuecallercompleteAt'])[_0xf5d6('0x5e')](moment(_0x15f710[_0x26f784][_0x12c489][_0xf5d6('0x59')]),_0xf5d6('0x5b'))||0x0;}}else{_0xd4aa2['voiceQueues'][_0xcef4e1][_0xf5d6('0x34')]+=_0xd4aa2[_0xf5d6('0x16')][_0xcef4e1][_0xf5d6('0x33')]||0x0;}}}}}}return _0xd4aa2[_0xf5d6('0x16')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x60')]=function(){var _0x99ed0b=this;return function(_0x1ad1b0){clearVoiceCallReports(_0x99ed0b[_0xf5d6('0x19')]);if(_0x1ad1b0){for(var _0x4ca191=0x0;_0x4ca191<_0x1ad1b0[_0xf5d6('0x44')];_0x4ca191+=0x1){_0x99ed0b[_0xf5d6('0x19')][_0xf5d6('0x2d')]+=0x1;_0x99ed0b[_0xf5d6('0x19')][_0xf5d6('0x34')]+=_0x1ad1b0[_0x4ca191]['duration'];if(_0x1ad1b0[_0x4ca191][_0xf5d6('0x61')]===_0xf5d6('0x62')){_0x99ed0b[_0xf5d6('0x19')][_0xf5d6('0x2e')]+=0x1;_0x99ed0b[_0xf5d6('0x19')][_0xf5d6('0x33')]+=_0x1ad1b0[_0x4ca191][_0xf5d6('0x63')]-_0x1ad1b0[_0x4ca191][_0xf5d6('0x64')]||0x0;_0x99ed0b[_0xf5d6('0x19')][_0xf5d6('0x35')]+=_0x1ad1b0[_0x4ca191][_0xf5d6('0x64')];}}}return _0x99ed0b[_0xf5d6('0x19')];};};Realtime['prototype']['initCampaigns']=function(){var _0x2683a2=this;return function(_0x549a0f){if(_0x549a0f){freeIsNotKey(_0x549a0f,_0x2683a2[_0xf5d6('0x17')],_0xf5d6('0x29'));for(var _0x574b24=0x0,_0x3de268={};_0x574b24<_0x549a0f[_0xf5d6('0x44')];_0x574b24+=0x1){_0x3de268=_0x549a0f[_0x574b24];if(_['isUndefined'](_0x2683a2[_0xf5d6('0x17')][_0x3de268[_0xf5d6('0x29')]])){_0x2683a2[_0xf5d6('0x17')][_0x3de268[_0xf5d6('0x29')]]=new Campaign(_0x3de268);}else{_0x2683a2[_0xf5d6('0x42')](_0x2683a2[_0xf5d6('0x17')][_0x3de268['name']],_0x3de268);_0x2683a2[_0xf5d6('0x17')][_0x3de268['name']][_0xf5d6('0x65')]=_0x3de268[_0xf5d6('0x66')]?_0x3de268[_0xf5d6('0x66')][_0xf5d6('0x29')]:undefined;}}}return _0x2683a2[_0xf5d6('0x17')];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x67')]=function(){var _0x1ee2a5=this;return function(_0x1976ae){if(_0x1976ae){freeIsNotKey(_0x1976ae,_0x1ee2a5[_0xf5d6('0x1a')],'id');for(var _0xae303d=0x0,_0x207297={};_0xae303d<_0x1976ae['length'];_0xae303d+=0x1){_0x207297=_0x1976ae[_0xae303d];if(_[_0xf5d6('0x45')](_0x1ee2a5[_0xf5d6('0x1a')][_0x207297['id']])){_0x1ee2a5[_0xf5d6('0x1a')][_0x207297['id']]=new VoiceExtension(_0x207297);}else{_0x1ee2a5[_0xf5d6('0x42')](_0x1ee2a5[_0xf5d6('0x1a')][_0x207297['id']],_0x207297);}}}return _0x1ee2a5[_0xf5d6('0x1a')];};};Realtime['prototype']['initCampaignHopperHistory']=function(){var _0x1708ad=this;return function(_0x1d2445){clearCampaigns(_0x1708ad[_0xf5d6('0x17')]);for(var _0x591083=0x0;_0x591083<_0x1d2445[_0xf5d6('0x44')];_0x591083+=0x1){_[_0xf5d6('0x54')](_0x1708ad[_0xf5d6('0x17')][_0x1d2445[_0x591083]['name']],_0x1d2445[_0x591083]);}return _0x1708ad['campaigns'];};};Realtime[_0xf5d6('0x41')][_0xf5d6('0x68')]=function(){var _0xd3ac91=this;return function(_0x36edd5){if(_0x36edd5){freeIsNotKey(_0x36edd5,_0xd3ac91[_0xf5d6('0x69')],'id');for(var _0x14c297=0x0,_0x50f6a1={},_0x2a7d5b={};_0x14c297<_0x36edd5[_0xf5d6('0x44')];_0x14c297+=0x1){_0x50f6a1=_0x36edd5[_0x14c297];if(_[_0xf5d6('0x45')](_0xd3ac91[_0xf5d6('0x69')][_0x50f6a1['id']])){_0xd3ac91[_0xf5d6('0x69')][_0x50f6a1['id']]=new FaxAccount(_0x50f6a1);}else{_0xd3ac91[_0xf5d6('0x42')](_0xd3ac91[_0xf5d6('0x69')][_0x50f6a1['id']],_0x50f6a1);}}}return _0xd3ac91[_0xf5d6('0x69')];};};module[_0xf5d6('0x6a')]=Realtime;