bf1160ccb8e7fbabc33da6079142eb0a46638ccc
[motion2.git] / server / services / routing / 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 _0x2ad4=['bluebird','util','lodash','moment','../model/agent','../model/interval','../model/openchannelQueue','../model/chatQueue','../model/mailQueue','../model/faxQueue','agents','intervals','chatQueues','smsQueues','mailQueues','faxQueues','chatQueuesWaitingInteractions','faxQueuesWaitingInteractions','mapKeys','hasOwnProperty','prototype','mergeFromDatabase','initAgents','isUndefined','initOpenchannelQueues','openchannelQueues','length','updateRouting','updateRealtime','initChatQueues','initSmsQueues','initMailQueues','initFaxQueues','exports'];(function(_0xc7101a,_0x207ccd){var _0x44cf8d=function(_0x341cd1){while(--_0x341cd1){_0xc7101a['push'](_0xc7101a['shift']());}};_0x44cf8d(++_0x207ccd);}(_0x2ad4,0x154));var _0x42ad=function(_0x24f870,_0x2c8a88){_0x24f870=_0x24f870-0x0;var _0x5d065b=_0x2ad4[_0x24f870];return _0x5d065b;};'use strict';var BPromise=require(_0x42ad('0x0'));var util=require(_0x42ad('0x1'));var _=require(_0x42ad('0x2'));var moment=require(_0x42ad('0x3'));var Agent=require(_0x42ad('0x4'));var Interval=require(_0x42ad('0x5'));var OpenchannelQueue=require(_0x42ad('0x6'));var ChatQueue=require(_0x42ad('0x7'));var SmsQueue=require('../model/smsQueue');var MailQueue=require(_0x42ad('0x8'));var FaxQueue=require(_0x42ad('0x9'));var Realtime=function(){this[_0x42ad('0xa')]={};this[_0x42ad('0xb')]={};this['openchannelQueues']={};this[_0x42ad('0xc')]={};this[_0x42ad('0xd')]={};this[_0x42ad('0xe')]={};this[_0x42ad('0xf')]={};this[_0x42ad('0x10')]={};this['mailQueuesWaitingInteractions']={};this['openchannelQueuesWaitingInteractions']={};this['smsQueuesWaitingInteractions']={};this[_0x42ad('0x11')]={};};function freeIsNotKey(_0x10f0e7,_0x4167f5,_0x146d09){var _0x385910=_[_0x42ad('0x12')](_0x10f0e7,function(_0x1e9592,_0x1eb328){return _0x1e9592[_0x146d09];});for(var _0x679ce8 in _0x4167f5){if(_0x4167f5[_0x42ad('0x13')](_0x679ce8)){if(!_0x385910[_0x679ce8]){delete _0x4167f5[_0x679ce8];}}}}Realtime[_0x42ad('0x14')][_0x42ad('0x15')]=function(_0x402a97,_0x414166){for(var _0x311c77 in _0x414166){if(_0x402a97['hasOwnProperty'](_0x311c77)){_0x402a97[_0x311c77]=_0x414166[_0x311c77];}}};Realtime[_0x42ad('0x14')][_0x42ad('0x16')]=function(){var _0x154395=this;return function(_0x287b0c){if(_0x287b0c){freeIsNotKey(_0x287b0c,_0x154395['agents'],'id');for(var _0x2aea3f=0x0,_0x4a6d43={},_0x48321c={};_0x2aea3f<_0x287b0c['length'];_0x2aea3f+=0x1){_0x4a6d43=_0x287b0c[_0x2aea3f];if(_[_0x42ad('0x17')](_0x154395[_0x42ad('0xa')][_0x4a6d43['id']])){_0x154395['agents'][_0x4a6d43['id']]=new Agent(_0x4a6d43);}else{_0x154395['mergeFromDatabase'](_0x154395['agents'][_0x4a6d43['id']],_0x4a6d43);}}}return _0x154395[_0x42ad('0xa')];};};Realtime[_0x42ad('0x14')]['initIntervals']=function(){var _0x56c4da=this;return function(_0x4121cc){if(_0x4121cc){freeIsNotKey(_0x4121cc,_0x56c4da[_0x42ad('0xb')],'id');for(var _0x38d8f4=0x0,_0x2f12cc={},_0x5a7311={};_0x38d8f4<_0x4121cc['length'];_0x38d8f4+=0x1){_0x2f12cc=_0x4121cc[_0x38d8f4];if(_['isUndefined'](_0x56c4da[_0x42ad('0xb')][_0x2f12cc['id']])){_0x56c4da[_0x42ad('0xb')][_0x2f12cc['id']]=new Interval(_0x2f12cc);}else{_0x56c4da[_0x42ad('0x15')](_0x56c4da[_0x42ad('0xb')][_0x2f12cc['id']],_0x2f12cc);}}}return _0x56c4da[_0x42ad('0xb')];};};Realtime['prototype'][_0x42ad('0x18')]=function(){var _0x34c92e=this;return function(_0x5e112d){if(_0x5e112d){freeIsNotKey(_0x5e112d,_0x34c92e[_0x42ad('0x19')],'id');for(var _0x41a0ec=0x0,_0x5bafae={},_0x83b449={};_0x41a0ec<_0x5e112d[_0x42ad('0x1a')];_0x41a0ec+=0x1){_0x5bafae=_0x5e112d[_0x41a0ec];if(_[_0x42ad('0x17')](_0x34c92e[_0x42ad('0x19')][_0x5bafae['id']])){_0x34c92e[_0x42ad('0x19')][_0x5bafae['id']]=new OpenchannelQueue(_0x5bafae);}else{_0x34c92e['mergeFromDatabase'](_0x34c92e[_0x42ad('0x19')][_0x5bafae['id']],_0x5bafae);}_0x34c92e[_0x42ad('0x19')][_0x5bafae['id']][_0x42ad('0x1b')]();_0x34c92e[_0x42ad('0x19')][_0x5bafae['id']][_0x42ad('0x1c')]();}}return _0x34c92e[_0x42ad('0x19')];};};Realtime[_0x42ad('0x14')][_0x42ad('0x1d')]=function(){var _0xbb4897=this;return function(_0x222864){if(_0x222864){freeIsNotKey(_0x222864,_0xbb4897[_0x42ad('0xc')],'id');for(var _0x2494e0=0x0,_0x3d2acd={},_0x54e1a6={};_0x2494e0<_0x222864[_0x42ad('0x1a')];_0x2494e0+=0x1){_0x3d2acd=_0x222864[_0x2494e0];if(_[_0x42ad('0x17')](_0xbb4897['chatQueues'][_0x3d2acd['id']])){_0xbb4897[_0x42ad('0xc')][_0x3d2acd['id']]=new ChatQueue(_0x3d2acd);}else{_0xbb4897['mergeFromDatabase'](_0xbb4897['chatQueues'][_0x3d2acd['id']],_0x3d2acd);}_0xbb4897['chatQueues'][_0x3d2acd['id']][_0x42ad('0x1b')]();_0xbb4897['chatQueues'][_0x3d2acd['id']][_0x42ad('0x1c')]();}}return _0xbb4897[_0x42ad('0xc')];};};Realtime[_0x42ad('0x14')][_0x42ad('0x1e')]=function(){var _0x2dfe1e=this;return function(_0x2ee8ae){if(_0x2ee8ae){freeIsNotKey(_0x2ee8ae,_0x2dfe1e['smsQueues'],'id');for(var _0x96465a=0x0,_0x485648={},_0x7f92b8={};_0x96465a<_0x2ee8ae[_0x42ad('0x1a')];_0x96465a+=0x1){_0x485648=_0x2ee8ae[_0x96465a];if(_['isUndefined'](_0x2dfe1e[_0x42ad('0xd')][_0x485648['id']])){_0x2dfe1e[_0x42ad('0xd')][_0x485648['id']]=new SmsQueue(_0x485648);}else{_0x2dfe1e[_0x42ad('0x15')](_0x2dfe1e[_0x42ad('0xd')][_0x485648['id']],_0x485648);}_0x2dfe1e[_0x42ad('0xd')][_0x485648['id']][_0x42ad('0x1b')]();_0x2dfe1e[_0x42ad('0xd')][_0x485648['id']][_0x42ad('0x1c')]();}}return _0x2dfe1e[_0x42ad('0xd')];};};Realtime[_0x42ad('0x14')][_0x42ad('0x1f')]=function(){var _0x58c972=this;return function(_0x4440bb){if(_0x4440bb){freeIsNotKey(_0x4440bb,_0x58c972['mailQueues'],'id');for(var _0x35765a=0x0,_0x279605={},_0x407b51={};_0x35765a<_0x4440bb[_0x42ad('0x1a')];_0x35765a+=0x1){_0x279605=_0x4440bb[_0x35765a];if(_['isUndefined'](_0x58c972[_0x42ad('0xe')][_0x279605['id']])){_0x58c972[_0x42ad('0xe')][_0x279605['id']]=new MailQueue(_0x279605);}else{_0x58c972[_0x42ad('0x15')](_0x58c972[_0x42ad('0xe')][_0x279605['id']],_0x279605);}_0x58c972['mailQueues'][_0x279605['id']][_0x42ad('0x1b')]();_0x58c972['mailQueues'][_0x279605['id']][_0x42ad('0x1c')]();}}return _0x58c972[_0x42ad('0xe')];};};Realtime['prototype'][_0x42ad('0x20')]=function(){var _0x4d1816=this;return function(_0x26c997){if(_0x26c997){freeIsNotKey(_0x26c997,_0x4d1816[_0x42ad('0xf')],'id');for(var _0x1f8ea2=0x0,_0x11a299={},_0x154032={};_0x1f8ea2<_0x26c997[_0x42ad('0x1a')];_0x1f8ea2+=0x1){_0x11a299=_0x26c997[_0x1f8ea2];if(_[_0x42ad('0x17')](_0x4d1816[_0x42ad('0xf')][_0x11a299['id']])){_0x4d1816[_0x42ad('0xf')][_0x11a299['id']]=new FaxQueue(_0x11a299);}else{_0x4d1816[_0x42ad('0x15')](_0x4d1816['faxQueues'][_0x11a299['id']],_0x11a299);}_0x4d1816['faxQueues'][_0x11a299['id']][_0x42ad('0x1b')]();_0x4d1816['faxQueues'][_0x11a299['id']][_0x42ad('0x1c')]();}}return _0x4d1816[_0x42ad('0xf')];};};module[_0x42ad('0x21')]=Realtime;