6a7fc0ff31aab08e696de162eeff578dedd519d3
[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 _0x99ba=['updateRouting','prototype','map','_rr','updateRealtime','loggedIn','length','online','whatsappPause','paused','available','waiting','stringify','format','whatsapp:queue:%s','emit','whatsapp_queue:save','exports','lodash','md5','ioredis','redis','defaults','localhost','name','timeout','strategy','beepall','Agents','mapAgentsId'];(function(_0xc22b0a,_0x13910e){var _0xc5ffc9=function(_0x381990){while(--_0x381990){_0xc22b0a['push'](_0xc22b0a['shift']());}};_0xc5ffc9(++_0x13910e);}(_0x99ba,0x198));var _0xa99b=function(_0xc083f3,_0x5eaa52){_0xc083f3=_0xc083f3-0x0;var _0x3c7c01=_0x99ba[_0xc083f3];return _0x3c7c01;};'use strict';var _=require(_0xa99b('0x0'));var md5=require(_0xa99b('0x1'));var util=require('util');var Redis=require(_0xa99b('0x2'));var config=require('../../../config/environment');config[_0xa99b('0x3')]=_[_0xa99b('0x4')](config[_0xa99b('0x3')],{'host':_0xa99b('0x5'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xa99b('0x3')]));function WhatsappQueue(_0x44c5ca){this['id']=_0x44c5ca['id']||0x0;this[_0xa99b('0x6')]=_0x44c5ca[_0xa99b('0x6')]||'';this[_0xa99b('0x7')]=_0x44c5ca[_0xa99b('0x7')]||0xa;this['strategy']=_0x44c5ca[_0xa99b('0x8')]||_0xa99b('0x9');this[_0xa99b('0xa')]=_0x44c5ca['Agents'];this[_0xa99b('0xb')]={};this['waiting']=0x0;this[_0xa99b('0x1')]='';this[_0xa99b('0xc')]();this['updateRealtime']();}WhatsappQueue[_0xa99b('0xd')][_0xa99b('0xc')]=function(){var _0x4955f2=this[_0xa99b('0xb')]['_rr'];this[_0xa99b('0xb')]=_[_0xa99b('0xe')](this['Agents'],'id');this['mapAgentsId'][_0xa99b('0xf')]=_0x4955f2;};WhatsappQueue[_0xa99b('0xd')][_0xa99b('0x10')]=function(){this[_0xa99b('0x11')]=0x0;this['paused']=0x0;for(var _0x412850=0x0;_0x412850<this[_0xa99b('0xa')][_0xa99b('0x12')];_0x412850+=0x1){if(this[_0xa99b('0xa')][_0x412850][_0xa99b('0x13')]){this[_0xa99b('0x11')]+=0x1;}if(this[_0xa99b('0xa')][_0x412850][_0xa99b('0x14')]){this[_0xa99b('0x15')]+=0x1;}}this[_0xa99b('0x16')]=this['loggedIn']-this[_0xa99b('0x15')];this['available']=this[_0xa99b('0x16')]>=0x0?this['available']:0x0;var _0x19a587={'id':this['id'],'available':this[_0xa99b('0x16')],'loggedIn':this[_0xa99b('0x11')],'name':this['name'],'paused':this['paused'],'waiting':this[_0xa99b('0x17')]};var _0x20929f=md5(JSON[_0xa99b('0x18')](_0x19a587));if(this[_0xa99b('0x1')]!==_0x20929f){this[_0xa99b('0x1')]=_0x20929f;io['to'](util[_0xa99b('0x19')](_0xa99b('0x1a'),_0x19a587['name']))[_0xa99b('0x1b')](_0xa99b('0x1c'),_0x19a587);}};module[_0xa99b('0x1d')]=WhatsappQueue;