cb5259a2df8c0f51f9c3d330b2ae72c8e07c869b
[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 _0xa9e8=['[%s][QUEUE]\x20%s','message','remove','info','[%s][QUEUE][AGENT:%s][STATUS:%s]','busy','OFFLINE','PAUSE','Capacity','CurrentCapacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','writeLog','lodash','util','../utils','ioredis','routing','localhost','socket.io-emitter','redis','emit','name','user:save','split','\x20interaction','account','body','queue','msg','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','format'];(function(_0x4dcb2c,_0x3ebb29){var _0x98f5d=function(_0x565eaa){while(--_0x565eaa){_0x4dcb2c['push'](_0x4dcb2c['shift']());}};_0x98f5d(++_0x3ebb29);}(_0xa9e8,0x78));var _0x8a9e=function(_0x5edca9,_0x1bb3af){_0x5edca9=_0x5edca9-0x0;var _0x9610ba=_0xa9e8[_0x5edca9];return _0x9610ba;};'use strict';var _=require(_0x8a9e('0x0'));var util=require(_0x8a9e('0x1'));var utils=require(_0x8a9e('0x2'));var Mustache=require('mustache');var Redis=require(_0x8a9e('0x3'));var config=require('../../../../../config/environment');var logger=require('../../../../../config/logger')(_0x8a9e('0x4'));config['redis']=_['defaults'](config['redis'],{'host':_0x8a9e('0x5'),'port':0x18eb});var io=require(_0x8a9e('0x6'))(new Redis(config[_0x8a9e('0x7')]));function emit(_0x254f8a,_0x55b987,_0x43835c){io['to'](_0x254f8a)[_0x8a9e('0x8')](_0x55b987,_0x43835c);}function sendNotification(_0x5211f0,_0x1968e8,_0x128f53,_0x43342d,_0x5913fe,_0x6bc2fe){io['to'](util['format']('user:%s',_0x43342d[_0x8a9e('0x9')]))[_0x8a9e('0x8')](_0x8a9e('0xa'),_0x43342d);var _0x17d22d=_0x6bc2fe||{};var _0xa89490=_0x128f53[_0x8a9e('0xb')]('.');var _0x2cc223={'uniqueid':_0x1968e8,'channel':_0xa89490[0x0],'id':_0xa89490[0x1],'title':_0xa89490[0x0]+_0x8a9e('0xc'),'interactionId':_0xa89490[0x2],'queue':_0x5913fe?_0x5913fe[_0x8a9e('0x9')]:null,'sound':_0x17d22d[_0x8a9e('0xd')]['notificationSound'],'shake':_0x17d22d[_0x8a9e('0xd')]['notificationShake']};try{if(!_0x17d22d[_0x8a9e('0xe')]){_0x17d22d[_0x8a9e('0xe')]={};}if(_0x5913fe){_0x17d22d[_0x8a9e('0xe')][_0x8a9e('0xf')]=_0x5913fe;}else if(_0x17d22d['body']['queue']){delete _0x17d22d[_0x8a9e('0xe')][_0x8a9e('0xf')];}_0x2cc223[_0x8a9e('0x10')]=utils['getMustacheRender'](_0x17d22d[_0x8a9e('0xd')][_0x8a9e('0x11')],_0x17d22d);}catch(_0xe84bf9){_0x2cc223[_0x8a9e('0x10')]=_0x8a9e('0x12');logger['error'](util[_0x8a9e('0x13')](_0x8a9e('0x14'),_0x1968e8,_0xe84bf9[_0x8a9e('0x15')]));}io['to'](util[_0x8a9e('0x13')]('user:%s',_0x43342d['name']))[_0x8a9e('0x8')](util[_0x8a9e('0x13')]('notification:%s',_0x5211f0?'save':_0x8a9e('0x16')),_0x2cc223);}function writeLog(_0x1aec7d,_0x5ac1e2,_0x347edf){return logger[_0x8a9e('0x17')](util[_0x8a9e('0x13')](_0x8a9e('0x18'),_0x1aec7d,_0x5ac1e2[_0x8a9e('0x9')],_0x347edf));}exports['isAgentAvailable']=function(_0x567433,_0xc0b2e7,_0x14c152,_0x3e3f5c){if(_0xc0b2e7[_0x8a9e('0x19')]){writeLog(_0x567433,_0xc0b2e7,'BUSY');return![];}if(!_0xc0b2e7['online']){writeLog(_0x567433,_0xc0b2e7,_0x8a9e('0x1a'));return![];}if(_0xc0b2e7[_0x14c152+'Pause']){writeLog(_0x567433,_0xc0b2e7,_0x8a9e('0x1b'));return![];}if(_0x3e3f5c&&_0xc0b2e7['hasOwnProperty'](_0x14c152+_0x8a9e('0x1c'))&&_0xc0b2e7['hasOwnProperty'](_0x14c152+'CurrentCapacity')){if(_0xc0b2e7[_0x14c152+_0x8a9e('0x1c')]>0x0&&_0xc0b2e7[_0x14c152+_0x8a9e('0x1d')]>=_0xc0b2e7[_0x14c152+_0x8a9e('0x1c')]){writeLog(_0x567433,_0xc0b2e7,_0x14c152[_0x8a9e('0x1e')]()+_0x8a9e('0x1f'));return![];}}return!![];};exports[_0x8a9e('0x20')]=function(_0x4a0537,_0x4fc9cf,_0x221d83,_0x5be809,_0x58e76e){return sendNotification(!![],_0x4a0537,_0x4fc9cf,_0x221d83,_0x5be809,_0x58e76e);};exports[_0x8a9e('0x21')]=function(_0x118742,_0x422fd1,_0x2d1382,_0x23369c,_0x1fc495){return sendNotification(![],_0x118742,_0x422fd1,_0x2d1382,_0x23369c,_0x1fc495);};exports[_0x8a9e('0x22')]=writeLog;