01960345663ec0c320cdaeadf2f63f908122e264
[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 _0xb772=['paused','length','online','whatsappPause','available','stringify','format','whatsapp:queue:%s','emit','whatsapp_queue:save','exports','lodash','md5','util','ioredis','../../../config/environment','redis','localhost','name','timeout','strategy','beepall','Agents','waiting','updateRouting','updateRealtime','prototype','mapAgentsId','map','_rr','loggedIn'];(function(_0x32f352,_0xbb3f4f){var _0xd9618e=function(_0x4f558e){while(--_0x4f558e){_0x32f352['push'](_0x32f352['shift']());}};_0xd9618e(++_0xbb3f4f);}(_0xb772,0x141));var _0x2b77=function(_0x95942,_0x85da80){_0x95942=_0x95942-0x0;var _0x6d7f81=_0xb772[_0x95942];return _0x6d7f81;};'use strict';var _=require(_0x2b77('0x0'));var md5=require(_0x2b77('0x1'));var util=require(_0x2b77('0x2'));var Redis=require(_0x2b77('0x3'));var config=require(_0x2b77('0x4'));config[_0x2b77('0x5')]=_['defaults'](config['redis'],{'host':_0x2b77('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x2b77('0x5')]));function WhatsappQueue(_0x119a9a){this['id']=_0x119a9a['id']||0x0;this['name']=_0x119a9a[_0x2b77('0x7')]||'';this['timeout']=_0x119a9a[_0x2b77('0x8')]||0xa;this[_0x2b77('0x9')]=_0x119a9a[_0x2b77('0x9')]||_0x2b77('0xa');this[_0x2b77('0xb')]=_0x119a9a['Agents'];this['mapAgentsId']={};this[_0x2b77('0xc')]=0x0;this['md5']='';this[_0x2b77('0xd')]();this[_0x2b77('0xe')]();}WhatsappQueue[_0x2b77('0xf')]['updateRouting']=function(){var _0x44a3e3=this[_0x2b77('0x10')]['_rr'];this[_0x2b77('0x10')]=_[_0x2b77('0x11')](this['Agents'],'id');this['mapAgentsId'][_0x2b77('0x12')]=_0x44a3e3;};WhatsappQueue['prototype'][_0x2b77('0xe')]=function(){this[_0x2b77('0x13')]=0x0;this[_0x2b77('0x14')]=0x0;for(var _0x58e9e8=0x0;_0x58e9e8<this['Agents'][_0x2b77('0x15')];_0x58e9e8+=0x1){if(this[_0x2b77('0xb')][_0x58e9e8][_0x2b77('0x16')]){this[_0x2b77('0x13')]+=0x1;}if(this[_0x2b77('0xb')][_0x58e9e8][_0x2b77('0x17')]){this[_0x2b77('0x14')]+=0x1;}}this[_0x2b77('0x18')]=this[_0x2b77('0x13')]-this['paused'];this[_0x2b77('0x18')]=this[_0x2b77('0x18')]>=0x0?this[_0x2b77('0x18')]:0x0;var _0x50ed5e={'id':this['id'],'available':this[_0x2b77('0x18')],'loggedIn':this[_0x2b77('0x13')],'name':this[_0x2b77('0x7')],'paused':this[_0x2b77('0x14')],'waiting':this[_0x2b77('0xc')]};var _0x52ded=md5(JSON[_0x2b77('0x19')](_0x50ed5e));if(this[_0x2b77('0x1')]!==_0x52ded){this[_0x2b77('0x1')]=_0x52ded;io['to'](util[_0x2b77('0x1a')](_0x2b77('0x1b'),_0x50ed5e[_0x2b77('0x7')]))[_0x2b77('0x1c')](_0x2b77('0x1d'),_0x50ed5e);}};module[_0x2b77('0x1e')]=WhatsappQueue;