Built motion from commit 53172ac8.|2.6.30
[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 _0xd6a3=['strategy','beepall','Agents','mapAgentsId','waiting','updateRealtime','_rr','map','loggedIn','paused','online','available','whatsapp:queue:%s','emit','whatsapp_queue:save','md5','util','../../../config/environment','redis','localhost','socket.io-emitter','name','timeout'];(function(_0x27c068,_0x342981){var _0xe5a67f=function(_0x20658a){while(--_0x20658a){_0x27c068['push'](_0x27c068['shift']());}};_0xe5a67f(++_0x342981);}(_0xd6a3,0x17f));var _0x3d6a=function(_0x299df2,_0x44f255){_0x299df2=_0x299df2-0x0;var _0x5bb6cc=_0xd6a3[_0x299df2];return _0x5bb6cc;};'use strict';var _=require('lodash');var md5=require(_0x3d6a('0x0'));var util=require(_0x3d6a('0x1'));var Redis=require('ioredis');var config=require(_0x3d6a('0x2'));config[_0x3d6a('0x3')]=_['defaults'](config[_0x3d6a('0x3')],{'host':_0x3d6a('0x4'),'port':0x18eb});var io=require(_0x3d6a('0x5'))(new Redis(config['redis']));function WhatsappQueue(_0x1ca436){this['id']=_0x1ca436['id']||0x0;this[_0x3d6a('0x6')]=_0x1ca436[_0x3d6a('0x6')]||'';this['timeout']=_0x1ca436[_0x3d6a('0x7')]||0xa;this[_0x3d6a('0x8')]=_0x1ca436['strategy']||_0x3d6a('0x9');this[_0x3d6a('0xa')]=_0x1ca436[_0x3d6a('0xa')];this[_0x3d6a('0xb')]={};this[_0x3d6a('0xc')]=0x0;this[_0x3d6a('0x0')]='';this['updateRouting']();this[_0x3d6a('0xd')]();}WhatsappQueue['prototype']['updateRouting']=function(){var _0x285251=this['mapAgentsId'][_0x3d6a('0xe')];this[_0x3d6a('0xb')]=_[_0x3d6a('0xf')](this[_0x3d6a('0xa')],'id');this[_0x3d6a('0xb')][_0x3d6a('0xe')]=_0x285251;};WhatsappQueue['prototype'][_0x3d6a('0xd')]=function(){this[_0x3d6a('0x10')]=0x0;this[_0x3d6a('0x11')]=0x0;for(var _0x25b214=0x0;_0x25b214<this[_0x3d6a('0xa')]['length'];_0x25b214+=0x1){if(this['Agents'][_0x25b214][_0x3d6a('0x12')]){this['loggedIn']+=0x1;}if(this['Agents'][_0x25b214]['whatsappPause']){this[_0x3d6a('0x11')]+=0x1;}}this[_0x3d6a('0x13')]=this['loggedIn']-this[_0x3d6a('0x11')];this[_0x3d6a('0x13')]=this[_0x3d6a('0x13')]>=0x0?this['available']:0x0;var _0x256bcb={'id':this['id'],'available':this[_0x3d6a('0x13')],'loggedIn':this[_0x3d6a('0x10')],'name':this[_0x3d6a('0x6')],'paused':this[_0x3d6a('0x11')],'waiting':this[_0x3d6a('0xc')]};var _0xaef31f=md5(JSON['stringify'](_0x256bcb));if(this[_0x3d6a('0x0')]!==_0xaef31f){this['md5']=_0xaef31f;io['to'](util['format'](_0x3d6a('0x14'),_0x256bcb[_0x3d6a('0x6')]))[_0x3d6a('0x15')](_0x3d6a('0x16'),_0x256bcb);}};module['exports']=WhatsappQueue;