7d636069cdb7ca5bea8d954d3850813c36d89aa8
[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 _0xdfaf=['localhost','name','timeout','strategy','beepall','Agents','waiting','updateRouting','mapAgentsId','_rr','updateRealtime','loggedIn','paused','length','available','stringify','format','emit','whatsapp_queue:save','exports','lodash','md5','util','../../../config/environment','redis','defaults'];(function(_0x1c7a6a,_0x9437c4){var _0x2ba38d=function(_0x406ad9){while(--_0x406ad9){_0x1c7a6a['push'](_0x1c7a6a['shift']());}};_0x2ba38d(++_0x9437c4);}(_0xdfaf,0x132));var _0xfdfa=function(_0x344c22,_0x10c62f){_0x344c22=_0x344c22-0x0;var _0xc4eb4a=_0xdfaf[_0x344c22];return _0xc4eb4a;};'use strict';var _=require(_0xfdfa('0x0'));var md5=require(_0xfdfa('0x1'));var util=require(_0xfdfa('0x2'));var Redis=require('ioredis');var config=require(_0xfdfa('0x3'));config[_0xfdfa('0x4')]=_[_0xfdfa('0x5')](config[_0xfdfa('0x4')],{'host':_0xfdfa('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xfdfa('0x4')]));function WhatsappQueue(_0x1d8944){this['id']=_0x1d8944['id']||0x0;this[_0xfdfa('0x7')]=_0x1d8944['name']||'';this['timeout']=_0x1d8944[_0xfdfa('0x8')]||0xa;this[_0xfdfa('0x9')]=_0x1d8944['strategy']||_0xfdfa('0xa');this['Agents']=_0x1d8944[_0xfdfa('0xb')];this['mapAgentsId']={};this[_0xfdfa('0xc')]=0x0;this[_0xfdfa('0x1')]='';this['updateRouting']();this['updateRealtime']();}WhatsappQueue['prototype'][_0xfdfa('0xd')]=function(){var _0x1b2b51=this[_0xfdfa('0xe')][_0xfdfa('0xf')];this[_0xfdfa('0xe')]=_['map'](this[_0xfdfa('0xb')],'id');this[_0xfdfa('0xe')][_0xfdfa('0xf')]=_0x1b2b51;};WhatsappQueue['prototype'][_0xfdfa('0x10')]=function(){this[_0xfdfa('0x11')]=0x0;this[_0xfdfa('0x12')]=0x0;for(var _0x3badd8=0x0;_0x3badd8<this[_0xfdfa('0xb')][_0xfdfa('0x13')];_0x3badd8+=0x1){if(this['Agents'][_0x3badd8]['online']){this['loggedIn']+=0x1;}if(this['Agents'][_0x3badd8]['whatsappPause']){this[_0xfdfa('0x12')]+=0x1;}}this['available']=this[_0xfdfa('0x11')]-this['paused'];this[_0xfdfa('0x14')]=this[_0xfdfa('0x14')]>=0x0?this['available']:0x0;var _0x13372a={'id':this['id'],'available':this[_0xfdfa('0x14')],'loggedIn':this['loggedIn'],'name':this[_0xfdfa('0x7')],'paused':this[_0xfdfa('0x12')],'waiting':this[_0xfdfa('0xc')]};var _0xb9589=md5(JSON[_0xfdfa('0x15')](_0x13372a));if(this[_0xfdfa('0x1')]!==_0xb9589){this['md5']=_0xb9589;io['to'](util[_0xfdfa('0x16')]('whatsapp:queue:%s',_0x13372a[_0xfdfa('0x7')]))[_0xfdfa('0x17')](_0xfdfa('0x18'),_0x13372a);}};module[_0xfdfa('0x19')]=WhatsappQueue;