d5168f298ce8717778aa6b780bf118a3d9f0cf5c
[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 _0x0300=['length','online','whatsappPause','available','stringify','whatsapp:queue:%s','emit','whatsapp_queue:save','exports','md5','ioredis','redis','defaults','localhost','socket.io-emitter','name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','updateRouting','updateRealtime','_rr','map','prototype','loggedIn','paused'];(function(_0x305da2,_0x10d5df){var _0x2b5102=function(_0x3c271f){while(--_0x3c271f){_0x305da2['push'](_0x305da2['shift']());}};_0x2b5102(++_0x10d5df);}(_0x0300,0x10e));var _0x0030=function(_0x2973a7,_0x1fd1e4){_0x2973a7=_0x2973a7-0x0;var _0x162a04=_0x0300[_0x2973a7];return _0x162a04;};'use strict';var _=require('lodash');var md5=require(_0x0030('0x0'));var util=require('util');var Redis=require(_0x0030('0x1'));var config=require('../../../config/environment');config[_0x0030('0x2')]=_[_0x0030('0x3')](config['redis'],{'host':_0x0030('0x4'),'port':0x18eb});var io=require(_0x0030('0x5'))(new Redis(config[_0x0030('0x2')]));function WhatsappQueue(_0x50e943){this['id']=_0x50e943['id']||0x0;this[_0x0030('0x6')]=_0x50e943[_0x0030('0x6')]||'';this[_0x0030('0x7')]=_0x50e943['timeout']||0xa;this[_0x0030('0x8')]=_0x50e943['strategy']||_0x0030('0x9');this['Agents']=_0x50e943[_0x0030('0xa')];this[_0x0030('0xb')]={};this[_0x0030('0xc')]=0x0;this[_0x0030('0x0')]='';this[_0x0030('0xd')]();this[_0x0030('0xe')]();}WhatsappQueue['prototype'][_0x0030('0xd')]=function(){var _0x4d2cd4=this[_0x0030('0xb')][_0x0030('0xf')];this[_0x0030('0xb')]=_[_0x0030('0x10')](this[_0x0030('0xa')],'id');this[_0x0030('0xb')][_0x0030('0xf')]=_0x4d2cd4;};WhatsappQueue[_0x0030('0x11')]['updateRealtime']=function(){this[_0x0030('0x12')]=0x0;this[_0x0030('0x13')]=0x0;for(var _0x16871e=0x0;_0x16871e<this[_0x0030('0xa')][_0x0030('0x14')];_0x16871e+=0x1){if(this[_0x0030('0xa')][_0x16871e][_0x0030('0x15')]){this[_0x0030('0x12')]+=0x1;}if(this['Agents'][_0x16871e][_0x0030('0x16')]){this['paused']+=0x1;}}this[_0x0030('0x17')]=this[_0x0030('0x12')]-this[_0x0030('0x13')];this[_0x0030('0x17')]=this[_0x0030('0x17')]>=0x0?this[_0x0030('0x17')]:0x0;var _0x8ce6fd={'id':this['id'],'available':this[_0x0030('0x17')],'loggedIn':this[_0x0030('0x12')],'name':this[_0x0030('0x6')],'paused':this[_0x0030('0x13')],'waiting':this['waiting']};var _0x588bb3=md5(JSON[_0x0030('0x18')](_0x8ce6fd));if(this[_0x0030('0x0')]!==_0x588bb3){this[_0x0030('0x0')]=_0x588bb3;io['to'](util['format'](_0x0030('0x19'),_0x8ce6fd['name']))[_0x0030('0x1a')](_0x0030('0x1b'),_0x8ce6fd);}};module[_0x0030('0x1c')]=WhatsappQueue;