f49bf2097a80416bdedb18683ac2202da7860c81
[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 _0x6b24=['I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','format','user:%s','notification:%s','save','remove','info','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','OFFLINE','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','\x20MAXCAPACITY','showNotification','hideNotification','writeLog','util','../utils','mustache','ioredis','redis','socket.io-emitter','emit','name','user:save','split','account','notificationSound','notificationShake','body','queue','getMustacheRender','notificationTemplate','msg'];(function(_0x1bb6aa,_0x40fe82){var _0x2ef28e=function(_0x32b4eb){while(--_0x32b4eb){_0x1bb6aa['push'](_0x1bb6aa['shift']());}};_0x2ef28e(++_0x40fe82);}(_0x6b24,0x1ce));var _0x46b2=function(_0x3c68e4,_0x20e968){_0x3c68e4=_0x3c68e4-0x0;var _0x2b35e7=_0x6b24[_0x3c68e4];return _0x2b35e7;};'use strict';var _=require('lodash');var util=require(_0x46b2('0x0'));var utils=require(_0x46b2('0x1'));var Mustache=require(_0x46b2('0x2'));var Redis=require(_0x46b2('0x3'));var config=require('../../../../../config/environment');var logger=require('../../../../../config/logger')('routing');config[_0x46b2('0x4')]=_['defaults'](config[_0x46b2('0x4')],{'host':'localhost','port':0x18eb});var io=require(_0x46b2('0x5'))(new Redis(config['redis']));function emit(_0x512905,_0x326eb7,_0x233ccf){io['to'](_0x512905)[_0x46b2('0x6')](_0x326eb7,_0x233ccf);}function sendNotification(_0x1531c,_0x294294,_0x686192,_0x3144df,_0xde459c,_0x3e6b4d){io['to'](util['format']('user:%s',_0x3144df[_0x46b2('0x7')]))[_0x46b2('0x6')](_0x46b2('0x8'),_0x3144df);var _0x5bb2c3=_0x3e6b4d||{};var _0x18ae06=_0x686192[_0x46b2('0x9')]('.');var _0x13cfac={'uniqueid':_0x294294,'channel':_0x18ae06[0x0],'id':_0x18ae06[0x1],'title':_0x18ae06[0x0]+'\x20interaction','interactionId':_0x18ae06[0x2],'queue':_0xde459c?_0xde459c[_0x46b2('0x7')]:null,'sound':_0x5bb2c3[_0x46b2('0xa')][_0x46b2('0xb')],'shake':_0x5bb2c3[_0x46b2('0xa')][_0x46b2('0xc')]};try{if(!_0x5bb2c3[_0x46b2('0xd')]){_0x5bb2c3[_0x46b2('0xd')]={};}if(_0xde459c){_0x5bb2c3[_0x46b2('0xd')][_0x46b2('0xe')]=_0xde459c;}else if(_0x5bb2c3[_0x46b2('0xd')]['queue']){delete _0x5bb2c3[_0x46b2('0xd')][_0x46b2('0xe')];}_0x13cfac['msg']=utils[_0x46b2('0xf')](_0x5bb2c3[_0x46b2('0xa')][_0x46b2('0x10')],_0x5bb2c3);}catch(_0x3c62c6){_0x13cfac[_0x46b2('0x11')]=_0x46b2('0x12');logger[_0x46b2('0x13')](util['format'](_0x46b2('0x14'),_0x294294,_0x3c62c6['message']));}io['to'](util[_0x46b2('0x15')](_0x46b2('0x16'),_0x3144df[_0x46b2('0x7')]))['emit'](util[_0x46b2('0x15')](_0x46b2('0x17'),_0x1531c?_0x46b2('0x18'):_0x46b2('0x19')),_0x13cfac);}function writeLog(_0x350f85,_0x321033,_0x3a0ea5){return logger[_0x46b2('0x1a')](util[_0x46b2('0x15')](_0x46b2('0x1b'),_0x350f85,_0x321033[_0x46b2('0x7')],_0x3a0ea5));}exports[_0x46b2('0x1c')]=function(_0x451985,_0x160e6b,_0x1caa77,_0x50011b){if(_0x160e6b[_0x46b2('0x1d')]){writeLog(_0x451985,_0x160e6b,'BUSY');return![];}if(!_0x160e6b['online']){writeLog(_0x451985,_0x160e6b,_0x46b2('0x1e'));return![];}if(_0x160e6b[_0x1caa77+_0x46b2('0x1f')]){writeLog(_0x451985,_0x160e6b,_0x46b2('0x20'));return![];}if(_0x50011b&&_0x160e6b[_0x46b2('0x21')](_0x1caa77+_0x46b2('0x22'))&&_0x160e6b['hasOwnProperty'](_0x1caa77+_0x46b2('0x23'))){if(_0x160e6b[_0x1caa77+_0x46b2('0x22')]>0x0&&_0x160e6b[_0x1caa77+'CurrentCapacity']>=_0x160e6b[_0x1caa77+_0x46b2('0x22')]){writeLog(_0x451985,_0x160e6b,_0x1caa77['toUpperCase']()+_0x46b2('0x24'));return![];}}return!![];};exports[_0x46b2('0x25')]=function(_0x463d6e,_0x150a8b,_0x259c1c,_0x364048,_0x74615){return sendNotification(!![],_0x463d6e,_0x150a8b,_0x259c1c,_0x364048,_0x74615);};exports[_0x46b2('0x26')]=function(_0x429496,_0x20ccb2,_0x5421d9,_0x4e2a9b,_0x4dcee5){return sendNotification(![],_0x429496,_0x20ccb2,_0x5421d9,_0x4e2a9b,_0x4dcee5);};exports[_0x46b2('0x27')]=writeLog;