c2ee8c6c00228dab9b15ab8af2ced2c673ace490
[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 _0x2917=['user:save','\x20interaction','account','notificationSound','notificationShake','body','queue','msg','getMustacheRender','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','format','[%s][QUEUE]\x20%s','message','notification:%s','remove','BUSY','online','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','\x20MAXCAPACITY','showNotification','hideNotification','writeLog','lodash','util','../utils','mustache','ioredis','../../../../../config/environment','../../../../../config/logger','defaults','redis','localhost','socket.io-emitter','emit','user:%s','name'];(function(_0x14e7b9,_0x3380c9){var _0x4bda5e=function(_0x34bdcc){while(--_0x34bdcc){_0x14e7b9['push'](_0x14e7b9['shift']());}};_0x4bda5e(++_0x3380c9);}(_0x2917,0x142));var _0x7291=function(_0x11b58d,_0x555c55){_0x11b58d=_0x11b58d-0x0;var _0xc2811b=_0x2917[_0x11b58d];return _0xc2811b;};'use strict';var _=require(_0x7291('0x0'));var util=require(_0x7291('0x1'));var utils=require(_0x7291('0x2'));var Mustache=require(_0x7291('0x3'));var Redis=require(_0x7291('0x4'));var config=require(_0x7291('0x5'));var logger=require(_0x7291('0x6'))('routing');config['redis']=_[_0x7291('0x7')](config[_0x7291('0x8')],{'host':_0x7291('0x9'),'port':0x18eb});var io=require(_0x7291('0xa'))(new Redis(config[_0x7291('0x8')]));function emit(_0x237997,_0x4609af,_0x1f0fd8){io['to'](_0x237997)[_0x7291('0xb')](_0x4609af,_0x1f0fd8);}function sendNotification(_0xb013b3,_0x3c7f38,_0xdf62dc,_0x27f037,_0x15298e,_0x3efe33){io['to'](util['format'](_0x7291('0xc'),_0x27f037[_0x7291('0xd')]))[_0x7291('0xb')](_0x7291('0xe'),_0x27f037);var _0x2beb53=_0x3efe33||{};var _0x407f0e=_0xdf62dc['split']('.');var _0x4fd701={'uniqueid':_0x3c7f38,'channel':_0x407f0e[0x0],'id':_0x407f0e[0x1],'title':_0x407f0e[0x0]+_0x7291('0xf'),'interactionId':_0x407f0e[0x2],'queue':_0x15298e?_0x15298e[_0x7291('0xd')]:null,'sound':_0x2beb53[_0x7291('0x10')][_0x7291('0x11')],'shake':_0x2beb53[_0x7291('0x10')][_0x7291('0x12')]};try{if(!_0x2beb53[_0x7291('0x13')]){_0x2beb53['body']={};}if(_0x15298e){_0x2beb53[_0x7291('0x13')][_0x7291('0x14')]=_0x15298e;}else if(_0x2beb53[_0x7291('0x13')]['queue']){delete _0x2beb53['body'][_0x7291('0x14')];}_0x4fd701[_0x7291('0x15')]=utils[_0x7291('0x16')](_0x2beb53[_0x7291('0x10')][_0x7291('0x17')],_0x2beb53);}catch(_0x354bd5){_0x4fd701['msg']=_0x7291('0x18');logger[_0x7291('0x19')](util[_0x7291('0x1a')](_0x7291('0x1b'),_0x3c7f38,_0x354bd5[_0x7291('0x1c')]));}io['to'](util['format'](_0x7291('0xc'),_0x27f037['name']))[_0x7291('0xb')](util[_0x7291('0x1a')](_0x7291('0x1d'),_0xb013b3?'save':_0x7291('0x1e')),_0x4fd701);}function writeLog(_0x50c6db,_0x31d537,_0x1aa349){return logger['info'](util['format']('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x50c6db,_0x31d537[_0x7291('0xd')],_0x1aa349));}exports['isAgentAvailable']=function(_0x17839a,_0x251649,_0x5d7fd8,_0x3fa414){if(_0x251649['busy']){writeLog(_0x17839a,_0x251649,_0x7291('0x1f'));return![];}if(!_0x251649[_0x7291('0x20')]){writeLog(_0x17839a,_0x251649,'OFFLINE');return![];}if(_0x251649[_0x5d7fd8+_0x7291('0x21')]){writeLog(_0x17839a,_0x251649,_0x7291('0x22'));return![];}if(_0x3fa414&&_0x251649[_0x7291('0x23')](_0x5d7fd8+_0x7291('0x24'))&&_0x251649[_0x7291('0x23')](_0x5d7fd8+_0x7291('0x25'))){if(_0x251649[_0x5d7fd8+_0x7291('0x24')]>0x0&&_0x251649[_0x5d7fd8+_0x7291('0x25')]>=_0x251649[_0x5d7fd8+_0x7291('0x24')]){writeLog(_0x17839a,_0x251649,_0x5d7fd8['toUpperCase']()+_0x7291('0x26'));return![];}}return!![];};exports[_0x7291('0x27')]=function(_0x4e2efa,_0x370bd8,_0x42056c,_0x48cb19,_0x386667){return sendNotification(!![],_0x4e2efa,_0x370bd8,_0x42056c,_0x48cb19,_0x386667);};exports[_0x7291('0x28')]=function(_0x522ef7,_0x31207c,_0x10e006,_0xf32830,_0x5d18f2){return sendNotification(![],_0x522ef7,_0x31207c,_0x10e006,_0xf32830,_0x5d18f2);};exports[_0x7291('0x29')]=writeLog;