cc6dd7f1aeaca151bbb4114c1d08098817e3e270
[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 _0xd0bb=['toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','some','channel','QueuesWaitingInteractions','capitalize','InteractionId','agents','WaitingInteractions','message','writeLog','lodash','util','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','redis','defaults','socket.io-emitter','\x20interaction','name','account','notificationSound','body','queue','msg','getMustacheRender','error','format','[%s][QUEUE]\x20%s','user:%s','emit','notification:%s','save','remove','[%s][QUEUE][AGENT:%s][STATUS:%s]','busy','BUSY','online','OFFLINE','Pause','PAUSE','hasOwnProperty','CurrentCapacity','Capacity'];(function(_0x1f1f31,_0x16ab7d){var _0x1cd1bf=function(_0x2269ff){while(--_0x2269ff){_0x1f1f31['push'](_0x1f1f31['shift']());}};_0x1cd1bf(++_0x16ab7d);}(_0xd0bb,0x1a8));var _0xbd0b=function(_0x73740d,_0x49a324){_0x73740d=_0x73740d-0x0;var _0x3eecfe=_0xd0bb[_0x73740d];return _0x3eecfe;};'use strict';var _=require(_0xbd0b('0x0'));var util=require(_0xbd0b('0x1'));var utils=require(_0xbd0b('0x2'));var Redis=require(_0xbd0b('0x3'));var config=require(_0xbd0b('0x4'));var logger=require(_0xbd0b('0x5'))('routing');config[_0xbd0b('0x6')]=_[_0xbd0b('0x7')](config[_0xbd0b('0x6')],{'host':'localhost','port':0x18eb});var io=require(_0xbd0b('0x8'))(new Redis(config['redis']));function sendNotification(_0x1828d1,_0x3876bc,_0x507731,_0x342a8c,_0x3f5762,_0x552636){var _0x200ecb=_0x552636||{};var _0x2f14d5=_0x507731['split']('.');var _0x348e1b={'uniqueid':_0x3876bc,'channel':_0x2f14d5[0x0],'id':_0x2f14d5[0x1],'title':_0x2f14d5[0x0]+_0xbd0b('0x9'),'interactionId':_0x2f14d5[0x2],'queue':_0x3f5762?_0x3f5762[_0xbd0b('0xa')]:null,'sound':_0x200ecb[_0xbd0b('0xb')][_0xbd0b('0xc')],'shake':_0x200ecb['account']['notificationShake']};try{if(!_0x200ecb['body']){_0x200ecb[_0xbd0b('0xd')]={};}if(_0x3f5762){_0x200ecb[_0xbd0b('0xd')][_0xbd0b('0xe')]=_0x3f5762;}else if(_0x200ecb[_0xbd0b('0xd')][_0xbd0b('0xe')]){delete _0x200ecb[_0xbd0b('0xd')][_0xbd0b('0xe')];}_0x348e1b[_0xbd0b('0xf')]=utils[_0xbd0b('0x10')](_0x200ecb[_0xbd0b('0xb')]['notificationTemplate'],_0x200ecb);}catch(_0x9ee0db){_0x348e1b[_0xbd0b('0xf')]='I\x20can\x27t\x20render\x20your\x20template';logger[_0xbd0b('0x11')](util[_0xbd0b('0x12')](_0xbd0b('0x13'),_0x3876bc,_0x9ee0db['message']));}io['to'](util[_0xbd0b('0x12')](_0xbd0b('0x14'),_0x342a8c[_0xbd0b('0xa')]))[_0xbd0b('0x15')](util[_0xbd0b('0x12')](_0xbd0b('0x16'),_0x1828d1?_0xbd0b('0x17'):_0xbd0b('0x18')),_0x348e1b);}function writeLog(_0x8b86d1,_0x1b0050,_0x4a8b8a){return logger['debug'](util['format'](_0xbd0b('0x19'),_0x8b86d1,_0x1b0050[_0xbd0b('0xa')],_0x4a8b8a));}exports['isAgentAvailable']=function(_0x358e4d,_0xfa7194,_0xaac9af,_0x2e5c45){if(_0xfa7194[_0xbd0b('0x1a')]){writeLog(_0x358e4d,_0xfa7194,_0xbd0b('0x1b'));return![];}if(!_0xfa7194[_0xbd0b('0x1c')]){writeLog(_0x358e4d,_0xfa7194,_0xbd0b('0x1d'));return![];}if(_0xfa7194[_0xaac9af+_0xbd0b('0x1e')]){writeLog(_0x358e4d,_0xfa7194,_0xbd0b('0x1f'));return![];}if(_0x2e5c45&&_0xfa7194[_0xbd0b('0x20')](_0xaac9af+'Capacity')&&_0xfa7194['hasOwnProperty'](_0xaac9af+_0xbd0b('0x21'))){if(_0xfa7194[_0xaac9af+_0xbd0b('0x22')]>0x0&&_0xfa7194[_0xaac9af+_0xbd0b('0x21')]>=_0xfa7194[_0xaac9af+'Capacity']){writeLog(_0x358e4d,_0xfa7194,_0xaac9af[_0xbd0b('0x23')]()+_0xbd0b('0x24'));return![];}}return!![];};exports[_0xbd0b('0x25')]=function(_0xd88c1d,_0xcc0e63,_0x4449c9,_0x511c6d,_0x1295dc){return sendNotification(!![],_0xd88c1d,_0xcc0e63,_0x4449c9,_0x511c6d,_0x1295dc);};exports[_0xbd0b('0x26')]=function(_0x18a7bf,_0xa8fd02,_0x36200c,_0x7df2f9,_0x41ad46){return sendNotification(![],_0x18a7bf,_0xa8fd02,_0x36200c,_0x7df2f9,_0x41ad46);};exports[_0xbd0b('0x27')]=function(_0x1e46c9,_0x5a861f,_0x30b000){var _0x313466=_0x5a861f[_0xbd0b('0x28')][_0xbd0b('0x29')];if(!_0x313466&&_0x30b000){_0x313466=_0x30b000['id'];}var _0x14d3c1=_[_0xbd0b('0x2a')](_0x1e46c9[_0x5a861f[_0xbd0b('0x2b')]+_0xbd0b('0x2c')],function(_0x509979){var _0xb03fb2=_[_0xbd0b('0x2d')](_0x5a861f[_0xbd0b('0x2b')])+_0xbd0b('0x2e');return _0x509979[_0xb03fb2]===_0x5a861f[_0xbd0b('0x28')]['id'];});if(!_0x14d3c1&&_0x313466&&_0x1e46c9[_0xbd0b('0x2f')][_0x313466]){_0x14d3c1=_['some'](_0x1e46c9[_0xbd0b('0x2f')][_0x313466][_0x5a861f[_0xbd0b('0x2b')]+'WaitingInteractions'],function(_0x151d76){return _0x151d76['id']===_0x5a861f['interaction']['id'];});}return _0x14d3c1;};exports['saveWaitingNotification']=function(_0x156a75,_0x296b32,_0x4a6bbe,_0x7368b7){if(_0x4a6bbe&&_0x4a6bbe['id']&&_0x156a75['agents']&&_0x156a75[_0xbd0b('0x2f')][_0x4a6bbe['id']]){_0x156a75[_0xbd0b('0x2f')][_0x4a6bbe['id']][_0x7368b7+_0xbd0b('0x30')][_0x296b32[_0xbd0b('0x31')]['id']]={'id':_0x296b32[_0xbd0b('0x28')]['id']};}};exports['removeWaitingNotification']=function(_0x3ebedf,_0x1e947b,_0x193cd6,_0x29a226){if(_0x193cd6&&_0x193cd6['id']&&_0x3ebedf[_0xbd0b('0x2f')]&&_0x3ebedf[_0xbd0b('0x2f')][_0x193cd6['id']]){delete _0x3ebedf['agents'][_0x193cd6['id']][_0x29a226+_0xbd0b('0x30')][_0x1e947b['message']['id']];}};exports[_0xbd0b('0x32')]=writeLog;