509ae00db6457cea8e396852eb68ac83acf7757b
[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 _0x62da=['paused','length','online','available','stringify','whatsapp:queue:%s','emit','whatsapp_queue:save','exports','util','ioredis','../../../config/environment','redis','localhost','name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','md5','updateRouting','updateRealtime','prototype','_rr','map','loggedIn'];(function(_0x43ea9e,_0x4ba4d2){var _0x19252a=function(_0x20b20e){while(--_0x20b20e){_0x43ea9e['push'](_0x43ea9e['shift']());}};_0x19252a(++_0x4ba4d2);}(_0x62da,0xe9));var _0xa62d=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x62da[_0x20a584];return _0x4b41a8;};'use strict';var _=require('lodash');var md5=require('md5');var util=require(_0xa62d('0x0'));var Redis=require(_0xa62d('0x1'));var config=require(_0xa62d('0x2'));config[_0xa62d('0x3')]=_['defaults'](config['redis'],{'host':_0xa62d('0x4'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xa62d('0x3')]));function WhatsappQueue(_0x5dc23f){this['id']=_0x5dc23f['id']||0x0;this['name']=_0x5dc23f[_0xa62d('0x5')]||'';this['timeout']=_0x5dc23f[_0xa62d('0x6')]||0xa;this[_0xa62d('0x7')]=_0x5dc23f[_0xa62d('0x7')]||_0xa62d('0x8');this[_0xa62d('0x9')]=_0x5dc23f[_0xa62d('0x9')];this[_0xa62d('0xa')]={};this[_0xa62d('0xb')]=0x0;this[_0xa62d('0xc')]='';this[_0xa62d('0xd')]();this[_0xa62d('0xe')]();}WhatsappQueue[_0xa62d('0xf')][_0xa62d('0xd')]=function(){var _0x52411c=this[_0xa62d('0xa')][_0xa62d('0x10')];this[_0xa62d('0xa')]=_[_0xa62d('0x11')](this[_0xa62d('0x9')],'id');this[_0xa62d('0xa')][_0xa62d('0x10')]=_0x52411c;};WhatsappQueue[_0xa62d('0xf')][_0xa62d('0xe')]=function(){this[_0xa62d('0x12')]=0x0;this[_0xa62d('0x13')]=0x0;for(var _0x499d8f=0x0;_0x499d8f<this[_0xa62d('0x9')][_0xa62d('0x14')];_0x499d8f+=0x1){if(this[_0xa62d('0x9')][_0x499d8f][_0xa62d('0x15')]){this['loggedIn']+=0x1;}if(this['Agents'][_0x499d8f]['whatsappPause']){this['paused']+=0x1;}}this[_0xa62d('0x16')]=this['loggedIn']-this[_0xa62d('0x13')];this[_0xa62d('0x16')]=this['available']>=0x0?this[_0xa62d('0x16')]:0x0;var _0x205146={'id':this['id'],'available':this[_0xa62d('0x16')],'loggedIn':this[_0xa62d('0x12')],'name':this[_0xa62d('0x5')],'paused':this[_0xa62d('0x13')],'waiting':this[_0xa62d('0xb')]};var _0x11712c=md5(JSON[_0xa62d('0x17')](_0x205146));if(this[_0xa62d('0xc')]!==_0x11712c){this[_0xa62d('0xc')]=_0x11712c;io['to'](util['format'](_0xa62d('0x18'),_0x205146[_0xa62d('0x5')]))[_0xa62d('0x19')](_0xa62d('0x1a'),_0x205146);}};module[_0xa62d('0x1b')]=WhatsappQueue;