Built motion from commit b5996064.|2.6.21
[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 _0xe547=['toUpperCase','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','some','channel','QueuesWaitingInteractions','capitalize','InteractionId','agents','WaitingInteractions','saveWaitingNotification','removeWaitingNotification','writeLog','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','routing','defaults','redis','localhost','socket.io-emitter','split','\x20interaction','name','account','notificationSound','notificationShake','body','queue','msg','getMustacheRender','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','format','[%s][QUEUE]\x20%s','message','emit','notification:%s','save','remove','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','online','OFFLINE','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity'];(function(_0x20cced,_0x4e5560){var _0x47ee35=function(_0xe03c28){while(--_0xe03c28){_0x20cced['push'](_0x20cced['shift']());}};_0x47ee35(++_0x4e5560);}(_0xe547,0x191));var _0x7e54=function(_0xe078c6,_0x3a5eb4){_0xe078c6=_0xe078c6-0x0;var _0x428a9e=_0xe547[_0xe078c6];return _0x428a9e;};'use strict';var _=require('lodash');var util=require('util');var utils=require(_0x7e54('0x0'));var Redis=require(_0x7e54('0x1'));var config=require(_0x7e54('0x2'));var logger=require(_0x7e54('0x3'))(_0x7e54('0x4'));config['redis']=_[_0x7e54('0x5')](config[_0x7e54('0x6')],{'host':_0x7e54('0x7'),'port':0x18eb});var io=require(_0x7e54('0x8'))(new Redis(config[_0x7e54('0x6')]));function sendNotification(_0x3c99e0,_0x3fa88e,_0x536333,_0x160c07,_0x1b220e,_0x10c0a7){var _0x2afc1f=_0x10c0a7||{};var _0x2ff95c=_0x536333[_0x7e54('0x9')]('.');var _0x38d0af={'uniqueid':_0x3fa88e,'channel':_0x2ff95c[0x0],'id':_0x2ff95c[0x1],'title':_0x2ff95c[0x0]+_0x7e54('0xa'),'interactionId':_0x2ff95c[0x2],'queue':_0x1b220e?_0x1b220e[_0x7e54('0xb')]:null,'sound':_0x2afc1f[_0x7e54('0xc')][_0x7e54('0xd')],'shake':_0x2afc1f[_0x7e54('0xc')][_0x7e54('0xe')]};try{if(!_0x2afc1f[_0x7e54('0xf')]){_0x2afc1f[_0x7e54('0xf')]={};}if(_0x1b220e){_0x2afc1f['body'][_0x7e54('0x10')]=_0x1b220e;}else if(_0x2afc1f[_0x7e54('0xf')][_0x7e54('0x10')]){delete _0x2afc1f['body'][_0x7e54('0x10')];}_0x38d0af[_0x7e54('0x11')]=utils[_0x7e54('0x12')](_0x2afc1f[_0x7e54('0xc')][_0x7e54('0x13')],_0x2afc1f);}catch(_0x49efbf){_0x38d0af['msg']=_0x7e54('0x14');logger['error'](util[_0x7e54('0x15')](_0x7e54('0x16'),_0x3fa88e,_0x49efbf[_0x7e54('0x17')]));}io['to'](util[_0x7e54('0x15')]('user:%s',_0x160c07['name']))[_0x7e54('0x18')](util['format'](_0x7e54('0x19'),_0x3c99e0?_0x7e54('0x1a'):_0x7e54('0x1b')),_0x38d0af);}function writeLog(_0x329c12,_0x47eec0,_0x285c84){return logger[_0x7e54('0x1c')](util[_0x7e54('0x15')](_0x7e54('0x1d'),_0x329c12,_0x47eec0['name'],_0x285c84));}exports[_0x7e54('0x1e')]=function(_0x381574,_0x1ae074,_0x10ed71,_0x5117a6){if(_0x1ae074[_0x7e54('0x1f')]){writeLog(_0x381574,_0x1ae074,'BUSY');return![];}if(!_0x1ae074[_0x7e54('0x20')]){writeLog(_0x381574,_0x1ae074,_0x7e54('0x21'));return![];}if(_0x1ae074[_0x10ed71+_0x7e54('0x22')]){writeLog(_0x381574,_0x1ae074,_0x7e54('0x23'));return![];}if(_0x5117a6&&_0x1ae074[_0x7e54('0x24')](_0x10ed71+_0x7e54('0x25'))&&_0x1ae074[_0x7e54('0x24')](_0x10ed71+_0x7e54('0x26'))){if(_0x1ae074[_0x10ed71+'Capacity']>0x0&&_0x1ae074[_0x10ed71+'CurrentCapacity']>=_0x1ae074[_0x10ed71+'Capacity']){writeLog(_0x381574,_0x1ae074,_0x10ed71[_0x7e54('0x27')]()+'\x20MAXCAPACITY');return![];}}return!![];};exports[_0x7e54('0x28')]=function(_0x383f7e,_0x66ddc9,_0x3f4f7e,_0x588fb0,_0x3cced4){return sendNotification(!![],_0x383f7e,_0x66ddc9,_0x3f4f7e,_0x588fb0,_0x3cced4);};exports[_0x7e54('0x29')]=function(_0x193bf6,_0xe35c2a,_0x1f0683,_0x2f11cd,_0x54c742){return sendNotification(![],_0x193bf6,_0xe35c2a,_0x1f0683,_0x2f11cd,_0x54c742);};exports[_0x7e54('0x2a')]=function(_0x36f971,_0x5d6fa1,_0x5a35b2){var _0xa4da44=_0x5d6fa1[_0x7e54('0x2b')][_0x7e54('0x2c')];if(!_0xa4da44&&_0x5a35b2){_0xa4da44=_0x5a35b2['id'];}var _0x174806=_[_0x7e54('0x2d')](_0x36f971[_0x5d6fa1[_0x7e54('0x2e')]+_0x7e54('0x2f')],function(_0x3b9c8f){var _0x5b6497=_[_0x7e54('0x30')](_0x5d6fa1[_0x7e54('0x2e')])+_0x7e54('0x31');return _0x3b9c8f[_0x5b6497]===_0x5d6fa1[_0x7e54('0x2b')]['id'];});if(!_0x174806&&_0xa4da44&&_0x36f971['agents'][_0xa4da44]){_0x174806=_['some'](_0x36f971[_0x7e54('0x32')][_0xa4da44][_0x5d6fa1[_0x7e54('0x2e')]+_0x7e54('0x33')],function(_0x9618f6){return _0x9618f6['id']===_0x5d6fa1[_0x7e54('0x2b')]['id'];});}return _0x174806;};exports[_0x7e54('0x34')]=function(_0x1ae144,_0x426a33,_0x4cd5fe,_0x41bbe8){if(_0x4cd5fe&&_0x4cd5fe['id']&&_0x1ae144[_0x7e54('0x32')]&&_0x1ae144[_0x7e54('0x32')][_0x4cd5fe['id']]){_0x1ae144[_0x7e54('0x32')][_0x4cd5fe['id']][_0x41bbe8+_0x7e54('0x33')][_0x426a33[_0x7e54('0x17')]['id']]={'id':_0x426a33[_0x7e54('0x2b')]['id']};}};exports[_0x7e54('0x35')]=function(_0x11ae37,_0x30a1a0,_0x596c3b,_0x14df2a){if(_0x596c3b&&_0x596c3b['id']&&_0x11ae37['agents']&&_0x11ae37['agents'][_0x596c3b['id']]){delete _0x11ae37[_0x7e54('0x32')][_0x596c3b['id']][_0x14df2a+_0x7e54('0x33')][_0x30a1a0['message']['id']];}};exports[_0x7e54('0x36')]=writeLog;