Built motion from commit (unavailable).|2.5.14
[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 _0x4a7c=['md5','util','ioredis','redis','defaults','localhost','socket.io-emitter','name','timeout','strategy','Agents','mapAgentsId','waiting','updateRealtime','prototype','_rr','length','online','loggedIn','whatsappPause','paused','available','format','whatsapp:queue:%s','emit'];(function(_0x2dbce7,_0x57cb8d){var _0x3a3ed0=function(_0x28c8c6){while(--_0x28c8c6){_0x2dbce7['push'](_0x2dbce7['shift']());}};_0x3a3ed0(++_0x57cb8d);}(_0x4a7c,0x12c));var _0xc4a7=function(_0x46519f,_0x1126d2){_0x46519f=_0x46519f-0x0;var _0x3944f2=_0x4a7c[_0x46519f];return _0x3944f2;};'use strict';var _=require('lodash');var md5=require(_0xc4a7('0x0'));var util=require(_0xc4a7('0x1'));var Redis=require(_0xc4a7('0x2'));var config=require('../../../config/environment');config[_0xc4a7('0x3')]=_[_0xc4a7('0x4')](config['redis'],{'host':_0xc4a7('0x5'),'port':0x18eb});var io=require(_0xc4a7('0x6'))(new Redis(config[_0xc4a7('0x3')]));function WhatsappQueue(_0x18a9f6){this['id']=_0x18a9f6['id']||0x0;this[_0xc4a7('0x7')]=_0x18a9f6[_0xc4a7('0x7')]||'';this['timeout']=_0x18a9f6[_0xc4a7('0x8')]||0xa;this[_0xc4a7('0x9')]=_0x18a9f6['strategy']||'beepall';this[_0xc4a7('0xa')]=_0x18a9f6[_0xc4a7('0xa')];this[_0xc4a7('0xb')]={};this[_0xc4a7('0xc')]=0x0;this['md5']='';this['updateRouting']();this[_0xc4a7('0xd')]();}WhatsappQueue[_0xc4a7('0xe')]['updateRouting']=function(){var _0x3f8e9b=this[_0xc4a7('0xb')][_0xc4a7('0xf')];this['mapAgentsId']=_['map'](this[_0xc4a7('0xa')],'id');this['mapAgentsId'][_0xc4a7('0xf')]=_0x3f8e9b;};WhatsappQueue[_0xc4a7('0xe')]['updateRealtime']=function(){this['loggedIn']=0x0;this['paused']=0x0;for(var _0x3c19ef=0x0;_0x3c19ef<this[_0xc4a7('0xa')][_0xc4a7('0x10')];_0x3c19ef+=0x1){if(this['Agents'][_0x3c19ef][_0xc4a7('0x11')]){this[_0xc4a7('0x12')]+=0x1;}if(this['Agents'][_0x3c19ef][_0xc4a7('0x13')]){this[_0xc4a7('0x14')]+=0x1;}}this[_0xc4a7('0x15')]=this[_0xc4a7('0x12')]-this['paused'];this[_0xc4a7('0x15')]=this[_0xc4a7('0x15')]>=0x0?this[_0xc4a7('0x15')]:0x0;var _0x3bdb3c={'id':this['id'],'available':this['available'],'loggedIn':this['loggedIn'],'name':this[_0xc4a7('0x7')],'paused':this[_0xc4a7('0x14')],'waiting':this[_0xc4a7('0xc')]};var _0x41ffd7=md5(JSON['stringify'](_0x3bdb3c));if(this[_0xc4a7('0x0')]!==_0x41ffd7){this[_0xc4a7('0x0')]=_0x41ffd7;io['to'](util[_0xc4a7('0x16')](_0xc4a7('0x17'),_0x3bdb3c[_0xc4a7('0x7')]))[_0xc4a7('0x18')]('whatsapp_queue:save',_0x3bdb3c);}};module['exports']=WhatsappQueue;