Built motion from commit b0a9a629.|2.6.33
[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 _0x5ab9=['message','emit','notification:%s','save','remove','debug','isAgentAvailable','BUSY','Pause','PAUSE','hasOwnProperty','CurrentCapacity','Capacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','channel','QueuesWaitingInteractions','capitalize','agents','some','WaitingInteractions','saveWaitingNotification','removeWaitingNotification','writeLog','util','ioredis','../../../../../config/environment','../../../../../config/logger','redis','defaults','localhost','split','\x20interaction','name','account','notificationSound','notificationShake','body','queue','getMustacheRender','notificationTemplate','msg','error','format','[%s][QUEUE]\x20%s'];(function(_0x3a37af,_0x511881){var _0x13a26a=function(_0x4ef778){while(--_0x4ef778){_0x3a37af['push'](_0x3a37af['shift']());}};_0x13a26a(++_0x511881);}(_0x5ab9,0x117));var _0x95ab=function(_0x32bdd4,_0x143a69){_0x32bdd4=_0x32bdd4-0x0;var _0x4b54d3=_0x5ab9[_0x32bdd4];return _0x4b54d3;};'use strict';var _=require('lodash');var util=require(_0x95ab('0x0'));var utils=require('../utils');var Redis=require(_0x95ab('0x1'));var config=require(_0x95ab('0x2'));var logger=require(_0x95ab('0x3'))('routing');config[_0x95ab('0x4')]=_[_0x95ab('0x5')](config['redis'],{'host':_0x95ab('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x95ab('0x4')]));function sendNotification(_0x23b91d,_0x546d8b,_0x56b5cb,_0x4ac348,_0x195203,_0x3431c5){var _0x1f32c8=_0x3431c5||{};var _0x2e2696=_0x56b5cb[_0x95ab('0x7')]('.');var _0x36712d={'uniqueid':_0x546d8b,'channel':_0x2e2696[0x0],'id':_0x2e2696[0x1],'title':_0x2e2696[0x0]+_0x95ab('0x8'),'interactionId':_0x2e2696[0x2],'queue':_0x195203?_0x195203[_0x95ab('0x9')]:null,'sound':_0x1f32c8[_0x95ab('0xa')][_0x95ab('0xb')],'shake':_0x1f32c8[_0x95ab('0xa')][_0x95ab('0xc')]};try{if(!_0x1f32c8['body']){_0x1f32c8['body']={};}if(_0x195203){_0x1f32c8[_0x95ab('0xd')]['queue']=_0x195203;}else if(_0x1f32c8[_0x95ab('0xd')][_0x95ab('0xe')]){delete _0x1f32c8[_0x95ab('0xd')]['queue'];}_0x36712d['msg']=utils[_0x95ab('0xf')](_0x1f32c8[_0x95ab('0xa')][_0x95ab('0x10')],_0x1f32c8);}catch(_0x2b1d19){_0x36712d[_0x95ab('0x11')]='I\x20can\x27t\x20render\x20your\x20template';logger[_0x95ab('0x12')](util[_0x95ab('0x13')](_0x95ab('0x14'),_0x546d8b,_0x2b1d19[_0x95ab('0x15')]));}io['to'](util[_0x95ab('0x13')]('user:%s',_0x4ac348[_0x95ab('0x9')]))[_0x95ab('0x16')](util['format'](_0x95ab('0x17'),_0x23b91d?_0x95ab('0x18'):_0x95ab('0x19')),_0x36712d);}function writeLog(_0x137646,_0x22a8d1,_0x3c4275){return logger[_0x95ab('0x1a')](util[_0x95ab('0x13')]('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x137646,_0x22a8d1['name'],_0x3c4275));}exports[_0x95ab('0x1b')]=function(_0x1f0c7a,_0x3446b4,_0xb1885e,_0x4845bf){if(_0x3446b4['busy']){writeLog(_0x1f0c7a,_0x3446b4,_0x95ab('0x1c'));return![];}if(!_0x3446b4['online']){writeLog(_0x1f0c7a,_0x3446b4,'OFFLINE');return![];}if(_0x3446b4[_0xb1885e+_0x95ab('0x1d')]){writeLog(_0x1f0c7a,_0x3446b4,_0x95ab('0x1e'));return![];}if(_0x4845bf&&_0x3446b4[_0x95ab('0x1f')](_0xb1885e+'Capacity')&&_0x3446b4['hasOwnProperty'](_0xb1885e+_0x95ab('0x20'))){if(_0x3446b4[_0xb1885e+_0x95ab('0x21')]>0x0&&_0x3446b4[_0xb1885e+_0x95ab('0x20')]>=_0x3446b4[_0xb1885e+_0x95ab('0x21')]){writeLog(_0x1f0c7a,_0x3446b4,_0xb1885e[_0x95ab('0x22')]()+_0x95ab('0x23'));return![];}}return!![];};exports[_0x95ab('0x24')]=function(_0x46309d,_0x31f4c1,_0x5cb9be,_0x5f4ced,_0xd28b4f){return sendNotification(!![],_0x46309d,_0x31f4c1,_0x5cb9be,_0x5f4ced,_0xd28b4f);};exports[_0x95ab('0x25')]=function(_0x58231c,_0x48233c,_0x4f17d1,_0xc7d396,_0x408c47){return sendNotification(![],_0x58231c,_0x48233c,_0x4f17d1,_0xc7d396,_0x408c47);};exports[_0x95ab('0x26')]=function(_0x4f46a7,_0xd73a14,_0x395516){var _0x1fcd49=_0xd73a14[_0x95ab('0x27')][_0x95ab('0x28')];if(!_0x1fcd49&&_0x395516){_0x1fcd49=_0x395516['id'];}var _0xd0bc7=_['some'](_0x4f46a7[_0xd73a14[_0x95ab('0x29')]+_0x95ab('0x2a')],function(_0x58522a){var _0x9965d3=_[_0x95ab('0x2b')](_0xd73a14[_0x95ab('0x29')])+'InteractionId';return _0x58522a[_0x9965d3]===_0xd73a14[_0x95ab('0x27')]['id'];});if(!_0xd0bc7&&_0x1fcd49&&_0x4f46a7[_0x95ab('0x2c')][_0x1fcd49]){_0xd0bc7=_[_0x95ab('0x2d')](_0x4f46a7[_0x95ab('0x2c')][_0x1fcd49][_0xd73a14[_0x95ab('0x29')]+_0x95ab('0x2e')],function(_0x5700a0){return _0x5700a0['id']===_0xd73a14[_0x95ab('0x27')]['id'];});}return _0xd0bc7;};exports[_0x95ab('0x2f')]=function(_0x271661,_0x36b640,_0x3a842e,_0x19ea96){if(_0x3a842e&&_0x3a842e['id']&&_0x271661[_0x95ab('0x2c')]&&_0x271661[_0x95ab('0x2c')][_0x3a842e['id']]){_0x271661[_0x95ab('0x2c')][_0x3a842e['id']][_0x19ea96+_0x95ab('0x2e')][_0x36b640[_0x95ab('0x15')]['id']]={'id':_0x36b640[_0x95ab('0x27')]['id']};}};exports[_0x95ab('0x30')]=function(_0x456cf9,_0x3372ab,_0x27a0f4,_0x1aad1d){if(_0x27a0f4&&_0x27a0f4['id']&&_0x456cf9[_0x95ab('0x2c')]&&_0x456cf9[_0x95ab('0x2c')][_0x27a0f4['id']]){delete _0x456cf9['agents'][_0x27a0f4['id']][_0x1aad1d+_0x95ab('0x2e')][_0x3372ab[_0x95ab('0x15')]['id']];}};exports[_0x95ab('0x31')]=writeLog;