Built motion from commit e1760111.|2.6.18
[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 _0x974e=['[%s][QUEUE]\x20%s','message','save','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY','online','OFFLINE','Pause','PAUSE','hasOwnProperty','CurrentCapacity','Capacity','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','some','channel','QueuesWaitingInteractions','capitalize','InteractionId','agents','WaitingInteractions','saveWaitingNotification','removeWaitingNotification','lodash','util','ioredis','../../../../../config/environment','../../../../../config/logger','routing','redis','defaults','format','user:%s','name','emit','user:save','split','\x20interaction','account','notificationSound','notificationShake','body','queue','msg','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error'];(function(_0x2513eb,_0x2a2231){var _0x564ca0=function(_0x4b0d5f){while(--_0x4b0d5f){_0x2513eb['push'](_0x2513eb['shift']());}};_0x564ca0(++_0x2a2231);}(_0x974e,0x190));var _0xe974=function(_0x4565bf,_0x5ad9d6){_0x4565bf=_0x4565bf-0x0;var _0x5610ba=_0x974e[_0x4565bf];return _0x5610ba;};'use strict';var _=require(_0xe974('0x0'));var util=require(_0xe974('0x1'));var utils=require('../utils');var Redis=require(_0xe974('0x2'));var config=require(_0xe974('0x3'));var logger=require(_0xe974('0x4'))(_0xe974('0x5'));config[_0xe974('0x6')]=_[_0xe974('0x7')](config['redis'],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xe974('0x6')]));function sendNotification(_0x5bcccc,_0x5601dc,_0x3305ba,_0x5380a4,_0x11cedb,_0x231a96){io['to'](util[_0xe974('0x8')](_0xe974('0x9'),_0x5380a4[_0xe974('0xa')]))[_0xe974('0xb')](_0xe974('0xc'),_0x5380a4);var _0x1e822c=_0x231a96||{};var _0x410965=_0x3305ba[_0xe974('0xd')]('.');var _0x52137a={'uniqueid':_0x5601dc,'channel':_0x410965[0x0],'id':_0x410965[0x1],'title':_0x410965[0x0]+_0xe974('0xe'),'interactionId':_0x410965[0x2],'queue':_0x11cedb?_0x11cedb['name']:null,'sound':_0x1e822c[_0xe974('0xf')][_0xe974('0x10')],'shake':_0x1e822c['account'][_0xe974('0x11')]};try{if(!_0x1e822c[_0xe974('0x12')]){_0x1e822c[_0xe974('0x12')]={};}if(_0x11cedb){_0x1e822c['body'][_0xe974('0x13')]=_0x11cedb;}else if(_0x1e822c[_0xe974('0x12')][_0xe974('0x13')]){delete _0x1e822c[_0xe974('0x12')]['queue'];}_0x52137a[_0xe974('0x14')]=utils['getMustacheRender'](_0x1e822c['account'][_0xe974('0x15')],_0x1e822c);}catch(_0x4b8e85){_0x52137a[_0xe974('0x14')]=_0xe974('0x16');logger[_0xe974('0x17')](util[_0xe974('0x8')](_0xe974('0x18'),_0x5601dc,_0x4b8e85[_0xe974('0x19')]));}io['to'](util[_0xe974('0x8')](_0xe974('0x9'),_0x5380a4[_0xe974('0xa')]))[_0xe974('0xb')](util[_0xe974('0x8')]('notification:%s',_0x5bcccc?_0xe974('0x1a'):'remove'),_0x52137a);}function writeLog(_0x5874bf,_0x443425,_0x59abeb){return logger[_0xe974('0x1b')](util[_0xe974('0x8')](_0xe974('0x1c'),_0x5874bf,_0x443425[_0xe974('0xa')],_0x59abeb));}exports[_0xe974('0x1d')]=function(_0x470e09,_0x171de5,_0xdc08fa,_0x3cfabd){if(_0x171de5[_0xe974('0x1e')]){writeLog(_0x470e09,_0x171de5,_0xe974('0x1f'));return![];}if(!_0x171de5[_0xe974('0x20')]){writeLog(_0x470e09,_0x171de5,_0xe974('0x21'));return![];}if(_0x171de5[_0xdc08fa+_0xe974('0x22')]){writeLog(_0x470e09,_0x171de5,_0xe974('0x23'));return![];}if(_0x3cfabd&&_0x171de5[_0xe974('0x24')](_0xdc08fa+'Capacity')&&_0x171de5[_0xe974('0x24')](_0xdc08fa+_0xe974('0x25'))){if(_0x171de5[_0xdc08fa+'Capacity']>0x0&&_0x171de5[_0xdc08fa+'CurrentCapacity']>=_0x171de5[_0xdc08fa+_0xe974('0x26')]){writeLog(_0x470e09,_0x171de5,_0xdc08fa['toUpperCase']()+'\x20MAXCAPACITY');return![];}}return!![];};exports[_0xe974('0x27')]=function(_0x195734,_0x3c55f6,_0x1bb268,_0x318496,_0x27a89f){return sendNotification(!![],_0x195734,_0x3c55f6,_0x1bb268,_0x318496,_0x27a89f);};exports[_0xe974('0x28')]=function(_0x45e62e,_0x135614,_0x3e41f7,_0xc34e48,_0x37ebd0){return sendNotification(![],_0x45e62e,_0x135614,_0x3e41f7,_0xc34e48,_0x37ebd0);};exports[_0xe974('0x29')]=function(_0x1409b2,_0x7214d5,_0x468c36){var _0x11961f=_0x7214d5[_0xe974('0x2a')][_0xe974('0x2b')];if(!_0x11961f&&_0x468c36){_0x11961f=_0x468c36['id'];}var _0xcb0943=_[_0xe974('0x2c')](_0x1409b2[_0x7214d5[_0xe974('0x2d')]+_0xe974('0x2e')],function(_0x41118d){var _0x14032c=_[_0xe974('0x2f')](_0x7214d5['channel'])+_0xe974('0x30');return _0x41118d[_0x14032c]===_0x7214d5[_0xe974('0x2a')]['id'];});if(!_0xcb0943&&_0x11961f){_0xcb0943=_[_0xe974('0x2c')](_0x1409b2[_0xe974('0x31')][_0x11961f][_0x7214d5['channel']+_0xe974('0x32')],function(_0x173680){return _0x173680['id']===_0x7214d5[_0xe974('0x2a')]['id'];});}return _0xcb0943;};exports[_0xe974('0x33')]=function(_0x2b0cbe,_0x1dd4ed,_0x101cef,_0x4c309b){_0x2b0cbe['agents'][_0x101cef['id']][_0x4c309b+_0xe974('0x32')][_0x1dd4ed[_0xe974('0x19')]['id']]={'id':_0x1dd4ed[_0xe974('0x2a')]['id']};};exports[_0xe974('0x34')]=function(_0x1e65d8,_0x18db3b,_0x3470af,_0x166957){delete _0x1e65d8[_0xe974('0x31')][_0x3470af['id']][_0x166957+_0xe974('0x32')][_0x18db3b[_0xe974('0x19')]['id']];};exports['writeLog']=writeLog;