b7d4efb90a97702278365818d41006831f75fc69
[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 _0x0c71=['defaults','localhost','socket.io-emitter','redis','\x20interaction','name','notificationSound','account','notificationShake','body','queue','msg','getMustacheRender','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','format','[%s][QUEUE]\x20%s','user:%s','emit','notification:%s','save','remove','debug','isAgentAvailable','busy','BUSY','online','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','interaction','channel','InteractionId','some','agents','WaitingInteractions','saveWaitingNotification','message','removeWaitingNotification','writeLog','util','ioredis','../../../../../config/environment','../../../../../config/logger'];(function(_0x4f431d,_0xd51a3b){var _0x4f31e1=function(_0x1c688d){while(--_0x1c688d){_0x4f431d['push'](_0x4f431d['shift']());}};_0x4f31e1(++_0xd51a3b);}(_0x0c71,0xfb));var _0x10c7=function(_0x4b0a54,_0x31fc5b){_0x4b0a54=_0x4b0a54-0x0;var _0x3b51d6=_0x0c71[_0x4b0a54];return _0x3b51d6;};'use strict';var _=require('lodash');var util=require(_0x10c7('0x0'));var utils=require('../utils');var Redis=require(_0x10c7('0x1'));var config=require(_0x10c7('0x2'));var logger=require(_0x10c7('0x3'))('routing');config['redis']=_[_0x10c7('0x4')](config['redis'],{'host':_0x10c7('0x5'),'port':0x18eb});var io=require(_0x10c7('0x6'))(new Redis(config[_0x10c7('0x7')]));function sendNotification(_0x4480c2,_0x2dbe32,_0xd955fc,_0x4d8fc8,_0x3cbcd7,_0x221c8f){var _0x5709c7=_0x221c8f||{};var _0x346bbc=_0xd955fc['split']('.');var _0x55c113={'uniqueid':_0x2dbe32,'channel':_0x346bbc[0x0],'id':_0x346bbc[0x1],'title':_0x346bbc[0x0]+_0x10c7('0x8'),'interactionId':_0x346bbc[0x2],'queue':_0x3cbcd7?_0x3cbcd7[_0x10c7('0x9')]:null,'sound':_0x5709c7['account'][_0x10c7('0xa')],'shake':_0x5709c7[_0x10c7('0xb')][_0x10c7('0xc')]};try{if(!_0x5709c7[_0x10c7('0xd')]){_0x5709c7[_0x10c7('0xd')]={};}if(_0x3cbcd7){_0x5709c7[_0x10c7('0xd')][_0x10c7('0xe')]=_0x3cbcd7;}else if(_0x5709c7[_0x10c7('0xd')][_0x10c7('0xe')]){delete _0x5709c7[_0x10c7('0xd')]['queue'];}_0x55c113[_0x10c7('0xf')]=utils[_0x10c7('0x10')](_0x5709c7[_0x10c7('0xb')][_0x10c7('0x11')],_0x5709c7);}catch(_0x45568c){_0x55c113[_0x10c7('0xf')]=_0x10c7('0x12');logger['error'](util[_0x10c7('0x13')](_0x10c7('0x14'),_0x2dbe32,_0x45568c['message']));}io['to'](util[_0x10c7('0x13')](_0x10c7('0x15'),_0x4d8fc8[_0x10c7('0x9')]))[_0x10c7('0x16')](util[_0x10c7('0x13')](_0x10c7('0x17'),_0x4480c2?_0x10c7('0x18'):_0x10c7('0x19')),_0x55c113);}function writeLog(_0x2ecb76,_0x4ce96d,_0x59eb70){return logger[_0x10c7('0x1a')](util[_0x10c7('0x13')]('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x2ecb76,_0x4ce96d[_0x10c7('0x9')],_0x59eb70));}exports[_0x10c7('0x1b')]=function(_0xe1133a,_0x5373cf,_0x41a5ba,_0x5e3279){if(_0x5373cf[_0x10c7('0x1c')]){writeLog(_0xe1133a,_0x5373cf,_0x10c7('0x1d'));return![];}if(!_0x5373cf[_0x10c7('0x1e')]){writeLog(_0xe1133a,_0x5373cf,'OFFLINE');return![];}if(_0x5373cf[_0x41a5ba+_0x10c7('0x1f')]){writeLog(_0xe1133a,_0x5373cf,_0x10c7('0x20'));return![];}if(_0x5e3279&&_0x5373cf[_0x10c7('0x21')](_0x41a5ba+_0x10c7('0x22'))&&_0x5373cf[_0x10c7('0x21')](_0x41a5ba+_0x10c7('0x23'))){if(_0x5373cf[_0x41a5ba+_0x10c7('0x22')]>0x0&&_0x5373cf[_0x41a5ba+_0x10c7('0x23')]>=_0x5373cf[_0x41a5ba+_0x10c7('0x22')]){writeLog(_0xe1133a,_0x5373cf,_0x41a5ba[_0x10c7('0x24')]()+_0x10c7('0x25'));return![];}}return!![];};exports[_0x10c7('0x26')]=function(_0x3bc016,_0xe53724,_0x3c40c3,_0x3c9665,_0xec403){return sendNotification(!![],_0x3bc016,_0xe53724,_0x3c40c3,_0x3c9665,_0xec403);};exports[_0x10c7('0x27')]=function(_0x33093e,_0x43c2ff,_0x5626cd,_0x4c89c7,_0x4c331f){return sendNotification(![],_0x33093e,_0x43c2ff,_0x5626cd,_0x4c89c7,_0x4c331f);};exports[_0x10c7('0x28')]=function(_0x460e28,_0x45aa1c,_0x206e1d){var _0x27ac7e=_0x45aa1c[_0x10c7('0x29')]['UserId'];if(!_0x27ac7e&&_0x206e1d){_0x27ac7e=_0x206e1d['id'];}var _0x4630c8=_['some'](_0x460e28[_0x45aa1c[_0x10c7('0x2a')]+'QueuesWaitingInteractions'],function(_0x3731a1){var _0x14efa1=_['capitalize'](_0x45aa1c[_0x10c7('0x2a')])+_0x10c7('0x2b');return _0x3731a1[_0x14efa1]===_0x45aa1c[_0x10c7('0x29')]['id'];});if(!_0x4630c8&&_0x27ac7e&&_0x460e28['agents'][_0x27ac7e]){_0x4630c8=_[_0x10c7('0x2c')](_0x460e28[_0x10c7('0x2d')][_0x27ac7e][_0x45aa1c[_0x10c7('0x2a')]+_0x10c7('0x2e')],function(_0x93642b){return _0x93642b['id']===_0x45aa1c[_0x10c7('0x29')]['id'];});}return _0x4630c8;};exports[_0x10c7('0x2f')]=function(_0x53e78d,_0x4983dc,_0x3d0383,_0x3fa382){if(_0x3d0383&&_0x3d0383['id']&&_0x53e78d[_0x10c7('0x2d')]&&_0x53e78d[_0x10c7('0x2d')][_0x3d0383['id']]){_0x53e78d[_0x10c7('0x2d')][_0x3d0383['id']][_0x3fa382+_0x10c7('0x2e')][_0x4983dc[_0x10c7('0x30')]['id']]={'id':_0x4983dc[_0x10c7('0x29')]['id']};}};exports[_0x10c7('0x31')]=function(_0x3ff7a9,_0x2d7f9e,_0x28b273,_0x15d76f){if(_0x28b273&&_0x28b273['id']&&_0x3ff7a9[_0x10c7('0x2d')]&&_0x3ff7a9['agents'][_0x28b273['id']]){delete _0x3ff7a9[_0x10c7('0x2d')][_0x28b273['id']][_0x15d76f+_0x10c7('0x2e')][_0x2d7f9e[_0x10c7('0x30')]['id']];}};exports[_0x10c7('0x32')]=writeLog;