6c7e907ea31de501bd30c14ba3e030692f7680bb
[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 _0x4ba0=['online','OFFLINE','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','writeLog','lodash','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','routing','defaults','socket.io-emitter','emit','user:%s','name','user:save','split','\x20interaction','notificationShake','body','queue','getMustacheRender','account','I\x20can\x27t\x20render\x20your\x20template','error','message','format','notification:%s','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY'];(function(_0x3d6d05,_0x16c8b8){var _0x288baf=function(_0x2e0179){while(--_0x2e0179){_0x3d6d05['push'](_0x3d6d05['shift']());}};_0x288baf(++_0x16c8b8);}(_0x4ba0,0xe0));var _0x04ba=function(_0xbd08b4,_0x4790ed){_0xbd08b4=_0xbd08b4-0x0;var _0x314f1e=_0x4ba0[_0xbd08b4];return _0x314f1e;};'use strict';var _=require(_0x04ba('0x0'));var util=require('util');var utils=require(_0x04ba('0x1'));var Mustache=require('mustache');var Redis=require(_0x04ba('0x2'));var config=require(_0x04ba('0x3'));var logger=require(_0x04ba('0x4'))(_0x04ba('0x5'));config['redis']=_[_0x04ba('0x6')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x04ba('0x7'))(new Redis(config['redis']));function emit(_0x1ae533,_0x3ec930,_0x1e9dc8){io['to'](_0x1ae533)[_0x04ba('0x8')](_0x3ec930,_0x1e9dc8);}function sendNotification(_0x42c83a,_0x52f2df,_0x4a182c,_0x30a788,_0x4a9b2e,_0x15e6d3){io['to'](util['format'](_0x04ba('0x9'),_0x30a788[_0x04ba('0xa')]))['emit'](_0x04ba('0xb'),_0x30a788);var _0x178931=_0x15e6d3||{};var _0x97c39d=_0x4a182c[_0x04ba('0xc')]('.');var _0x15193c={'uniqueid':_0x52f2df,'channel':_0x97c39d[0x0],'id':_0x97c39d[0x1],'title':_0x97c39d[0x0]+_0x04ba('0xd'),'interactionId':_0x97c39d[0x2],'queue':_0x4a9b2e?_0x4a9b2e[_0x04ba('0xa')]:null,'sound':_0x178931['account']['notificationSound'],'shake':_0x178931['account'][_0x04ba('0xe')]};try{if(!_0x178931['body']){_0x178931['body']={};}if(_0x4a9b2e){_0x178931[_0x04ba('0xf')][_0x04ba('0x10')]=_0x4a9b2e;}else if(_0x178931['body']['queue']){delete _0x178931['body'][_0x04ba('0x10')];}_0x15193c['msg']=utils[_0x04ba('0x11')](_0x178931[_0x04ba('0x12')]['notificationTemplate'],_0x178931);}catch(_0x5afc2c){_0x15193c['msg']=_0x04ba('0x13');logger[_0x04ba('0x14')](util['format']('[%s][QUEUE]\x20%s',_0x52f2df,_0x5afc2c[_0x04ba('0x15')]));}io['to'](util[_0x04ba('0x16')](_0x04ba('0x9'),_0x30a788[_0x04ba('0xa')]))[_0x04ba('0x8')](util[_0x04ba('0x16')](_0x04ba('0x17'),_0x42c83a?'save':'remove'),_0x15193c);}function writeLog(_0x4b4872,_0x47d699,_0x152589){return logger['info'](util['format'](_0x04ba('0x18'),_0x4b4872,_0x47d699[_0x04ba('0xa')],_0x152589));}exports[_0x04ba('0x19')]=function(_0x26584e,_0x5dcf2a,_0x2ec67d,_0x24f7e9){if(_0x5dcf2a[_0x04ba('0x1a')]){writeLog(_0x26584e,_0x5dcf2a,_0x04ba('0x1b'));return![];}if(!_0x5dcf2a[_0x04ba('0x1c')]){writeLog(_0x26584e,_0x5dcf2a,_0x04ba('0x1d'));return![];}if(_0x5dcf2a[_0x2ec67d+_0x04ba('0x1e')]){writeLog(_0x26584e,_0x5dcf2a,_0x04ba('0x1f'));return![];}if(_0x24f7e9&&_0x5dcf2a[_0x04ba('0x20')](_0x2ec67d+_0x04ba('0x21'))&&_0x5dcf2a[_0x04ba('0x20')](_0x2ec67d+_0x04ba('0x22'))){if(_0x5dcf2a[_0x2ec67d+_0x04ba('0x21')]>0x0&&_0x5dcf2a[_0x2ec67d+_0x04ba('0x22')]>=_0x5dcf2a[_0x2ec67d+'Capacity']){writeLog(_0x26584e,_0x5dcf2a,_0x2ec67d['toUpperCase']()+'\x20MAXCAPACITY');return![];}}return!![];};exports['showNotification']=function(_0x57973d,_0x5437e7,_0x52d6eb,_0x53ff0b,_0x57182d){return sendNotification(!![],_0x57973d,_0x5437e7,_0x52d6eb,_0x53ff0b,_0x57182d);};exports['hideNotification']=function(_0x51cdbd,_0x1cacd2,_0x4d046d,_0x547235,_0x22dff6){return sendNotification(![],_0x51cdbd,_0x1cacd2,_0x4d046d,_0x547235,_0x22dff6);};exports[_0x04ba('0x23')]=writeLog;