d0ca629e518d2c385f7ba32b31fb0b9dcc7652a7
[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 _0x55ca=['initAgents','length','isUndefined','mergeFromDatabase','initIntervals','initOpenchannelQueues','updateRouting','updateRealtime','initChatQueues','chatQueues','initSmsQueues','initFaxQueues','faxQueues','exports','bluebird','util','../model/interval','../model/openchannelQueue','../model/smsQueue','../model/mailQueue','../model/faxQueue','../model/whatsappQueue','agents','intervals','openchannelQueues','smsQueues','mailQueues','whatsappQueues','chatQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','mapKeys','prototype','hasOwnProperty'];(function(_0x3ab51d,_0x2fa01d){var _0x29a04e=function(_0x7807b0){while(--_0x7807b0){_0x3ab51d['push'](_0x3ab51d['shift']());}};_0x29a04e(++_0x2fa01d);}(_0x55ca,0x126));var _0xa55c=function(_0x80544e,_0x37a3f3){_0x80544e=_0x80544e-0x0;var _0x4f9b90=_0x55ca[_0x80544e];return _0x4f9b90;};'use strict';var BPromise=require(_0xa55c('0x0'));var util=require(_0xa55c('0x1'));var _=require('lodash');var moment=require('moment');var Agent=require('../model/agent');var Interval=require(_0xa55c('0x2'));var OpenchannelQueue=require(_0xa55c('0x3'));var ChatQueue=require('../model/chatQueue');var SmsQueue=require(_0xa55c('0x4'));var MailQueue=require(_0xa55c('0x5'));var FaxQueue=require(_0xa55c('0x6'));var WhatsappQueue=require(_0xa55c('0x7'));var Realtime=function(){this[_0xa55c('0x8')]={};this[_0xa55c('0x9')]={};this[_0xa55c('0xa')]={};this['chatQueues']={};this[_0xa55c('0xb')]={};this[_0xa55c('0xc')]={};this['faxQueues']={};this[_0xa55c('0xd')]={};this[_0xa55c('0xe')]={};this['mailQueuesWaitingInteractions']={};this['openchannelQueuesWaitingInteractions']={};this[_0xa55c('0xf')]={};this[_0xa55c('0x10')]={};this[_0xa55c('0x11')]={};};function freeIsNotKey(_0x5d8e5a,_0x31646d,_0xe6d826){var _0x508342=_[_0xa55c('0x12')](_0x5d8e5a,function(_0x3998f7,_0x15eec8){return _0x3998f7[_0xe6d826];});for(var _0x5d47ff in _0x31646d){if(_0x31646d['hasOwnProperty'](_0x5d47ff)){if(!_0x508342[_0x5d47ff]){delete _0x31646d[_0x5d47ff];}}}}Realtime[_0xa55c('0x13')]['mergeFromDatabase']=function(_0x5a3672,_0x59ea8d){for(var _0x18ee85 in _0x59ea8d){if(_0x5a3672[_0xa55c('0x14')](_0x18ee85)){_0x5a3672[_0x18ee85]=_0x59ea8d[_0x18ee85];}}};Realtime[_0xa55c('0x13')][_0xa55c('0x15')]=function(){var _0x458480=this;return function(_0x247e77){if(_0x247e77){freeIsNotKey(_0x247e77,_0x458480['agents'],'id');for(var _0x3ccf65=0x0,_0x3dcf4f={},_0x25934f={};_0x3ccf65<_0x247e77[_0xa55c('0x16')];_0x3ccf65+=0x1){_0x3dcf4f=_0x247e77[_0x3ccf65];if(_[_0xa55c('0x17')](_0x458480[_0xa55c('0x8')][_0x3dcf4f['id']])){_0x458480[_0xa55c('0x8')][_0x3dcf4f['id']]=new Agent(_0x3dcf4f);}else{_0x458480[_0xa55c('0x18')](_0x458480[_0xa55c('0x8')][_0x3dcf4f['id']],_0x3dcf4f);}}}return _0x458480['agents'];};};Realtime[_0xa55c('0x13')][_0xa55c('0x19')]=function(){var _0x461284=this;return function(_0x358b61){if(_0x358b61){freeIsNotKey(_0x358b61,_0x461284[_0xa55c('0x9')],'id');for(var _0x5426e5=0x0,_0x4c0daf={},_0x5f5158={};_0x5426e5<_0x358b61[_0xa55c('0x16')];_0x5426e5+=0x1){_0x4c0daf=_0x358b61[_0x5426e5];if(_[_0xa55c('0x17')](_0x461284[_0xa55c('0x9')][_0x4c0daf['id']])){_0x461284['intervals'][_0x4c0daf['id']]=new Interval(_0x4c0daf);}else{_0x461284[_0xa55c('0x18')](_0x461284[_0xa55c('0x9')][_0x4c0daf['id']],_0x4c0daf);}}}return _0x461284['intervals'];};};Realtime[_0xa55c('0x13')][_0xa55c('0x1a')]=function(){var _0x940f28=this;return function(_0x1965f1){if(_0x1965f1){freeIsNotKey(_0x1965f1,_0x940f28[_0xa55c('0xa')],'id');for(var _0x49ed04=0x0,_0x1fc828={},_0x504c24={};_0x49ed04<_0x1965f1['length'];_0x49ed04+=0x1){_0x1fc828=_0x1965f1[_0x49ed04];if(_['isUndefined'](_0x940f28[_0xa55c('0xa')][_0x1fc828['id']])){_0x940f28['openchannelQueues'][_0x1fc828['id']]=new OpenchannelQueue(_0x1fc828);}else{_0x940f28[_0xa55c('0x18')](_0x940f28[_0xa55c('0xa')][_0x1fc828['id']],_0x1fc828);}_0x940f28[_0xa55c('0xa')][_0x1fc828['id']][_0xa55c('0x1b')]();_0x940f28[_0xa55c('0xa')][_0x1fc828['id']][_0xa55c('0x1c')]();}}return _0x940f28[_0xa55c('0xa')];};};Realtime[_0xa55c('0x13')][_0xa55c('0x1d')]=function(){var _0x3cd152=this;return function(_0x1273d7){if(_0x1273d7){freeIsNotKey(_0x1273d7,_0x3cd152['chatQueues'],'id');for(var _0x430d55=0x0,_0x28814f={},_0x1c9f6b={};_0x430d55<_0x1273d7[_0xa55c('0x16')];_0x430d55+=0x1){_0x28814f=_0x1273d7[_0x430d55];if(_['isUndefined'](_0x3cd152[_0xa55c('0x1e')][_0x28814f['id']])){_0x3cd152[_0xa55c('0x1e')][_0x28814f['id']]=new ChatQueue(_0x28814f);}else{_0x3cd152[_0xa55c('0x18')](_0x3cd152[_0xa55c('0x1e')][_0x28814f['id']],_0x28814f);}_0x3cd152[_0xa55c('0x1e')][_0x28814f['id']][_0xa55c('0x1b')]();_0x3cd152['chatQueues'][_0x28814f['id']][_0xa55c('0x1c')]();}}return _0x3cd152['chatQueues'];};};Realtime[_0xa55c('0x13')][_0xa55c('0x1f')]=function(){var _0x1cc53e=this;return function(_0x223813){if(_0x223813){freeIsNotKey(_0x223813,_0x1cc53e['smsQueues'],'id');for(var _0x3d28fb=0x0,_0x2096ae={},_0x331e58={};_0x3d28fb<_0x223813[_0xa55c('0x16')];_0x3d28fb+=0x1){_0x2096ae=_0x223813[_0x3d28fb];if(_[_0xa55c('0x17')](_0x1cc53e[_0xa55c('0xb')][_0x2096ae['id']])){_0x1cc53e[_0xa55c('0xb')][_0x2096ae['id']]=new SmsQueue(_0x2096ae);}else{_0x1cc53e[_0xa55c('0x18')](_0x1cc53e[_0xa55c('0xb')][_0x2096ae['id']],_0x2096ae);}_0x1cc53e[_0xa55c('0xb')][_0x2096ae['id']][_0xa55c('0x1b')]();_0x1cc53e['smsQueues'][_0x2096ae['id']]['updateRealtime']();}}return _0x1cc53e[_0xa55c('0xb')];};};Realtime[_0xa55c('0x13')]['initMailQueues']=function(){var _0x30fadd=this;return function(_0x2f0110){if(_0x2f0110){freeIsNotKey(_0x2f0110,_0x30fadd[_0xa55c('0xc')],'id');for(var _0x1839ac=0x0,_0x30d4f8={},_0x38ff96={};_0x1839ac<_0x2f0110[_0xa55c('0x16')];_0x1839ac+=0x1){_0x30d4f8=_0x2f0110[_0x1839ac];if(_[_0xa55c('0x17')](_0x30fadd[_0xa55c('0xc')][_0x30d4f8['id']])){_0x30fadd['mailQueues'][_0x30d4f8['id']]=new MailQueue(_0x30d4f8);}else{_0x30fadd['mergeFromDatabase'](_0x30fadd['mailQueues'][_0x30d4f8['id']],_0x30d4f8);}_0x30fadd[_0xa55c('0xc')][_0x30d4f8['id']][_0xa55c('0x1b')]();_0x30fadd[_0xa55c('0xc')][_0x30d4f8['id']]['updateRealtime']();}}return _0x30fadd[_0xa55c('0xc')];};};Realtime['prototype'][_0xa55c('0x20')]=function(){var _0x4ad813=this;return function(_0x18c6f1){if(_0x18c6f1){freeIsNotKey(_0x18c6f1,_0x4ad813[_0xa55c('0x21')],'id');for(var _0x3c0ec1=0x0,_0x4d3eb5={},_0x7c4a47={};_0x3c0ec1<_0x18c6f1[_0xa55c('0x16')];_0x3c0ec1+=0x1){_0x4d3eb5=_0x18c6f1[_0x3c0ec1];if(_['isUndefined'](_0x4ad813[_0xa55c('0x21')][_0x4d3eb5['id']])){_0x4ad813[_0xa55c('0x21')][_0x4d3eb5['id']]=new FaxQueue(_0x4d3eb5);}else{_0x4ad813['mergeFromDatabase'](_0x4ad813['faxQueues'][_0x4d3eb5['id']],_0x4d3eb5);}_0x4ad813[_0xa55c('0x21')][_0x4d3eb5['id']]['updateRouting']();_0x4ad813[_0xa55c('0x21')][_0x4d3eb5['id']][_0xa55c('0x1c')]();}}return _0x4ad813['faxQueues'];};};Realtime['prototype']['initWhatsappQueues']=function(){var _0x4de781=this;return function(_0x3b3308){if(_0x3b3308){freeIsNotKey(_0x3b3308,_0x4de781[_0xa55c('0xd')],'id');for(var _0x429336=0x0,_0x99c4f8={},_0x2d8cbf={};_0x429336<_0x3b3308['length'];_0x429336+=0x1){_0x99c4f8=_0x3b3308[_0x429336];if(_[_0xa55c('0x17')](_0x4de781[_0xa55c('0xd')][_0x99c4f8['id']])){_0x4de781[_0xa55c('0xd')][_0x99c4f8['id']]=new WhatsappQueue(_0x99c4f8);}else{_0x4de781[_0xa55c('0x18')](_0x4de781[_0xa55c('0xd')][_0x99c4f8['id']],_0x99c4f8);}_0x4de781[_0xa55c('0xd')][_0x99c4f8['id']]['updateRouting']();_0x4de781[_0xa55c('0xd')][_0x99c4f8['id']]['updateRealtime']();}}return _0x4de781['whatsappQueues'];};};module[_0xa55c('0x22')]=Realtime;