8901119a1bf00ff303ddf8c6dbd2cb9a1d0337d0
[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 _0x8201=['CurrentCapacity','Capacity','toUpperCase','hideNotification','writeLog','lodash','mustache','../../../../../config/environment','routing','redis','localhost','socket.io-emitter','emit','name','user:save','split','notificationSound','notificationShake','body','queue','msg','account','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','format','message','user:%s','notification:%s','save','info','isAgentAvailable','busy','BUSY','PAUSE','hasOwnProperty'];(function(_0x40bdbc,_0x3fabcd){var _0xc603a8=function(_0x17c0e6){while(--_0x17c0e6){_0x40bdbc['push'](_0x40bdbc['shift']());}};_0xc603a8(++_0x3fabcd);}(_0x8201,0x71));var _0x1820=function(_0x205bd2,_0x32b362){_0x205bd2=_0x205bd2-0x0;var _0x249b2f=_0x8201[_0x205bd2];return _0x249b2f;};'use strict';var _=require(_0x1820('0x0'));var util=require('util');var utils=require('../utils');var Mustache=require(_0x1820('0x1'));var Redis=require('ioredis');var config=require(_0x1820('0x2'));var logger=require('../../../../../config/logger')(_0x1820('0x3'));config[_0x1820('0x4')]=_['defaults'](config[_0x1820('0x4')],{'host':_0x1820('0x5'),'port':0x18eb});var io=require(_0x1820('0x6'))(new Redis(config['redis']));function emit(_0x4297b3,_0x1ee24d,_0x5d33c6){io['to'](_0x4297b3)[_0x1820('0x7')](_0x1ee24d,_0x5d33c6);}function sendNotification(_0x395dea,_0xb7aff9,_0x1bccaa,_0x210e2e,_0x2fcd9a,_0x25f597){io['to'](util['format']('user:%s',_0x210e2e[_0x1820('0x8')]))[_0x1820('0x7')](_0x1820('0x9'),_0x210e2e);var _0x4673b7=_0x25f597||{};var _0x21fd6c=_0x1bccaa[_0x1820('0xa')]('.');var _0x118a9e={'uniqueid':_0xb7aff9,'channel':_0x21fd6c[0x0],'id':_0x21fd6c[0x1],'title':_0x21fd6c[0x0]+'\x20interaction','interactionId':_0x21fd6c[0x2],'queue':_0x2fcd9a?_0x2fcd9a['name']:null,'sound':_0x4673b7['account'][_0x1820('0xb')],'shake':_0x4673b7['account'][_0x1820('0xc')]};try{if(!_0x4673b7[_0x1820('0xd')]){_0x4673b7[_0x1820('0xd')]={};}if(_0x2fcd9a){_0x4673b7['body'][_0x1820('0xe')]=_0x2fcd9a;}else if(_0x4673b7['body'][_0x1820('0xe')]){delete _0x4673b7[_0x1820('0xd')][_0x1820('0xe')];}_0x118a9e[_0x1820('0xf')]=utils['getMustacheRender'](_0x4673b7[_0x1820('0x10')][_0x1820('0x11')],_0x4673b7);}catch(_0x5cacf6){_0x118a9e[_0x1820('0xf')]=_0x1820('0x12');logger[_0x1820('0x13')](util[_0x1820('0x14')]('[%s][QUEUE]\x20%s',_0xb7aff9,_0x5cacf6[_0x1820('0x15')]));}io['to'](util[_0x1820('0x14')](_0x1820('0x16'),_0x210e2e[_0x1820('0x8')]))[_0x1820('0x7')](util[_0x1820('0x14')](_0x1820('0x17'),_0x395dea?_0x1820('0x18'):'remove'),_0x118a9e);}function writeLog(_0x14603d,_0xd81af1,_0x22ec43){return logger[_0x1820('0x19')](util['format']('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x14603d,_0xd81af1[_0x1820('0x8')],_0x22ec43));}exports[_0x1820('0x1a')]=function(_0x57e4c7,_0x2a4618,_0x2840b4,_0x3c00d3){if(_0x2a4618[_0x1820('0x1b')]){writeLog(_0x57e4c7,_0x2a4618,_0x1820('0x1c'));return![];}if(!_0x2a4618['online']){writeLog(_0x57e4c7,_0x2a4618,'OFFLINE');return![];}if(_0x2a4618[_0x2840b4+'Pause']){writeLog(_0x57e4c7,_0x2a4618,_0x1820('0x1d'));return![];}if(_0x3c00d3&&_0x2a4618['hasOwnProperty'](_0x2840b4+'Capacity')&&_0x2a4618[_0x1820('0x1e')](_0x2840b4+'CurrentCapacity')){if(_0x2a4618[_0x2840b4+'Capacity']>0x0&&_0x2a4618[_0x2840b4+_0x1820('0x1f')]>=_0x2a4618[_0x2840b4+_0x1820('0x20')]){writeLog(_0x57e4c7,_0x2a4618,_0x2840b4[_0x1820('0x21')]()+'\x20MAXCAPACITY');return![];}}return!![];};exports['showNotification']=function(_0x4f3f6e,_0x4f5405,_0x22eb1a,_0x5e0581,_0x4161b8){return sendNotification(!![],_0x4f3f6e,_0x4f5405,_0x22eb1a,_0x5e0581,_0x4161b8);};exports[_0x1820('0x22')]=function(_0x3d535d,_0x12aa88,_0x1b93f8,_0x2e5ad1,_0x4bce70){return sendNotification(![],_0x3d535d,_0x12aa88,_0x1b93f8,_0x2e5ad1,_0x4bce70);};exports[_0x1820('0x23')]=writeLog;