Built motion from commit 192134f6.|2.6.25
[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 _0x5f26=['name','timeout','strategy','beepall','Agents','mapAgentsId','updateRouting','updateRealtime','prototype','map','_rr','loggedIn','length','online','whatsappPause','paused','available','waiting','stringify','emit','whatsapp_queue:save','exports','md5','ioredis','../../../config/environment','redis','defaults','localhost','socket.io-emitter'];(function(_0xf60ce3,_0x2ed4f5){var _0x1b40b5=function(_0x52f3b6){while(--_0x52f3b6){_0xf60ce3['push'](_0xf60ce3['shift']());}};_0x1b40b5(++_0x2ed4f5);}(_0x5f26,0x1ac));var _0x65f2=function(_0x34efa6,_0x343fe2){_0x34efa6=_0x34efa6-0x0;var _0x469490=_0x5f26[_0x34efa6];return _0x469490;};'use strict';var _=require('lodash');var md5=require(_0x65f2('0x0'));var util=require('util');var Redis=require(_0x65f2('0x1'));var config=require(_0x65f2('0x2'));config[_0x65f2('0x3')]=_[_0x65f2('0x4')](config[_0x65f2('0x3')],{'host':_0x65f2('0x5'),'port':0x18eb});var io=require(_0x65f2('0x6'))(new Redis(config[_0x65f2('0x3')]));function WhatsappQueue(_0x1d8e1d){this['id']=_0x1d8e1d['id']||0x0;this['name']=_0x1d8e1d[_0x65f2('0x7')]||'';this[_0x65f2('0x8')]=_0x1d8e1d[_0x65f2('0x8')]||0xa;this['strategy']=_0x1d8e1d[_0x65f2('0x9')]||_0x65f2('0xa');this[_0x65f2('0xb')]=_0x1d8e1d[_0x65f2('0xb')];this[_0x65f2('0xc')]={};this['waiting']=0x0;this[_0x65f2('0x0')]='';this[_0x65f2('0xd')]();this[_0x65f2('0xe')]();}WhatsappQueue[_0x65f2('0xf')][_0x65f2('0xd')]=function(){var _0x2d67d4=this[_0x65f2('0xc')]['_rr'];this[_0x65f2('0xc')]=_[_0x65f2('0x10')](this['Agents'],'id');this[_0x65f2('0xc')][_0x65f2('0x11')]=_0x2d67d4;};WhatsappQueue[_0x65f2('0xf')][_0x65f2('0xe')]=function(){this[_0x65f2('0x12')]=0x0;this['paused']=0x0;for(var _0xa9ba0e=0x0;_0xa9ba0e<this[_0x65f2('0xb')][_0x65f2('0x13')];_0xa9ba0e+=0x1){if(this[_0x65f2('0xb')][_0xa9ba0e][_0x65f2('0x14')]){this[_0x65f2('0x12')]+=0x1;}if(this[_0x65f2('0xb')][_0xa9ba0e][_0x65f2('0x15')]){this[_0x65f2('0x16')]+=0x1;}}this[_0x65f2('0x17')]=this[_0x65f2('0x12')]-this['paused'];this[_0x65f2('0x17')]=this[_0x65f2('0x17')]>=0x0?this[_0x65f2('0x17')]:0x0;var _0x7ebc32={'id':this['id'],'available':this[_0x65f2('0x17')],'loggedIn':this['loggedIn'],'name':this['name'],'paused':this['paused'],'waiting':this[_0x65f2('0x18')]};var _0x3e21c7=md5(JSON[_0x65f2('0x19')](_0x7ebc32));if(this['md5']!==_0x3e21c7){this[_0x65f2('0x0')]=_0x3e21c7;io['to'](util['format']('whatsapp:queue:%s',_0x7ebc32[_0x65f2('0x7')]))[_0x65f2('0x1a')](_0x65f2('0x1b'),_0x7ebc32);}};module[_0x65f2('0x1c')]=WhatsappQueue;