Built motion from commit 00bf23f6.|2.6.16
[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 _0x4d3f=['capitalize','InteractionId','agents','WaitingInteractions','saveWaitingNotification','message','removeWaitingNotification','writeLog','util','ioredis','../../../../../config/logger','routing','redis','defaults','socket.io-emitter','format','user:%s','name','emit','user:save','split','\x20interaction','account','notificationSound','notificationShake','body','queue','msg','I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','notification:%s','save','remove','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY','Pause','PAUSE','Capacity','hasOwnProperty','CurrentCapacity','toUpperCase','showNotification','checkWaitingNotifications','interaction','some','channel','QueuesWaitingInteractions'];(function(_0x1d8119,_0xc98f17){var _0x3e30f6=function(_0x2c7f3e){while(--_0x2c7f3e){_0x1d8119['push'](_0x1d8119['shift']());}};_0x3e30f6(++_0xc98f17);}(_0x4d3f,0x198));var _0xf4d3=function(_0x39a545,_0x2e80ad){_0x39a545=_0x39a545-0x0;var _0x8d15db=_0x4d3f[_0x39a545];return _0x8d15db;};'use strict';var _=require('lodash');var util=require(_0xf4d3('0x0'));var utils=require('../utils');var Redis=require(_0xf4d3('0x1'));var config=require('../../../../../config/environment');var logger=require(_0xf4d3('0x2'))(_0xf4d3('0x3'));config[_0xf4d3('0x4')]=_[_0xf4d3('0x5')](config[_0xf4d3('0x4')],{'host':'localhost','port':0x18eb});var io=require(_0xf4d3('0x6'))(new Redis(config[_0xf4d3('0x4')]));function sendNotification(_0x524fe3,_0x7d1b1a,_0x15e9d4,_0x4d9add,_0x1a6514,_0x54b7e1){io['to'](util[_0xf4d3('0x7')](_0xf4d3('0x8'),_0x4d9add[_0xf4d3('0x9')]))[_0xf4d3('0xa')](_0xf4d3('0xb'),_0x4d9add);var _0x21d688=_0x54b7e1||{};var _0x39f4e7=_0x15e9d4[_0xf4d3('0xc')]('.');var _0x1d5ec5={'uniqueid':_0x7d1b1a,'channel':_0x39f4e7[0x0],'id':_0x39f4e7[0x1],'title':_0x39f4e7[0x0]+_0xf4d3('0xd'),'interactionId':_0x39f4e7[0x2],'queue':_0x1a6514?_0x1a6514['name']:null,'sound':_0x21d688[_0xf4d3('0xe')][_0xf4d3('0xf')],'shake':_0x21d688[_0xf4d3('0xe')][_0xf4d3('0x10')]};try{if(!_0x21d688['body']){_0x21d688['body']={};}if(_0x1a6514){_0x21d688[_0xf4d3('0x11')][_0xf4d3('0x12')]=_0x1a6514;}else if(_0x21d688[_0xf4d3('0x11')][_0xf4d3('0x12')]){delete _0x21d688[_0xf4d3('0x11')][_0xf4d3('0x12')];}_0x1d5ec5[_0xf4d3('0x13')]=utils['getMustacheRender'](_0x21d688[_0xf4d3('0xe')]['notificationTemplate'],_0x21d688);}catch(_0x59050f){_0x1d5ec5['msg']=_0xf4d3('0x14');logger[_0xf4d3('0x15')](util[_0xf4d3('0x7')](_0xf4d3('0x16'),_0x7d1b1a,_0x59050f['message']));}io['to'](util[_0xf4d3('0x7')]('user:%s',_0x4d9add[_0xf4d3('0x9')]))['emit'](util[_0xf4d3('0x7')](_0xf4d3('0x17'),_0x524fe3?_0xf4d3('0x18'):_0xf4d3('0x19')),_0x1d5ec5);}function writeLog(_0x346e14,_0x1c7e22,_0x144b25){return logger['debug'](util[_0xf4d3('0x7')](_0xf4d3('0x1a'),_0x346e14,_0x1c7e22[_0xf4d3('0x9')],_0x144b25));}exports[_0xf4d3('0x1b')]=function(_0xeb911c,_0x5bf951,_0x393dfb,_0x4c0b79){if(_0x5bf951[_0xf4d3('0x1c')]){writeLog(_0xeb911c,_0x5bf951,_0xf4d3('0x1d'));return![];}if(!_0x5bf951['online']){writeLog(_0xeb911c,_0x5bf951,'OFFLINE');return![];}if(_0x5bf951[_0x393dfb+_0xf4d3('0x1e')]){writeLog(_0xeb911c,_0x5bf951,_0xf4d3('0x1f'));return![];}if(_0x4c0b79&&_0x5bf951['hasOwnProperty'](_0x393dfb+_0xf4d3('0x20'))&&_0x5bf951[_0xf4d3('0x21')](_0x393dfb+_0xf4d3('0x22'))){if(_0x5bf951[_0x393dfb+'Capacity']>0x0&&_0x5bf951[_0x393dfb+'CurrentCapacity']>=_0x5bf951[_0x393dfb+_0xf4d3('0x20')]){writeLog(_0xeb911c,_0x5bf951,_0x393dfb[_0xf4d3('0x23')]()+'\x20MAXCAPACITY');return![];}}return!![];};exports[_0xf4d3('0x24')]=function(_0x3ebace,_0x130447,_0x352df3,_0x14c4f5,_0xf45884){return sendNotification(!![],_0x3ebace,_0x130447,_0x352df3,_0x14c4f5,_0xf45884);};exports['hideNotification']=function(_0x17371c,_0x36273b,_0x34f9ac,_0xef4f8b,_0x37b417){return sendNotification(![],_0x17371c,_0x36273b,_0x34f9ac,_0xef4f8b,_0x37b417);};exports[_0xf4d3('0x25')]=function(_0x1020ec,_0x28661d,_0x53c0a3){var _0x2ff0f9=_0x28661d[_0xf4d3('0x26')]['UserId'];if(!_0x2ff0f9&&_0x53c0a3){_0x2ff0f9=_0x53c0a3['id'];}var _0x591334=_[_0xf4d3('0x27')](_0x1020ec[_0x28661d[_0xf4d3('0x28')]+_0xf4d3('0x29')],function(_0xa9353c){var _0x256006=_[_0xf4d3('0x2a')](_0x28661d[_0xf4d3('0x28')])+_0xf4d3('0x2b');return _0xa9353c[_0x256006]===_0x28661d['interaction']['id'];});if(!_0x591334&&_0x2ff0f9){_0x591334=_[_0xf4d3('0x27')](_0x1020ec[_0xf4d3('0x2c')][_0x2ff0f9][_0x28661d[_0xf4d3('0x28')]+_0xf4d3('0x2d')],function(_0x35e1eb){return _0x35e1eb['id']===_0x28661d['interaction']['id'];});}return _0x591334;};exports[_0xf4d3('0x2e')]=function(_0x297030,_0x3b7641,_0x1a8c20,_0x37a3b0){_0x297030[_0xf4d3('0x2c')][_0x1a8c20['id']][_0x37a3b0+_0xf4d3('0x2d')][_0x3b7641[_0xf4d3('0x2f')]['id']]={'id':_0x3b7641[_0xf4d3('0x26')]['id']};};exports[_0xf4d3('0x30')]=function(_0x1ee0b3,_0x29d8ec,_0x4f3e1f,_0x48dfd8){delete _0x1ee0b3[_0xf4d3('0x2c')][_0x4f3e1f['id']][_0x48dfd8+'WaitingInteractions'][_0x29d8ec['message']['id']];};exports[_0xf4d3('0x31')]=writeLog;