7c76c6607ba57901d815862a3e203906fd42d242
[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 _0xca23=['md5','defaults','redis','localhost','name','timeout','strategy','beepall','Agents','updateRouting','_rr','mapAgentsId','map','updateRealtime','loggedIn','paused','online','whatsappPause','available','waiting','stringify','format','emit','whatsapp_queue:save'];(function(_0x55c1f0,_0x4f574f){var _0x1530fa=function(_0x631542){while(--_0x631542){_0x55c1f0['push'](_0x55c1f0['shift']());}};_0x1530fa(++_0x4f574f);}(_0xca23,0xa8));var _0x3ca2=function(_0x11005e,_0x20c3d2){_0x11005e=_0x11005e-0x0;var _0x29338f=_0xca23[_0x11005e];return _0x29338f;};'use strict';var _=require('lodash');var md5=require(_0x3ca2('0x0'));var util=require('util');var Redis=require('ioredis');var config=require('../../../config/environment');config['redis']=_[_0x3ca2('0x1')](config[_0x3ca2('0x2')],{'host':_0x3ca2('0x3'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x3ca2('0x2')]));function WhatsappQueue(_0x18431e){this['id']=_0x18431e['id']||0x0;this[_0x3ca2('0x4')]=_0x18431e[_0x3ca2('0x4')]||'';this[_0x3ca2('0x5')]=_0x18431e['timeout']||0xa;this[_0x3ca2('0x6')]=_0x18431e[_0x3ca2('0x6')]||_0x3ca2('0x7');this['Agents']=_0x18431e[_0x3ca2('0x8')];this['mapAgentsId']={};this['waiting']=0x0;this['md5']='';this[_0x3ca2('0x9')]();this['updateRealtime']();}WhatsappQueue['prototype'][_0x3ca2('0x9')]=function(){var _0x10c479=this['mapAgentsId'][_0x3ca2('0xa')];this[_0x3ca2('0xb')]=_[_0x3ca2('0xc')](this['Agents'],'id');this[_0x3ca2('0xb')][_0x3ca2('0xa')]=_0x10c479;};WhatsappQueue['prototype'][_0x3ca2('0xd')]=function(){this[_0x3ca2('0xe')]=0x0;this[_0x3ca2('0xf')]=0x0;for(var _0x4fb22f=0x0;_0x4fb22f<this['Agents']['length'];_0x4fb22f+=0x1){if(this[_0x3ca2('0x8')][_0x4fb22f][_0x3ca2('0x10')]){this['loggedIn']+=0x1;}if(this[_0x3ca2('0x8')][_0x4fb22f][_0x3ca2('0x11')]){this[_0x3ca2('0xf')]+=0x1;}}this[_0x3ca2('0x12')]=this[_0x3ca2('0xe')]-this[_0x3ca2('0xf')];this[_0x3ca2('0x12')]=this[_0x3ca2('0x12')]>=0x0?this[_0x3ca2('0x12')]:0x0;var _0x23c77a={'id':this['id'],'available':this['available'],'loggedIn':this[_0x3ca2('0xe')],'name':this[_0x3ca2('0x4')],'paused':this[_0x3ca2('0xf')],'waiting':this[_0x3ca2('0x13')]};var _0x42fe47=md5(JSON[_0x3ca2('0x14')](_0x23c77a));if(this['md5']!==_0x42fe47){this[_0x3ca2('0x0')]=_0x42fe47;io['to'](util[_0x3ca2('0x15')]('whatsapp:queue:%s',_0x23c77a['name']))[_0x3ca2('0x16')](_0x3ca2('0x17'),_0x23c77a);}};module['exports']=WhatsappQueue;