581c898d1989a870765be87fa34f9e5ad9d5949d
[motion2.git] / server / services / routing / model / whatsappQueue.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 _0xba2f=['lodash','md5','util','ioredis','redis','defaults','localhost','socket.io-emitter','name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','prototype','_rr','updateRealtime','loggedIn','paused','length','online','whatsappPause','available','stringify','format','whatsapp:queue:%s','emit','whatsapp_queue:save','exports'];(function(_0x43d2d4,_0x2a0913){var _0x28c926=function(_0xd3c0ef){while(--_0xd3c0ef){_0x43d2d4['push'](_0x43d2d4['shift']());}};_0x28c926(++_0x2a0913);}(_0xba2f,0x1e0));var _0xfba2=function(_0x349e66,_0x40079c){_0x349e66=_0x349e66-0x0;var _0x2590a5=_0xba2f[_0x349e66];return _0x2590a5;};'use strict';var _=require(_0xfba2('0x0'));var md5=require(_0xfba2('0x1'));var util=require(_0xfba2('0x2'));var Redis=require(_0xfba2('0x3'));var config=require('../../../config/environment');config[_0xfba2('0x4')]=_[_0xfba2('0x5')](config[_0xfba2('0x4')],{'host':_0xfba2('0x6'),'port':0x18eb});var io=require(_0xfba2('0x7'))(new Redis(config[_0xfba2('0x4')]));function WhatsappQueue(_0x12f99b){this['id']=_0x12f99b['id']||0x0;this[_0xfba2('0x8')]=_0x12f99b[_0xfba2('0x8')]||'';this[_0xfba2('0x9')]=_0x12f99b[_0xfba2('0x9')]||0xa;this[_0xfba2('0xa')]=_0x12f99b['strategy']||_0xfba2('0xb');this[_0xfba2('0xc')]=_0x12f99b[_0xfba2('0xc')];this[_0xfba2('0xd')]={};this[_0xfba2('0xe')]=0x0;this['md5']='';this['updateRouting']();this['updateRealtime']();}WhatsappQueue[_0xfba2('0xf')]['updateRouting']=function(){var _0x58f40b=this[_0xfba2('0xd')][_0xfba2('0x10')];this[_0xfba2('0xd')]=_['map'](this[_0xfba2('0xc')],'id');this[_0xfba2('0xd')]['_rr']=_0x58f40b;};WhatsappQueue[_0xfba2('0xf')][_0xfba2('0x11')]=function(){this[_0xfba2('0x12')]=0x0;this[_0xfba2('0x13')]=0x0;for(var _0x5e4701=0x0;_0x5e4701<this[_0xfba2('0xc')][_0xfba2('0x14')];_0x5e4701+=0x1){if(this['Agents'][_0x5e4701][_0xfba2('0x15')]){this['loggedIn']+=0x1;}if(this['Agents'][_0x5e4701][_0xfba2('0x16')]){this['paused']+=0x1;}}this[_0xfba2('0x17')]=this[_0xfba2('0x12')]-this[_0xfba2('0x13')];this[_0xfba2('0x17')]=this[_0xfba2('0x17')]>=0x0?this[_0xfba2('0x17')]:0x0;var _0x165f05={'id':this['id'],'available':this['available'],'loggedIn':this['loggedIn'],'name':this[_0xfba2('0x8')],'paused':this['paused'],'waiting':this['waiting']};var _0x52d721=md5(JSON[_0xfba2('0x18')](_0x165f05));if(this[_0xfba2('0x1')]!==_0x52d721){this[_0xfba2('0x1')]=_0x52d721;io['to'](util[_0xfba2('0x19')](_0xfba2('0x1a'),_0x165f05['name']))[_0xfba2('0x1b')](_0xfba2('0x1c'),_0x165f05);}};module[_0xfba2('0x1d')]=WhatsappQueue;