b8d014350fe8ab2f1c29a77bc748a56db8472d48
[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 _0x5c24=['timeout','strategy','beepall','Agents','waiting','updateRouting','_rr','mapAgentsId','map','prototype','updateRealtime','loggedIn','length','whatsappPause','available','paused','stringify','whatsapp:queue:%s','emit','whatsapp_queue:save','lodash','md5','util','ioredis','../../../config/environment','redis','defaults','localhost','socket.io-emitter','name'];(function(_0x204a6f,_0xf149a){var _0x447627=function(_0x289b47){while(--_0x289b47){_0x204a6f['push'](_0x204a6f['shift']());}};_0x447627(++_0xf149a);}(_0x5c24,0x1f4));var _0x45c2=function(_0x296754,_0x5befe9){_0x296754=_0x296754-0x0;var _0x1d9f1d=_0x5c24[_0x296754];return _0x1d9f1d;};'use strict';var _=require(_0x45c2('0x0'));var md5=require(_0x45c2('0x1'));var util=require(_0x45c2('0x2'));var Redis=require(_0x45c2('0x3'));var config=require(_0x45c2('0x4'));config[_0x45c2('0x5')]=_[_0x45c2('0x6')](config[_0x45c2('0x5')],{'host':_0x45c2('0x7'),'port':0x18eb});var io=require(_0x45c2('0x8'))(new Redis(config[_0x45c2('0x5')]));function WhatsappQueue(_0x7908c1){this['id']=_0x7908c1['id']||0x0;this[_0x45c2('0x9')]=_0x7908c1[_0x45c2('0x9')]||'';this[_0x45c2('0xa')]=_0x7908c1['timeout']||0xa;this['strategy']=_0x7908c1[_0x45c2('0xb')]||_0x45c2('0xc');this['Agents']=_0x7908c1[_0x45c2('0xd')];this['mapAgentsId']={};this[_0x45c2('0xe')]=0x0;this['md5']='';this[_0x45c2('0xf')]();this['updateRealtime']();}WhatsappQueue['prototype'][_0x45c2('0xf')]=function(){var _0x52584f=this['mapAgentsId'][_0x45c2('0x10')];this[_0x45c2('0x11')]=_[_0x45c2('0x12')](this['Agents'],'id');this[_0x45c2('0x11')][_0x45c2('0x10')]=_0x52584f;};WhatsappQueue[_0x45c2('0x13')][_0x45c2('0x14')]=function(){this[_0x45c2('0x15')]=0x0;this['paused']=0x0;for(var _0x5e67ae=0x0;_0x5e67ae<this[_0x45c2('0xd')][_0x45c2('0x16')];_0x5e67ae+=0x1){if(this[_0x45c2('0xd')][_0x5e67ae]['online']){this[_0x45c2('0x15')]+=0x1;}if(this[_0x45c2('0xd')][_0x5e67ae][_0x45c2('0x17')]){this['paused']+=0x1;}}this['available']=this['loggedIn']-this['paused'];this[_0x45c2('0x18')]=this['available']>=0x0?this[_0x45c2('0x18')]:0x0;var _0x25b35c={'id':this['id'],'available':this[_0x45c2('0x18')],'loggedIn':this['loggedIn'],'name':this[_0x45c2('0x9')],'paused':this[_0x45c2('0x19')],'waiting':this[_0x45c2('0xe')]};var _0x7d1ece=md5(JSON[_0x45c2('0x1a')](_0x25b35c));if(this['md5']!==_0x7d1ece){this[_0x45c2('0x1')]=_0x7d1ece;io['to'](util['format'](_0x45c2('0x1b'),_0x25b35c['name']))[_0x45c2('0x1c')](_0x45c2('0x1d'),_0x25b35c);}};module['exports']=WhatsappQueue;