Built motion from commit 5293bb2a.|2.6.30
[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 _0xecf5=['\x20interaction','name','account','notificationSound','body','queue','msg','getMustacheRender','notificationTemplate','error','[%s][QUEUE]\x20%s','format','user:%s','emit','notification:%s','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','busy','online','OFFLINE','Pause','PAUSE','hasOwnProperty','CurrentCapacity','Capacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','some','channel','capitalize','InteractionId','interaction','agents','WaitingInteractions','message','removeWaitingNotification','util','../utils','../../../../../config/environment','../../../../../config/logger','redis','localhost','socket.io-emitter'];(function(_0x12fc8d,_0x19ee33){var _0x3f9d04=function(_0x52e51c){while(--_0x52e51c){_0x12fc8d['push'](_0x12fc8d['shift']());}};_0x3f9d04(++_0x19ee33);}(_0xecf5,0x1c5));var _0x5ecf=function(_0x40ea4b,_0x2c6a87){_0x40ea4b=_0x40ea4b-0x0;var _0x41a42b=_0xecf5[_0x40ea4b];return _0x41a42b;};'use strict';var _=require('lodash');var util=require(_0x5ecf('0x0'));var utils=require(_0x5ecf('0x1'));var Redis=require('ioredis');var config=require(_0x5ecf('0x2'));var logger=require(_0x5ecf('0x3'))('routing');config['redis']=_['defaults'](config[_0x5ecf('0x4')],{'host':_0x5ecf('0x5'),'port':0x18eb});var io=require(_0x5ecf('0x6'))(new Redis(config[_0x5ecf('0x4')]));function sendNotification(_0x22a122,_0x2d5a17,_0x4af53e,_0x4972e3,_0x5d89af,_0x99e0d1){var _0x1d4cad=_0x99e0d1||{};var _0x3111c1=_0x4af53e['split']('.');var _0x28257a={'uniqueid':_0x2d5a17,'channel':_0x3111c1[0x0],'id':_0x3111c1[0x1],'title':_0x3111c1[0x0]+_0x5ecf('0x7'),'interactionId':_0x3111c1[0x2],'queue':_0x5d89af?_0x5d89af[_0x5ecf('0x8')]:null,'sound':_0x1d4cad[_0x5ecf('0x9')][_0x5ecf('0xa')],'shake':_0x1d4cad['account']['notificationShake']};try{if(!_0x1d4cad[_0x5ecf('0xb')]){_0x1d4cad[_0x5ecf('0xb')]={};}if(_0x5d89af){_0x1d4cad[_0x5ecf('0xb')][_0x5ecf('0xc')]=_0x5d89af;}else if(_0x1d4cad[_0x5ecf('0xb')]['queue']){delete _0x1d4cad['body'][_0x5ecf('0xc')];}_0x28257a[_0x5ecf('0xd')]=utils[_0x5ecf('0xe')](_0x1d4cad['account'][_0x5ecf('0xf')],_0x1d4cad);}catch(_0x9ead61){_0x28257a['msg']='I\x20can\x27t\x20render\x20your\x20template';logger[_0x5ecf('0x10')](util['format'](_0x5ecf('0x11'),_0x2d5a17,_0x9ead61['message']));}io['to'](util[_0x5ecf('0x12')](_0x5ecf('0x13'),_0x4972e3[_0x5ecf('0x8')]))[_0x5ecf('0x14')](util['format'](_0x5ecf('0x15'),_0x22a122?'save':'remove'),_0x28257a);}function writeLog(_0x190f90,_0x2e408e,_0x2b5ad9){return logger[_0x5ecf('0x16')](util[_0x5ecf('0x12')](_0x5ecf('0x17'),_0x190f90,_0x2e408e[_0x5ecf('0x8')],_0x2b5ad9));}exports['isAgentAvailable']=function(_0x59fe12,_0x35a74a,_0x49fff9,_0x13d928){if(_0x35a74a[_0x5ecf('0x18')]){writeLog(_0x59fe12,_0x35a74a,'BUSY');return![];}if(!_0x35a74a[_0x5ecf('0x19')]){writeLog(_0x59fe12,_0x35a74a,_0x5ecf('0x1a'));return![];}if(_0x35a74a[_0x49fff9+_0x5ecf('0x1b')]){writeLog(_0x59fe12,_0x35a74a,_0x5ecf('0x1c'));return![];}if(_0x13d928&&_0x35a74a['hasOwnProperty'](_0x49fff9+'Capacity')&&_0x35a74a[_0x5ecf('0x1d')](_0x49fff9+_0x5ecf('0x1e'))){if(_0x35a74a[_0x49fff9+_0x5ecf('0x1f')]>0x0&&_0x35a74a[_0x49fff9+'CurrentCapacity']>=_0x35a74a[_0x49fff9+_0x5ecf('0x1f')]){writeLog(_0x59fe12,_0x35a74a,_0x49fff9[_0x5ecf('0x20')]()+_0x5ecf('0x21'));return![];}}return!![];};exports[_0x5ecf('0x22')]=function(_0x3b6390,_0x44f18d,_0x15b163,_0x137e90,_0x11d12a){return sendNotification(!![],_0x3b6390,_0x44f18d,_0x15b163,_0x137e90,_0x11d12a);};exports[_0x5ecf('0x23')]=function(_0x1786c7,_0x1a4f14,_0x133738,_0x302562,_0x1273ce){return sendNotification(![],_0x1786c7,_0x1a4f14,_0x133738,_0x302562,_0x1273ce);};exports[_0x5ecf('0x24')]=function(_0x6dd7b4,_0x50597b,_0x1a2677){var _0x5831f8=_0x50597b['interaction']['UserId'];if(!_0x5831f8&&_0x1a2677){_0x5831f8=_0x1a2677['id'];}var _0x460bb2=_[_0x5ecf('0x25')](_0x6dd7b4[_0x50597b[_0x5ecf('0x26')]+'QueuesWaitingInteractions'],function(_0x1bf9e7){var _0x131531=_[_0x5ecf('0x27')](_0x50597b[_0x5ecf('0x26')])+_0x5ecf('0x28');return _0x1bf9e7[_0x131531]===_0x50597b[_0x5ecf('0x29')]['id'];});if(!_0x460bb2&&_0x5831f8&&_0x6dd7b4['agents'][_0x5831f8]){_0x460bb2=_[_0x5ecf('0x25')](_0x6dd7b4[_0x5ecf('0x2a')][_0x5831f8][_0x50597b[_0x5ecf('0x26')]+'WaitingInteractions'],function(_0x232586){return _0x232586['id']===_0x50597b['interaction']['id'];});}return _0x460bb2;};exports['saveWaitingNotification']=function(_0x256f79,_0x17c38b,_0x43685d,_0x57953b){if(_0x43685d&&_0x43685d['id']&&_0x256f79[_0x5ecf('0x2a')]&&_0x256f79[_0x5ecf('0x2a')][_0x43685d['id']]){_0x256f79['agents'][_0x43685d['id']][_0x57953b+_0x5ecf('0x2b')][_0x17c38b[_0x5ecf('0x2c')]['id']]={'id':_0x17c38b[_0x5ecf('0x29')]['id']};}};exports[_0x5ecf('0x2d')]=function(_0x59e1c2,_0x300da7,_0x16b3de,_0x4f66ff){if(_0x16b3de&&_0x16b3de['id']&&_0x59e1c2[_0x5ecf('0x2a')]&&_0x59e1c2[_0x5ecf('0x2a')][_0x16b3de['id']]){delete _0x59e1c2['agents'][_0x16b3de['id']][_0x4f66ff+_0x5ecf('0x2b')][_0x300da7[_0x5ecf('0x2c')]['id']];}};exports['writeLog']=writeLog;