257c51eabad5bc14f90854742993967f4297a983
[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 _0xf2f3=['mustache','../../../../../config/environment','../../../../../config/logger','routing','redis','localhost','socket.io-emitter','emit','format','name','user:save','split','account','notificationShake','body','queue','msg','getMustacheRender','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','user:%s','save','remove','info','isAgentAvailable','busy','BUSY','online','OFFLINE','PAUSE','hasOwnProperty','CurrentCapacity','Capacity','showNotification','writeLog','util','../utils'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xf2f3,0x15d));var _0x3f2f=function(_0x179478,_0x5e01b5){_0x179478=_0x179478-0x0;var _0x5384dd=_0xf2f3[_0x179478];return _0x5384dd;};'use strict';var _=require('lodash');var util=require(_0x3f2f('0x0'));var utils=require(_0x3f2f('0x1'));var Mustache=require(_0x3f2f('0x2'));var Redis=require('ioredis');var config=require(_0x3f2f('0x3'));var logger=require(_0x3f2f('0x4'))(_0x3f2f('0x5'));config['redis']=_['defaults'](config[_0x3f2f('0x6')],{'host':_0x3f2f('0x7'),'port':0x18eb});var io=require(_0x3f2f('0x8'))(new Redis(config[_0x3f2f('0x6')]));function emit(_0xbcd687,_0x4650c5,_0x401c52){io['to'](_0xbcd687)[_0x3f2f('0x9')](_0x4650c5,_0x401c52);}function sendNotification(_0xc83ca3,_0x2c54f8,_0x191f5f,_0x438f59,_0x2e3ee3,_0x325b66){io['to'](util[_0x3f2f('0xa')]('user:%s',_0x438f59[_0x3f2f('0xb')]))[_0x3f2f('0x9')](_0x3f2f('0xc'),_0x438f59);var _0x548dd4=_0x325b66||{};var _0x376e78=_0x191f5f[_0x3f2f('0xd')]('.');var _0x5e6169={'uniqueid':_0x2c54f8,'channel':_0x376e78[0x0],'id':_0x376e78[0x1],'title':_0x376e78[0x0]+'\x20interaction','interactionId':_0x376e78[0x2],'queue':_0x2e3ee3?_0x2e3ee3[_0x3f2f('0xb')]:null,'sound':_0x548dd4['account']['notificationSound'],'shake':_0x548dd4[_0x3f2f('0xe')][_0x3f2f('0xf')]};try{if(!_0x548dd4[_0x3f2f('0x10')]){_0x548dd4['body']={};}if(_0x2e3ee3){_0x548dd4['body'][_0x3f2f('0x11')]=_0x2e3ee3;}else if(_0x548dd4[_0x3f2f('0x10')][_0x3f2f('0x11')]){delete _0x548dd4[_0x3f2f('0x10')][_0x3f2f('0x11')];}_0x5e6169[_0x3f2f('0x12')]=utils[_0x3f2f('0x13')](_0x548dd4['account'][_0x3f2f('0x14')],_0x548dd4);}catch(_0x3a8b51){_0x5e6169[_0x3f2f('0x12')]=_0x3f2f('0x15');logger[_0x3f2f('0x16')](util[_0x3f2f('0xa')](_0x3f2f('0x17'),_0x2c54f8,_0x3a8b51['message']));}io['to'](util[_0x3f2f('0xa')](_0x3f2f('0x18'),_0x438f59[_0x3f2f('0xb')]))['emit'](util[_0x3f2f('0xa')]('notification:%s',_0xc83ca3?_0x3f2f('0x19'):_0x3f2f('0x1a')),_0x5e6169);}function writeLog(_0x3e39b9,_0x123aed,_0x1c6840){return logger[_0x3f2f('0x1b')](util[_0x3f2f('0xa')]('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x3e39b9,_0x123aed[_0x3f2f('0xb')],_0x1c6840));}exports[_0x3f2f('0x1c')]=function(_0x525d7d,_0x335c59,_0x181226,_0x40920e){if(_0x335c59[_0x3f2f('0x1d')]){writeLog(_0x525d7d,_0x335c59,_0x3f2f('0x1e'));return![];}if(!_0x335c59[_0x3f2f('0x1f')]){writeLog(_0x525d7d,_0x335c59,_0x3f2f('0x20'));return![];}if(_0x335c59[_0x181226+'Pause']){writeLog(_0x525d7d,_0x335c59,_0x3f2f('0x21'));return![];}if(_0x40920e&&_0x335c59[_0x3f2f('0x22')](_0x181226+'Capacity')&&_0x335c59[_0x3f2f('0x22')](_0x181226+_0x3f2f('0x23'))){if(_0x335c59[_0x181226+_0x3f2f('0x24')]>0x0&&_0x335c59[_0x181226+'CurrentCapacity']>=_0x335c59[_0x181226+_0x3f2f('0x24')]){writeLog(_0x525d7d,_0x335c59,_0x181226['toUpperCase']()+'\x20MAXCAPACITY');return![];}}return!![];};exports[_0x3f2f('0x25')]=function(_0x3bcc4f,_0x422763,_0x195c0d,_0x304cce,_0x57d989){return sendNotification(!![],_0x3bcc4f,_0x422763,_0x195c0d,_0x304cce,_0x57d989);};exports['hideNotification']=function(_0xb839b,_0x394251,_0x13195f,_0x449674,_0x1717a9){return sendNotification(![],_0xb839b,_0x394251,_0x13195f,_0x449674,_0x1717a9);};exports[_0x3f2f('0x26')]=writeLog;