dd741d5f528a5b7068cab22ad03e40e21743ae69
[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 _0x5471=['defaults','redis','name','timeout','strategy','beepall','Agents','mapAgentsId','updateRealtime','updateRouting','_rr','prototype','loggedIn','paused','length','online','whatsappPause','available','format','whatsapp:queue:%s','exports','md5','util','ioredis'];(function(_0x347c40,_0x7839c4){var _0x52060f=function(_0x33cea3){while(--_0x33cea3){_0x347c40['push'](_0x347c40['shift']());}};_0x52060f(++_0x7839c4);}(_0x5471,0x1c5));var _0x1547=function(_0x154b12,_0x28ce9a){_0x154b12=_0x154b12-0x0;var _0x3d26a9=_0x5471[_0x154b12];return _0x3d26a9;};'use strict';var _=require('lodash');var md5=require(_0x1547('0x0'));var util=require(_0x1547('0x1'));var Redis=require(_0x1547('0x2'));var config=require('../../../config/environment');config['redis']=_[_0x1547('0x3')](config['redis'],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x1547('0x4')]));function WhatsappQueue(_0xdffcb6){this['id']=_0xdffcb6['id']||0x0;this[_0x1547('0x5')]=_0xdffcb6[_0x1547('0x5')]||'';this[_0x1547('0x6')]=_0xdffcb6['timeout']||0xa;this[_0x1547('0x7')]=_0xdffcb6[_0x1547('0x7')]||_0x1547('0x8');this[_0x1547('0x9')]=_0xdffcb6[_0x1547('0x9')];this[_0x1547('0xa')]={};this['waiting']=0x0;this[_0x1547('0x0')]='';this['updateRouting']();this[_0x1547('0xb')]();}WhatsappQueue['prototype'][_0x1547('0xc')]=function(){var _0x558fb7=this[_0x1547('0xa')][_0x1547('0xd')];this['mapAgentsId']=_['map'](this['Agents'],'id');this[_0x1547('0xa')][_0x1547('0xd')]=_0x558fb7;};WhatsappQueue[_0x1547('0xe')][_0x1547('0xb')]=function(){this[_0x1547('0xf')]=0x0;this[_0x1547('0x10')]=0x0;for(var _0x3dd32c=0x0;_0x3dd32c<this[_0x1547('0x9')][_0x1547('0x11')];_0x3dd32c+=0x1){if(this[_0x1547('0x9')][_0x3dd32c][_0x1547('0x12')]){this['loggedIn']+=0x1;}if(this['Agents'][_0x3dd32c][_0x1547('0x13')]){this[_0x1547('0x10')]+=0x1;}}this[_0x1547('0x14')]=this[_0x1547('0xf')]-this[_0x1547('0x10')];this[_0x1547('0x14')]=this['available']>=0x0?this[_0x1547('0x14')]:0x0;var _0x3ae2b8={'id':this['id'],'available':this[_0x1547('0x14')],'loggedIn':this[_0x1547('0xf')],'name':this[_0x1547('0x5')],'paused':this[_0x1547('0x10')],'waiting':this['waiting']};var _0x18aad6=md5(JSON['stringify'](_0x3ae2b8));if(this['md5']!==_0x18aad6){this[_0x1547('0x0')]=_0x18aad6;io['to'](util[_0x1547('0x15')](_0x1547('0x16'),_0x3ae2b8[_0x1547('0x5')]))['emit']('whatsapp_queue:save',_0x3ae2b8);}};module[_0x1547('0x17')]=WhatsappQueue;