1f4ad2eda73bdf3ce136ad17d4a8dc4457622b75
[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 _0xae18=['socket.io-emitter','timeout','strategy','beepall','Agents','mapAgentsId','waiting','md5','updateRouting','updateRealtime','prototype','_rr','paused','length','online','loggedIn','whatsappPause','available','format','whatsapp:queue:%s','emit','exports','util','ioredis','../../../config/environment','redis','defaults','localhost'];(function(_0x16ccb7,_0x1103c0){var _0x467ae2=function(_0x107953){while(--_0x107953){_0x16ccb7['push'](_0x16ccb7['shift']());}};_0x467ae2(++_0x1103c0);}(_0xae18,0xf6));var _0x8ae1=function(_0x328a60,_0x513c88){_0x328a60=_0x328a60-0x0;var _0xa24025=_0xae18[_0x328a60];return _0xa24025;};'use strict';var _=require('lodash');var md5=require('md5');var util=require(_0x8ae1('0x0'));var Redis=require(_0x8ae1('0x1'));var config=require(_0x8ae1('0x2'));config[_0x8ae1('0x3')]=_[_0x8ae1('0x4')](config['redis'],{'host':_0x8ae1('0x5'),'port':0x18eb});var io=require(_0x8ae1('0x6'))(new Redis(config[_0x8ae1('0x3')]));function WhatsappQueue(_0x59ca85){this['id']=_0x59ca85['id']||0x0;this['name']=_0x59ca85['name']||'';this[_0x8ae1('0x7')]=_0x59ca85['timeout']||0xa;this[_0x8ae1('0x8')]=_0x59ca85['strategy']||_0x8ae1('0x9');this[_0x8ae1('0xa')]=_0x59ca85[_0x8ae1('0xa')];this[_0x8ae1('0xb')]={};this[_0x8ae1('0xc')]=0x0;this[_0x8ae1('0xd')]='';this[_0x8ae1('0xe')]();this[_0x8ae1('0xf')]();}WhatsappQueue[_0x8ae1('0x10')][_0x8ae1('0xe')]=function(){var _0x29c4ce=this[_0x8ae1('0xb')][_0x8ae1('0x11')];this[_0x8ae1('0xb')]=_['map'](this[_0x8ae1('0xa')],'id');this['mapAgentsId']['_rr']=_0x29c4ce;};WhatsappQueue[_0x8ae1('0x10')][_0x8ae1('0xf')]=function(){this['loggedIn']=0x0;this[_0x8ae1('0x12')]=0x0;for(var _0x30cede=0x0;_0x30cede<this[_0x8ae1('0xa')][_0x8ae1('0x13')];_0x30cede+=0x1){if(this['Agents'][_0x30cede][_0x8ae1('0x14')]){this[_0x8ae1('0x15')]+=0x1;}if(this['Agents'][_0x30cede][_0x8ae1('0x16')]){this[_0x8ae1('0x12')]+=0x1;}}this['available']=this['loggedIn']-this[_0x8ae1('0x12')];this[_0x8ae1('0x17')]=this['available']>=0x0?this[_0x8ae1('0x17')]:0x0;var _0x3168da={'id':this['id'],'available':this['available'],'loggedIn':this[_0x8ae1('0x15')],'name':this['name'],'paused':this[_0x8ae1('0x12')],'waiting':this[_0x8ae1('0xc')]};var _0x235a78=md5(JSON['stringify'](_0x3168da));if(this[_0x8ae1('0xd')]!==_0x235a78){this[_0x8ae1('0xd')]=_0x235a78;io['to'](util[_0x8ae1('0x18')](_0x8ae1('0x19'),_0x3168da['name']))[_0x8ae1('0x1a')]('whatsapp_queue:save',_0x3168da);}};module[_0x8ae1('0x1b')]=WhatsappQueue;