9c4017c64d31c82af11f1448b12ef00a5e884b18
[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 _0x8abb=['stringify','format','whatsapp:queue:%s','emit','whatsapp_queue:save','lodash','md5','defaults','redis','socket.io-emitter','name','timeout','strategy','Agents','mapAgentsId','waiting','updateRealtime','prototype','updateRouting','map','loggedIn','paused','length','online','available'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x8abb,0x131));var _0xb8ab=function(_0x14ea60,_0x4e1fc0){_0x14ea60=_0x14ea60-0x0;var _0x5f08c0=_0x8abb[_0x14ea60];return _0x5f08c0;};'use strict';var _=require(_0xb8ab('0x0'));var md5=require(_0xb8ab('0x1'));var util=require('util');var Redis=require('ioredis');var config=require('../../../config/environment');config['redis']=_[_0xb8ab('0x2')](config[_0xb8ab('0x3')],{'host':'localhost','port':0x18eb});var io=require(_0xb8ab('0x4'))(new Redis(config['redis']));function WhatsappQueue(_0x36871a){this['id']=_0x36871a['id']||0x0;this[_0xb8ab('0x5')]=_0x36871a[_0xb8ab('0x5')]||'';this[_0xb8ab('0x6')]=_0x36871a[_0xb8ab('0x6')]||0xa;this[_0xb8ab('0x7')]=_0x36871a[_0xb8ab('0x7')]||'beepall';this[_0xb8ab('0x8')]=_0x36871a[_0xb8ab('0x8')];this[_0xb8ab('0x9')]={};this[_0xb8ab('0xa')]=0x0;this[_0xb8ab('0x1')]='';this['updateRouting']();this[_0xb8ab('0xb')]();}WhatsappQueue[_0xb8ab('0xc')][_0xb8ab('0xd')]=function(){var _0x461e73=this[_0xb8ab('0x9')]['_rr'];this[_0xb8ab('0x9')]=_[_0xb8ab('0xe')](this['Agents'],'id');this[_0xb8ab('0x9')]['_rr']=_0x461e73;};WhatsappQueue['prototype'][_0xb8ab('0xb')]=function(){this[_0xb8ab('0xf')]=0x0;this[_0xb8ab('0x10')]=0x0;for(var _0x151331=0x0;_0x151331<this[_0xb8ab('0x8')][_0xb8ab('0x11')];_0x151331+=0x1){if(this['Agents'][_0x151331][_0xb8ab('0x12')]){this['loggedIn']+=0x1;}if(this[_0xb8ab('0x8')][_0x151331]['whatsappPause']){this[_0xb8ab('0x10')]+=0x1;}}this['available']=this[_0xb8ab('0xf')]-this[_0xb8ab('0x10')];this[_0xb8ab('0x13')]=this[_0xb8ab('0x13')]>=0x0?this[_0xb8ab('0x13')]:0x0;var _0x26818e={'id':this['id'],'available':this[_0xb8ab('0x13')],'loggedIn':this[_0xb8ab('0xf')],'name':this[_0xb8ab('0x5')],'paused':this['paused'],'waiting':this[_0xb8ab('0xa')]};var _0x44061c=md5(JSON[_0xb8ab('0x14')](_0x26818e));if(this[_0xb8ab('0x1')]!==_0x44061c){this[_0xb8ab('0x1')]=_0x44061c;io['to'](util[_0xb8ab('0x15')](_0xb8ab('0x16'),_0x26818e[_0xb8ab('0x5')]))[_0xb8ab('0x17')](_0xb8ab('0x18'),_0x26818e);}};module['exports']=WhatsappQueue;