6bc03a804f8884f26e629d89a403f5ad9258b82b
[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 _0xf311=['strategy','beepall','Agents','mapAgentsId','waiting','updateRouting','updateRealtime','prototype','map','_rr','online','loggedIn','whatsappPause','available','paused','stringify','format','whatsapp_queue:save','exports','md5','util','ioredis','redis','defaults','socket.io-emitter','name','timeout'];(function(_0x5746df,_0x45e7ea){var _0x2173f6=function(_0x437699){while(--_0x437699){_0x5746df['push'](_0x5746df['shift']());}};_0x2173f6(++_0x45e7ea);}(_0xf311,0x18d));var _0x1f31=function(_0x1cc8fe,_0x105328){_0x1cc8fe=_0x1cc8fe-0x0;var _0x230054=_0xf311[_0x1cc8fe];return _0x230054;};'use strict';var _=require('lodash');var md5=require(_0x1f31('0x0'));var util=require(_0x1f31('0x1'));var Redis=require(_0x1f31('0x2'));var config=require('../../../config/environment');config[_0x1f31('0x3')]=_[_0x1f31('0x4')](config[_0x1f31('0x3')],{'host':'localhost','port':0x18eb});var io=require(_0x1f31('0x5'))(new Redis(config[_0x1f31('0x3')]));function WhatsappQueue(_0x581b04){this['id']=_0x581b04['id']||0x0;this[_0x1f31('0x6')]=_0x581b04[_0x1f31('0x6')]||'';this['timeout']=_0x581b04[_0x1f31('0x7')]||0xa;this[_0x1f31('0x8')]=_0x581b04['strategy']||_0x1f31('0x9');this['Agents']=_0x581b04[_0x1f31('0xa')];this[_0x1f31('0xb')]={};this[_0x1f31('0xc')]=0x0;this[_0x1f31('0x0')]='';this[_0x1f31('0xd')]();this[_0x1f31('0xe')]();}WhatsappQueue[_0x1f31('0xf')][_0x1f31('0xd')]=function(){var _0x2db999=this[_0x1f31('0xb')]['_rr'];this['mapAgentsId']=_[_0x1f31('0x10')](this['Agents'],'id');this[_0x1f31('0xb')][_0x1f31('0x11')]=_0x2db999;};WhatsappQueue[_0x1f31('0xf')]['updateRealtime']=function(){this['loggedIn']=0x0;this['paused']=0x0;for(var _0x261f48=0x0;_0x261f48<this[_0x1f31('0xa')]['length'];_0x261f48+=0x1){if(this[_0x1f31('0xa')][_0x261f48][_0x1f31('0x12')]){this[_0x1f31('0x13')]+=0x1;}if(this[_0x1f31('0xa')][_0x261f48][_0x1f31('0x14')]){this['paused']+=0x1;}}this[_0x1f31('0x15')]=this['loggedIn']-this[_0x1f31('0x16')];this['available']=this[_0x1f31('0x15')]>=0x0?this[_0x1f31('0x15')]:0x0;var _0x3e8d56={'id':this['id'],'available':this[_0x1f31('0x15')],'loggedIn':this['loggedIn'],'name':this[_0x1f31('0x6')],'paused':this[_0x1f31('0x16')],'waiting':this[_0x1f31('0xc')]};var _0xd056af=md5(JSON[_0x1f31('0x17')](_0x3e8d56));if(this[_0x1f31('0x0')]!==_0xd056af){this[_0x1f31('0x0')]=_0xd056af;io['to'](util[_0x1f31('0x18')]('whatsapp:queue:%s',_0x3e8d56[_0x1f31('0x6')]))['emit'](_0x1f31('0x19'),_0x3e8d56);}};module[_0x1f31('0x1a')]=WhatsappQueue;