2d39e1ecfe64a707299c24559666e4487c67223d
[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 _0x8c47=['mapAgentsId','waiting','md5','updateRouting','prototype','_rr','updateRealtime','loggedIn','paused','length','whatsappPause','available','stringify','format','whatsapp:queue:%s','whatsapp_queue:save','util','ioredis','../../../config/environment','redis','defaults','localhost','socket.io-emitter','name','timeout','beepall','Agents'];(function(_0x3e6d5d,_0x264c7a){var _0x238923=function(_0x201b19){while(--_0x201b19){_0x3e6d5d['push'](_0x3e6d5d['shift']());}};_0x238923(++_0x264c7a);}(_0x8c47,0x16f));var _0x78c4=function(_0x46698a,_0x8de1e4){_0x46698a=_0x46698a-0x0;var _0x356db0=_0x8c47[_0x46698a];return _0x356db0;};'use strict';var _=require('lodash');var md5=require('md5');var util=require(_0x78c4('0x0'));var Redis=require(_0x78c4('0x1'));var config=require(_0x78c4('0x2'));config[_0x78c4('0x3')]=_[_0x78c4('0x4')](config[_0x78c4('0x3')],{'host':_0x78c4('0x5'),'port':0x18eb});var io=require(_0x78c4('0x6'))(new Redis(config[_0x78c4('0x3')]));function WhatsappQueue(_0x53bd03){this['id']=_0x53bd03['id']||0x0;this[_0x78c4('0x7')]=_0x53bd03[_0x78c4('0x7')]||'';this[_0x78c4('0x8')]=_0x53bd03['timeout']||0xa;this['strategy']=_0x53bd03['strategy']||_0x78c4('0x9');this[_0x78c4('0xa')]=_0x53bd03['Agents'];this[_0x78c4('0xb')]={};this[_0x78c4('0xc')]=0x0;this[_0x78c4('0xd')]='';this[_0x78c4('0xe')]();this['updateRealtime']();}WhatsappQueue[_0x78c4('0xf')]['updateRouting']=function(){var _0x5b81e9=this['mapAgentsId'][_0x78c4('0x10')];this[_0x78c4('0xb')]=_['map'](this[_0x78c4('0xa')],'id');this[_0x78c4('0xb')][_0x78c4('0x10')]=_0x5b81e9;};WhatsappQueue['prototype'][_0x78c4('0x11')]=function(){this[_0x78c4('0x12')]=0x0;this[_0x78c4('0x13')]=0x0;for(var _0x52632b=0x0;_0x52632b<this[_0x78c4('0xa')][_0x78c4('0x14')];_0x52632b+=0x1){if(this[_0x78c4('0xa')][_0x52632b]['online']){this[_0x78c4('0x12')]+=0x1;}if(this['Agents'][_0x52632b][_0x78c4('0x15')]){this[_0x78c4('0x13')]+=0x1;}}this[_0x78c4('0x16')]=this[_0x78c4('0x12')]-this[_0x78c4('0x13')];this[_0x78c4('0x16')]=this['available']>=0x0?this[_0x78c4('0x16')]:0x0;var _0x437b94={'id':this['id'],'available':this['available'],'loggedIn':this[_0x78c4('0x12')],'name':this[_0x78c4('0x7')],'paused':this['paused'],'waiting':this['waiting']};var _0x39be51=md5(JSON[_0x78c4('0x17')](_0x437b94));if(this[_0x78c4('0xd')]!==_0x39be51){this[_0x78c4('0xd')]=_0x39be51;io['to'](util[_0x78c4('0x18')](_0x78c4('0x19'),_0x437b94[_0x78c4('0x7')]))['emit'](_0x78c4('0x1a'),_0x437b94);}};module['exports']=WhatsappQueue;