8d14e5711254acbcdfcda1583deddcaba3f3faa8
[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 _0x6336=['whatsappPause','available','stringify','whatsapp_queue:save','exports','lodash','md5','util','ioredis','../../../config/environment','defaults','localhost','redis','name','strategy','beepall','Agents','waiting','updateRouting','updateRealtime','prototype','mapAgentsId','_rr','map','loggedIn','paused','length','online'];(function(_0x39096d,_0x51f8a0){var _0x13da4f=function(_0x11e6b2){while(--_0x11e6b2){_0x39096d['push'](_0x39096d['shift']());}};_0x13da4f(++_0x51f8a0);}(_0x6336,0xc9));var _0x6633=function(_0x795cc3,_0x179eb4){_0x795cc3=_0x795cc3-0x0;var _0x183671=_0x6336[_0x795cc3];return _0x183671;};'use strict';var _=require(_0x6633('0x0'));var md5=require(_0x6633('0x1'));var util=require(_0x6633('0x2'));var Redis=require(_0x6633('0x3'));var config=require(_0x6633('0x4'));config['redis']=_[_0x6633('0x5')](config['redis'],{'host':_0x6633('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x6633('0x7')]));function WhatsappQueue(_0x2fcfa9){this['id']=_0x2fcfa9['id']||0x0;this['name']=_0x2fcfa9[_0x6633('0x8')]||'';this['timeout']=_0x2fcfa9['timeout']||0xa;this[_0x6633('0x9')]=_0x2fcfa9[_0x6633('0x9')]||_0x6633('0xa');this[_0x6633('0xb')]=_0x2fcfa9[_0x6633('0xb')];this['mapAgentsId']={};this[_0x6633('0xc')]=0x0;this[_0x6633('0x1')]='';this[_0x6633('0xd')]();this[_0x6633('0xe')]();}WhatsappQueue[_0x6633('0xf')][_0x6633('0xd')]=function(){var _0x2f943a=this[_0x6633('0x10')][_0x6633('0x11')];this[_0x6633('0x10')]=_[_0x6633('0x12')](this[_0x6633('0xb')],'id');this[_0x6633('0x10')][_0x6633('0x11')]=_0x2f943a;};WhatsappQueue['prototype'][_0x6633('0xe')]=function(){this[_0x6633('0x13')]=0x0;this[_0x6633('0x14')]=0x0;for(var _0x22625b=0x0;_0x22625b<this['Agents'][_0x6633('0x15')];_0x22625b+=0x1){if(this[_0x6633('0xb')][_0x22625b][_0x6633('0x16')]){this[_0x6633('0x13')]+=0x1;}if(this['Agents'][_0x22625b][_0x6633('0x17')]){this[_0x6633('0x14')]+=0x1;}}this['available']=this[_0x6633('0x13')]-this[_0x6633('0x14')];this[_0x6633('0x18')]=this['available']>=0x0?this[_0x6633('0x18')]:0x0;var _0x184594={'id':this['id'],'available':this['available'],'loggedIn':this[_0x6633('0x13')],'name':this[_0x6633('0x8')],'paused':this[_0x6633('0x14')],'waiting':this[_0x6633('0xc')]};var _0x33f403=md5(JSON[_0x6633('0x19')](_0x184594));if(this[_0x6633('0x1')]!==_0x33f403){this['md5']=_0x33f403;io['to'](util['format']('whatsapp:queue:%s',_0x184594[_0x6633('0x8')]))['emit'](_0x6633('0x1a'),_0x184594);}};module[_0x6633('0x1b')]=WhatsappQueue;