Built motion from commit 8356fca3.|2.6.19
[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 _0x5a93=['hideNotification','interaction','UserId','some','channel','capitalize','InteractionId','agents','saveWaitingNotification','WaitingInteractions','writeLog','util','ioredis','../../../../../config/environment','redis','defaults','socket.io-emitter','format','user:%s','name','emit','user:save','split','account','notificationSound','body','queue','msg','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','message','notification:%s','save','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','toUpperCase','\x20MAXCAPACITY'];(function(_0x403db1,_0x59018e){var _0x47c48f=function(_0x1b663c){while(--_0x1b663c){_0x403db1['push'](_0x403db1['shift']());}};_0x47c48f(++_0x59018e);}(_0x5a93,0xf6));var _0x35a9=function(_0x29e8bf,_0x5bf617){_0x29e8bf=_0x29e8bf-0x0;var _0x439087=_0x5a93[_0x29e8bf];return _0x439087;};'use strict';var _=require('lodash');var util=require(_0x35a9('0x0'));var utils=require('../utils');var Redis=require(_0x35a9('0x1'));var config=require(_0x35a9('0x2'));var logger=require('../../../../../config/logger')('routing');config[_0x35a9('0x3')]=_[_0x35a9('0x4')](config[_0x35a9('0x3')],{'host':'localhost','port':0x18eb});var io=require(_0x35a9('0x5'))(new Redis(config[_0x35a9('0x3')]));function sendNotification(_0x2e8a14,_0x354490,_0x271228,_0x45e6f7,_0x71d143,_0x22d770){io['to'](util[_0x35a9('0x6')](_0x35a9('0x7'),_0x45e6f7[_0x35a9('0x8')]))[_0x35a9('0x9')](_0x35a9('0xa'),_0x45e6f7);var _0x2dd7f4=_0x22d770||{};var _0xeca85e=_0x271228[_0x35a9('0xb')]('.');var _0x1e0958={'uniqueid':_0x354490,'channel':_0xeca85e[0x0],'id':_0xeca85e[0x1],'title':_0xeca85e[0x0]+'\x20interaction','interactionId':_0xeca85e[0x2],'queue':_0x71d143?_0x71d143[_0x35a9('0x8')]:null,'sound':_0x2dd7f4[_0x35a9('0xc')][_0x35a9('0xd')],'shake':_0x2dd7f4[_0x35a9('0xc')]['notificationShake']};try{if(!_0x2dd7f4[_0x35a9('0xe')]){_0x2dd7f4[_0x35a9('0xe')]={};}if(_0x71d143){_0x2dd7f4[_0x35a9('0xe')][_0x35a9('0xf')]=_0x71d143;}else if(_0x2dd7f4['body'][_0x35a9('0xf')]){delete _0x2dd7f4[_0x35a9('0xe')][_0x35a9('0xf')];}_0x1e0958[_0x35a9('0x10')]=utils['getMustacheRender'](_0x2dd7f4[_0x35a9('0xc')][_0x35a9('0x11')],_0x2dd7f4);}catch(_0x21b9f1){_0x1e0958['msg']=_0x35a9('0x12');logger[_0x35a9('0x13')](util[_0x35a9('0x6')](_0x35a9('0x14'),_0x354490,_0x21b9f1[_0x35a9('0x15')]));}io['to'](util[_0x35a9('0x6')]('user:%s',_0x45e6f7[_0x35a9('0x8')]))[_0x35a9('0x9')](util[_0x35a9('0x6')](_0x35a9('0x16'),_0x2e8a14?_0x35a9('0x17'):'remove'),_0x1e0958);}function writeLog(_0xa19efe,_0x4d7f2b,_0x354367){return logger[_0x35a9('0x18')](util[_0x35a9('0x6')](_0x35a9('0x19'),_0xa19efe,_0x4d7f2b[_0x35a9('0x8')],_0x354367));}exports[_0x35a9('0x1a')]=function(_0x2bf9ce,_0x26f49a,_0x27032e,_0x5eb97d){if(_0x26f49a[_0x35a9('0x1b')]){writeLog(_0x2bf9ce,_0x26f49a,_0x35a9('0x1c'));return![];}if(!_0x26f49a['online']){writeLog(_0x2bf9ce,_0x26f49a,'OFFLINE');return![];}if(_0x26f49a[_0x27032e+_0x35a9('0x1d')]){writeLog(_0x2bf9ce,_0x26f49a,_0x35a9('0x1e'));return![];}if(_0x5eb97d&&_0x26f49a[_0x35a9('0x1f')](_0x27032e+_0x35a9('0x20'))&&_0x26f49a[_0x35a9('0x1f')](_0x27032e+'CurrentCapacity')){if(_0x26f49a[_0x27032e+_0x35a9('0x20')]>0x0&&_0x26f49a[_0x27032e+_0x35a9('0x21')]>=_0x26f49a[_0x27032e+_0x35a9('0x20')]){writeLog(_0x2bf9ce,_0x26f49a,_0x27032e[_0x35a9('0x22')]()+_0x35a9('0x23'));return![];}}return!![];};exports['showNotification']=function(_0x484212,_0x5dfc9f,_0x2de1e4,_0x555746,_0x3119a6){return sendNotification(!![],_0x484212,_0x5dfc9f,_0x2de1e4,_0x555746,_0x3119a6);};exports[_0x35a9('0x24')]=function(_0x5e3631,_0x22835a,_0x4cd0b3,_0x1fc384,_0x42b5bd){return sendNotification(![],_0x5e3631,_0x22835a,_0x4cd0b3,_0x1fc384,_0x42b5bd);};exports['checkWaitingNotifications']=function(_0x534455,_0x16ee46,_0x207444){var _0x3f90fa=_0x16ee46[_0x35a9('0x25')][_0x35a9('0x26')];if(!_0x3f90fa&&_0x207444){_0x3f90fa=_0x207444['id'];}var _0x15ac13=_[_0x35a9('0x27')](_0x534455[_0x16ee46[_0x35a9('0x28')]+'QueuesWaitingInteractions'],function(_0x39fa5a){var _0x23abfd=_[_0x35a9('0x29')](_0x16ee46[_0x35a9('0x28')])+_0x35a9('0x2a');return _0x39fa5a[_0x23abfd]===_0x16ee46[_0x35a9('0x25')]['id'];});if(!_0x15ac13&&_0x3f90fa&&_0x534455['agents'][_0x3f90fa]){_0x15ac13=_[_0x35a9('0x27')](_0x534455[_0x35a9('0x2b')][_0x3f90fa][_0x16ee46[_0x35a9('0x28')]+'WaitingInteractions'],function(_0x37bd4c){return _0x37bd4c['id']===_0x16ee46['interaction']['id'];});}return _0x15ac13;};exports[_0x35a9('0x2c')]=function(_0x40ea7a,_0xd53b5d,_0xc07d46,_0x1445f1){if(_0xc07d46&&_0xc07d46['id']&&_0x40ea7a[_0x35a9('0x2b')]&&_0x40ea7a['agents'][_0xc07d46['id']]){_0x40ea7a['agents'][_0xc07d46['id']][_0x1445f1+_0x35a9('0x2d')][_0xd53b5d[_0x35a9('0x15')]['id']]={'id':_0xd53b5d['interaction']['id']};}};exports['removeWaitingNotification']=function(_0x294cfb,_0x569f7f,_0x5d4504,_0x58831e){if(_0x5d4504&&_0x5d4504['id']&&_0x294cfb[_0x35a9('0x2b')]&&_0x294cfb[_0x35a9('0x2b')][_0x5d4504['id']]){delete _0x294cfb['agents'][_0x5d4504['id']][_0x58831e+_0x35a9('0x2d')][_0x569f7f[_0x35a9('0x15')]['id']];}};exports[_0x35a9('0x2e')]=writeLog;