353bc9e278c8d0c032c69637f4d43d2bab02aaf8
[motion2.git] / server / services / routing / server / applications / strategy / util.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 _0x8f9a=['capitalize','InteractionId','WaitingInteractions','agents','removeWaitingNotification','writeLog','lodash','util','../utils','../../../../../config/environment','routing','defaults','redis','localhost','socket.io-emitter','format','user:%s','user:save','\x20interaction','name','account','notificationSound','notificationShake','body','queue','getMustacheRender','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','message','emit','notification:%s','save','[%s][QUEUE][AGENT:%s][STATUS:%s]','online','OFFLINE','PAUSE','hasOwnProperty','Capacity','\x20MAXCAPACITY','showNotification','hideNotification','interaction','UserId','some','channel','QueuesWaitingInteractions'];(function(_0x2c1c8,_0x4a52b0){var _0x495de6=function(_0x44c5cc){while(--_0x44c5cc){_0x2c1c8['push'](_0x2c1c8['shift']());}};_0x495de6(++_0x4a52b0);}(_0x8f9a,0x176));var _0xa8f9=function(_0x5207d3,_0x1b67d4){_0x5207d3=_0x5207d3-0x0;var _0x36785c=_0x8f9a[_0x5207d3];return _0x36785c;};'use strict';var _=require(_0xa8f9('0x0'));var util=require(_0xa8f9('0x1'));var utils=require(_0xa8f9('0x2'));var Redis=require('ioredis');var config=require(_0xa8f9('0x3'));var logger=require('../../../../../config/logger')(_0xa8f9('0x4'));config['redis']=_[_0xa8f9('0x5')](config[_0xa8f9('0x6')],{'host':_0xa8f9('0x7'),'port':0x18eb});var io=require(_0xa8f9('0x8'))(new Redis(config['redis']));function sendNotification(_0x4cb21b,_0x4a3039,_0x269b2d,_0x9ecafc,_0x7da7d1,_0x1c0d33){io['to'](util[_0xa8f9('0x9')](_0xa8f9('0xa'),_0x9ecafc['name']))['emit'](_0xa8f9('0xb'),_0x9ecafc);var _0x35d272=_0x1c0d33||{};var _0x1239b9=_0x269b2d['split']('.');var _0x32ce62={'uniqueid':_0x4a3039,'channel':_0x1239b9[0x0],'id':_0x1239b9[0x1],'title':_0x1239b9[0x0]+_0xa8f9('0xc'),'interactionId':_0x1239b9[0x2],'queue':_0x7da7d1?_0x7da7d1[_0xa8f9('0xd')]:null,'sound':_0x35d272[_0xa8f9('0xe')][_0xa8f9('0xf')],'shake':_0x35d272[_0xa8f9('0xe')][_0xa8f9('0x10')]};try{if(!_0x35d272[_0xa8f9('0x11')]){_0x35d272[_0xa8f9('0x11')]={};}if(_0x7da7d1){_0x35d272[_0xa8f9('0x11')][_0xa8f9('0x12')]=_0x7da7d1;}else if(_0x35d272[_0xa8f9('0x11')]['queue']){delete _0x35d272[_0xa8f9('0x11')][_0xa8f9('0x12')];}_0x32ce62['msg']=utils[_0xa8f9('0x13')](_0x35d272[_0xa8f9('0xe')][_0xa8f9('0x14')],_0x35d272);}catch(_0x30c0bd){_0x32ce62['msg']=_0xa8f9('0x15');logger['error'](util[_0xa8f9('0x9')]('[%s][QUEUE]\x20%s',_0x4a3039,_0x30c0bd[_0xa8f9('0x16')]));}io['to'](util['format']('user:%s',_0x9ecafc[_0xa8f9('0xd')]))[_0xa8f9('0x17')](util[_0xa8f9('0x9')](_0xa8f9('0x18'),_0x4cb21b?_0xa8f9('0x19'):'remove'),_0x32ce62);}function writeLog(_0x511d30,_0xeca131,_0x3f3c73){return logger['debug'](util[_0xa8f9('0x9')](_0xa8f9('0x1a'),_0x511d30,_0xeca131['name'],_0x3f3c73));}exports['isAgentAvailable']=function(_0x1222b3,_0x788c33,_0x5f2655,_0x28c670){if(_0x788c33['busy']){writeLog(_0x1222b3,_0x788c33,'BUSY');return![];}if(!_0x788c33[_0xa8f9('0x1b')]){writeLog(_0x1222b3,_0x788c33,_0xa8f9('0x1c'));return![];}if(_0x788c33[_0x5f2655+'Pause']){writeLog(_0x1222b3,_0x788c33,_0xa8f9('0x1d'));return![];}if(_0x28c670&&_0x788c33['hasOwnProperty'](_0x5f2655+'Capacity')&&_0x788c33[_0xa8f9('0x1e')](_0x5f2655+'CurrentCapacity')){if(_0x788c33[_0x5f2655+_0xa8f9('0x1f')]>0x0&&_0x788c33[_0x5f2655+'CurrentCapacity']>=_0x788c33[_0x5f2655+_0xa8f9('0x1f')]){writeLog(_0x1222b3,_0x788c33,_0x5f2655['toUpperCase']()+_0xa8f9('0x20'));return![];}}return!![];};exports[_0xa8f9('0x21')]=function(_0x226cc5,_0xd2f296,_0x18a468,_0x31fc07,_0x303f7e){return sendNotification(!![],_0x226cc5,_0xd2f296,_0x18a468,_0x31fc07,_0x303f7e);};exports[_0xa8f9('0x22')]=function(_0x2cedcb,_0x5be5d8,_0x5790a3,_0x13b504,_0x4831b5){return sendNotification(![],_0x2cedcb,_0x5be5d8,_0x5790a3,_0x13b504,_0x4831b5);};exports['checkWaitingNotifications']=function(_0x1f08d0,_0x58d205,_0x169f49){var _0x1416fa=_0x58d205[_0xa8f9('0x23')][_0xa8f9('0x24')];if(!_0x1416fa&&_0x169f49){_0x1416fa=_0x169f49['id'];}var _0x28df47=_[_0xa8f9('0x25')](_0x1f08d0[_0x58d205[_0xa8f9('0x26')]+_0xa8f9('0x27')],function(_0x381ad1){var _0x49212b=_[_0xa8f9('0x28')](_0x58d205[_0xa8f9('0x26')])+_0xa8f9('0x29');return _0x381ad1[_0x49212b]===_0x58d205['interaction']['id'];});if(!_0x28df47&&_0x1416fa){_0x28df47=_[_0xa8f9('0x25')](_0x1f08d0['agents'][_0x1416fa][_0x58d205['channel']+_0xa8f9('0x2a')],function(_0x1a2c24){return _0x1a2c24['id']===_0x58d205[_0xa8f9('0x23')]['id'];});}return _0x28df47;};exports['saveWaitingNotification']=function(_0x2a3226,_0xd17255,_0x56127a,_0xea195e){_0x2a3226[_0xa8f9('0x2b')][_0x56127a['id']][_0xea195e+_0xa8f9('0x2a')][_0xd17255[_0xa8f9('0x16')]['id']]={'id':_0xd17255['interaction']['id']};};exports[_0xa8f9('0x2c')]=function(_0x2b53ef,_0x558752,_0x48b350,_0x488776){delete _0x2b53ef[_0xa8f9('0x2b')][_0x48b350['id']][_0x488776+'WaitingInteractions'][_0x558752[_0xa8f9('0x16')]['id']];};exports[_0xa8f9('0x2d')]=writeLog;