748d3c7f1458ad337087a556dfeb162b93fe0083
[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 _0xf26c=['md5','util','ioredis','redis','defaults','socket.io-emitter','name','timeout','strategy','beepall','Agents','mapAgentsId','updateRouting','prototype','_rr','map','updateRealtime','loggedIn','paused','length','online','available','stringify'];(function(_0x33155c,_0x3fdde1){var _0x5becf7=function(_0x2f7a2f){while(--_0x2f7a2f){_0x33155c['push'](_0x33155c['shift']());}};_0x5becf7(++_0x3fdde1);}(_0xf26c,0x1cc));var _0xcf26=function(_0x4b4529,_0x2169ff){_0x4b4529=_0x4b4529-0x0;var _0x2f99c9=_0xf26c[_0x4b4529];return _0x2f99c9;};'use strict';var _=require('lodash');var md5=require(_0xcf26('0x0'));var util=require(_0xcf26('0x1'));var Redis=require(_0xcf26('0x2'));var config=require('../../../config/environment');config[_0xcf26('0x3')]=_[_0xcf26('0x4')](config[_0xcf26('0x3')],{'host':'localhost','port':0x18eb});var io=require(_0xcf26('0x5'))(new Redis(config[_0xcf26('0x3')]));function WhatsappQueue(_0x227035){this['id']=_0x227035['id']||0x0;this[_0xcf26('0x6')]=_0x227035['name']||'';this[_0xcf26('0x7')]=_0x227035[_0xcf26('0x7')]||0xa;this[_0xcf26('0x8')]=_0x227035['strategy']||_0xcf26('0x9');this[_0xcf26('0xa')]=_0x227035['Agents'];this[_0xcf26('0xb')]={};this['waiting']=0x0;this[_0xcf26('0x0')]='';this[_0xcf26('0xc')]();this['updateRealtime']();}WhatsappQueue[_0xcf26('0xd')][_0xcf26('0xc')]=function(){var _0x29d700=this[_0xcf26('0xb')][_0xcf26('0xe')];this[_0xcf26('0xb')]=_[_0xcf26('0xf')](this[_0xcf26('0xa')],'id');this[_0xcf26('0xb')]['_rr']=_0x29d700;};WhatsappQueue[_0xcf26('0xd')][_0xcf26('0x10')]=function(){this[_0xcf26('0x11')]=0x0;this[_0xcf26('0x12')]=0x0;for(var _0x165afa=0x0;_0x165afa<this[_0xcf26('0xa')][_0xcf26('0x13')];_0x165afa+=0x1){if(this[_0xcf26('0xa')][_0x165afa][_0xcf26('0x14')]){this[_0xcf26('0x11')]+=0x1;}if(this[_0xcf26('0xa')][_0x165afa]['whatsappPause']){this[_0xcf26('0x12')]+=0x1;}}this[_0xcf26('0x15')]=this['loggedIn']-this[_0xcf26('0x12')];this[_0xcf26('0x15')]=this[_0xcf26('0x15')]>=0x0?this['available']:0x0;var _0x27853e={'id':this['id'],'available':this[_0xcf26('0x15')],'loggedIn':this[_0xcf26('0x11')],'name':this[_0xcf26('0x6')],'paused':this[_0xcf26('0x12')],'waiting':this['waiting']};var _0x2731d=md5(JSON[_0xcf26('0x16')](_0x27853e));if(this[_0xcf26('0x0')]!==_0x2731d){this[_0xcf26('0x0')]=_0x2731d;io['to'](util['format']('whatsapp:queue:%s',_0x27853e[_0xcf26('0x6')]))['emit']('whatsapp_queue:save',_0x27853e);}};module['exports']=WhatsappQueue;