436e0490423bc4287b24ecf58a89ee597c26716c
[motion2.git] / server / services / routing / model / smsQueue.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 _0x37dc=['paused','length','available','stringify','sms:queue:%s','sms_queue:save','lodash','md5','util','ioredis','redis','name','timeout','strategy','beepall','Agents','waiting','updateRealtime','prototype','mapAgentsId','map','_rr','loggedIn'];(function(_0x38d499,_0x1cbb6b){var _0x274b18=function(_0x488d64){while(--_0x488d64){_0x38d499['push'](_0x38d499['shift']());}};_0x274b18(++_0x1cbb6b);}(_0x37dc,0x1e9));var _0xc37d=function(_0x15994b,_0x9e5cca){_0x15994b=_0x15994b-0x0;var _0x479bdf=_0x37dc[_0x15994b];return _0x479bdf;};'use strict';var _=require(_0xc37d('0x0'));var md5=require(_0xc37d('0x1'));var util=require(_0xc37d('0x2'));var Redis=require(_0xc37d('0x3'));var config=require('../../../config/environment');config[_0xc37d('0x4')]=_['defaults'](config[_0xc37d('0x4')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function SmsQueue(_0x4eabf9){this['id']=_0x4eabf9['id']||0x0;this[_0xc37d('0x5')]=_0x4eabf9[_0xc37d('0x5')]||'';this[_0xc37d('0x6')]=_0x4eabf9[_0xc37d('0x6')]||0xa;this[_0xc37d('0x7')]=_0x4eabf9[_0xc37d('0x7')]||_0xc37d('0x8');this[_0xc37d('0x9')]=_0x4eabf9[_0xc37d('0x9')];this['mapAgentsId']={};this[_0xc37d('0xa')]=0x0;this[_0xc37d('0x1')]='';this['updateRouting']();this[_0xc37d('0xb')]();}SmsQueue[_0xc37d('0xc')]['updateRouting']=function(){var _0x11f35f=this[_0xc37d('0xd')]['_rr'];this[_0xc37d('0xd')]=_[_0xc37d('0xe')](this[_0xc37d('0x9')],'id');this[_0xc37d('0xd')][_0xc37d('0xf')]=_0x11f35f;};SmsQueue[_0xc37d('0xc')][_0xc37d('0xb')]=function(){this[_0xc37d('0x10')]=0x0;this[_0xc37d('0x11')]=0x0;for(var _0x39aab8=0x0;_0x39aab8<this[_0xc37d('0x9')][_0xc37d('0x12')];_0x39aab8+=0x1){if(this['Agents'][_0x39aab8]['online']){this[_0xc37d('0x10')]+=0x1;}if(this['Agents'][_0x39aab8]['smsPause']){this[_0xc37d('0x11')]+=0x1;}}this[_0xc37d('0x13')]=this['loggedIn']-this[_0xc37d('0x11')];this['available']=this['available']>=0x0?this[_0xc37d('0x13')]:0x0;var _0x1816f4={'id':this['id'],'available':this[_0xc37d('0x13')],'loggedIn':this[_0xc37d('0x10')],'name':this[_0xc37d('0x5')],'paused':this[_0xc37d('0x11')],'waiting':this['waiting']};var _0x5dbbb1=md5(JSON[_0xc37d('0x14')](_0x1816f4));if(this[_0xc37d('0x1')]!==_0x5dbbb1){this[_0xc37d('0x1')]=_0x5dbbb1;io['to'](util['format'](_0xc37d('0x15'),_0x1816f4[_0xc37d('0x5')]))['emit'](_0xc37d('0x16'),_0x1816f4);}};module['exports']=SmsQueue;