9fe7cd71f500432a5ddb3210e81b3ea020b80965
[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 _0x78e2=['Capacity','CurrentCapacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','some','channel','QueuesWaitingInteractions','capitalize','InteractionId','agents','WaitingInteractions','removeWaitingNotification','writeLog','lodash','util','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','routing','redis','localhost','socket.io-emitter','format','user:%s','name','emit','user:save','split','\x20interaction','account','notificationSound','notificationShake','body','queue','msg','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','message','notification:%s','save','remove','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY','OFFLINE','Pause','PAUSE','hasOwnProperty'];(function(_0x448c09,_0x40cacc){var _0x3825cd=function(_0x468612){while(--_0x468612){_0x448c09['push'](_0x448c09['shift']());}};_0x3825cd(++_0x40cacc);}(_0x78e2,0x168));var _0x278e=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x78e2[_0x3dd15e];return _0x231fd0;};'use strict';var _=require(_0x278e('0x0'));var util=require(_0x278e('0x1'));var utils=require(_0x278e('0x2'));var Redis=require(_0x278e('0x3'));var config=require(_0x278e('0x4'));var logger=require(_0x278e('0x5'))(_0x278e('0x6'));config[_0x278e('0x7')]=_['defaults'](config['redis'],{'host':_0x278e('0x8'),'port':0x18eb});var io=require(_0x278e('0x9'))(new Redis(config['redis']));function sendNotification(_0x205be4,_0x44afa6,_0x3aed6c,_0x1444ff,_0x2f0ead,_0x3f7787){io['to'](util[_0x278e('0xa')](_0x278e('0xb'),_0x1444ff[_0x278e('0xc')]))[_0x278e('0xd')](_0x278e('0xe'),_0x1444ff);var _0x25283d=_0x3f7787||{};var _0xc8a77f=_0x3aed6c[_0x278e('0xf')]('.');var _0x3fb79a={'uniqueid':_0x44afa6,'channel':_0xc8a77f[0x0],'id':_0xc8a77f[0x1],'title':_0xc8a77f[0x0]+_0x278e('0x10'),'interactionId':_0xc8a77f[0x2],'queue':_0x2f0ead?_0x2f0ead[_0x278e('0xc')]:null,'sound':_0x25283d[_0x278e('0x11')][_0x278e('0x12')],'shake':_0x25283d[_0x278e('0x11')][_0x278e('0x13')]};try{if(!_0x25283d[_0x278e('0x14')]){_0x25283d[_0x278e('0x14')]={};}if(_0x2f0ead){_0x25283d['body']['queue']=_0x2f0ead;}else if(_0x25283d['body'][_0x278e('0x15')]){delete _0x25283d[_0x278e('0x14')][_0x278e('0x15')];}_0x3fb79a[_0x278e('0x16')]=utils['getMustacheRender'](_0x25283d[_0x278e('0x11')][_0x278e('0x17')],_0x25283d);}catch(_0x1e65a7){_0x3fb79a['msg']=_0x278e('0x18');logger[_0x278e('0x19')](util[_0x278e('0xa')](_0x278e('0x1a'),_0x44afa6,_0x1e65a7[_0x278e('0x1b')]));}io['to'](util[_0x278e('0xa')]('user:%s',_0x1444ff['name']))[_0x278e('0xd')](util[_0x278e('0xa')](_0x278e('0x1c'),_0x205be4?_0x278e('0x1d'):_0x278e('0x1e')),_0x3fb79a);}function writeLog(_0x31f2b8,_0x38c10c,_0x51625d){return logger['debug'](util['format'](_0x278e('0x1f'),_0x31f2b8,_0x38c10c[_0x278e('0xc')],_0x51625d));}exports[_0x278e('0x20')]=function(_0x18e43a,_0x18e388,_0x3d5c93,_0x65cb26){if(_0x18e388[_0x278e('0x21')]){writeLog(_0x18e43a,_0x18e388,_0x278e('0x22'));return![];}if(!_0x18e388['online']){writeLog(_0x18e43a,_0x18e388,_0x278e('0x23'));return![];}if(_0x18e388[_0x3d5c93+_0x278e('0x24')]){writeLog(_0x18e43a,_0x18e388,_0x278e('0x25'));return![];}if(_0x65cb26&&_0x18e388[_0x278e('0x26')](_0x3d5c93+_0x278e('0x27'))&&_0x18e388[_0x278e('0x26')](_0x3d5c93+_0x278e('0x28'))){if(_0x18e388[_0x3d5c93+_0x278e('0x27')]>0x0&&_0x18e388[_0x3d5c93+_0x278e('0x28')]>=_0x18e388[_0x3d5c93+_0x278e('0x27')]){writeLog(_0x18e43a,_0x18e388,_0x3d5c93[_0x278e('0x29')]()+_0x278e('0x2a'));return![];}}return!![];};exports[_0x278e('0x2b')]=function(_0x36039f,_0x143554,_0xede9b3,_0x8697ce,_0xf662d8){return sendNotification(!![],_0x36039f,_0x143554,_0xede9b3,_0x8697ce,_0xf662d8);};exports[_0x278e('0x2c')]=function(_0x5aa89f,_0x2d920e,_0x3650c6,_0x3663b5,_0x4248e7){return sendNotification(![],_0x5aa89f,_0x2d920e,_0x3650c6,_0x3663b5,_0x4248e7);};exports[_0x278e('0x2d')]=function(_0x1b81bb,_0x5224b3,_0x355406){var _0x1f4055=_0x5224b3[_0x278e('0x2e')][_0x278e('0x2f')];if(!_0x1f4055&&_0x355406){_0x1f4055=_0x355406['id'];}var _0x333968=_[_0x278e('0x30')](_0x1b81bb[_0x5224b3[_0x278e('0x31')]+_0x278e('0x32')],function(_0x48216d){var _0xbfb28=_[_0x278e('0x33')](_0x5224b3[_0x278e('0x31')])+_0x278e('0x34');return _0x48216d[_0xbfb28]===_0x5224b3[_0x278e('0x2e')]['id'];});if(!_0x333968&&_0x1f4055){_0x333968=_[_0x278e('0x30')](_0x1b81bb[_0x278e('0x35')][_0x1f4055][_0x5224b3[_0x278e('0x31')]+_0x278e('0x36')],function(_0x172b13){return _0x172b13['id']===_0x5224b3[_0x278e('0x2e')]['id'];});}return _0x333968;};exports['saveWaitingNotification']=function(_0x5bb05d,_0x5a4421,_0x60d319,_0x2d671e){_0x5bb05d[_0x278e('0x35')][_0x60d319['id']][_0x2d671e+'WaitingInteractions'][_0x5a4421['message']['id']]={'id':_0x5a4421[_0x278e('0x2e')]['id']};};exports[_0x278e('0x37')]=function(_0x2f7c8a,_0x60def6,_0x56f4d2,_0x547217){delete _0x2f7c8a[_0x278e('0x35')][_0x56f4d2['id']][_0x547217+_0x278e('0x36')][_0x60def6[_0x278e('0x1b')]['id']];};exports[_0x278e('0x38')]=writeLog;