a6832a1a8c5d505b15af002c66263a0bd2c56f95
[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 _0xd3d3=['user:%s','name','user:save','split','\x20interaction','account','notificationShake','body','queue','msg','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','error','[%s][QUEUE]\x20%s','message','notification:%s','save','info','isAgentAvailable','busy','OFFLINE','Pause','PAUSE','hasOwnProperty','CurrentCapacity','Capacity','toUpperCase','\x20MAXCAPACITY','hideNotification','writeLog','../utils','mustache','routing','redis','defaults','localhost','emit','format'];(function(_0x152cc6,_0xce8c){var _0x5cab68=function(_0x16ad44){while(--_0x16ad44){_0x152cc6['push'](_0x152cc6['shift']());}};_0x5cab68(++_0xce8c);}(_0xd3d3,0x19a));var _0x3d3d=function(_0x4a747d,_0x3b747f){_0x4a747d=_0x4a747d-0x0;var _0x3a5b5c=_0xd3d3[_0x4a747d];return _0x3a5b5c;};'use strict';var _=require('lodash');var util=require('util');var utils=require(_0x3d3d('0x0'));var Mustache=require(_0x3d3d('0x1'));var Redis=require('ioredis');var config=require('../../../../../config/environment');var logger=require('../../../../../config/logger')(_0x3d3d('0x2'));config[_0x3d3d('0x3')]=_[_0x3d3d('0x4')](config['redis'],{'host':_0x3d3d('0x5'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x3d3d('0x3')]));function emit(_0x2b6c5a,_0x73eb99,_0x217fc6){io['to'](_0x2b6c5a)[_0x3d3d('0x6')](_0x73eb99,_0x217fc6);}function sendNotification(_0x3cba4c,_0x27915e,_0x4e2a13,_0x29fea2,_0x46aeb7,_0x5d804b){io['to'](util[_0x3d3d('0x7')](_0x3d3d('0x8'),_0x29fea2[_0x3d3d('0x9')]))[_0x3d3d('0x6')](_0x3d3d('0xa'),_0x29fea2);var _0x18b9d0=_0x5d804b||{};var _0x50c9b1=_0x4e2a13[_0x3d3d('0xb')]('.');var _0x47bcdd={'uniqueid':_0x27915e,'channel':_0x50c9b1[0x0],'id':_0x50c9b1[0x1],'title':_0x50c9b1[0x0]+_0x3d3d('0xc'),'interactionId':_0x50c9b1[0x2],'queue':_0x46aeb7?_0x46aeb7[_0x3d3d('0x9')]:null,'sound':_0x18b9d0[_0x3d3d('0xd')]['notificationSound'],'shake':_0x18b9d0[_0x3d3d('0xd')][_0x3d3d('0xe')]};try{if(!_0x18b9d0[_0x3d3d('0xf')]){_0x18b9d0['body']={};}if(_0x46aeb7){_0x18b9d0[_0x3d3d('0xf')][_0x3d3d('0x10')]=_0x46aeb7;}else if(_0x18b9d0[_0x3d3d('0xf')][_0x3d3d('0x10')]){delete _0x18b9d0[_0x3d3d('0xf')][_0x3d3d('0x10')];}_0x47bcdd[_0x3d3d('0x11')]=utils['getMustacheRender'](_0x18b9d0[_0x3d3d('0xd')][_0x3d3d('0x12')],_0x18b9d0);}catch(_0xa1c93b){_0x47bcdd['msg']=_0x3d3d('0x13');logger[_0x3d3d('0x14')](util[_0x3d3d('0x7')](_0x3d3d('0x15'),_0x27915e,_0xa1c93b[_0x3d3d('0x16')]));}io['to'](util[_0x3d3d('0x7')](_0x3d3d('0x8'),_0x29fea2['name']))[_0x3d3d('0x6')](util['format'](_0x3d3d('0x17'),_0x3cba4c?_0x3d3d('0x18'):'remove'),_0x47bcdd);}function writeLog(_0x5ede83,_0x263a3d,_0x2cafd4){return logger[_0x3d3d('0x19')](util[_0x3d3d('0x7')]('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x5ede83,_0x263a3d[_0x3d3d('0x9')],_0x2cafd4));}exports[_0x3d3d('0x1a')]=function(_0x150a7b,_0x4d2fe6,_0x388900,_0x288002){if(_0x4d2fe6[_0x3d3d('0x1b')]){writeLog(_0x150a7b,_0x4d2fe6,'BUSY');return![];}if(!_0x4d2fe6['online']){writeLog(_0x150a7b,_0x4d2fe6,_0x3d3d('0x1c'));return![];}if(_0x4d2fe6[_0x388900+_0x3d3d('0x1d')]){writeLog(_0x150a7b,_0x4d2fe6,_0x3d3d('0x1e'));return![];}if(_0x288002&&_0x4d2fe6[_0x3d3d('0x1f')](_0x388900+'Capacity')&&_0x4d2fe6[_0x3d3d('0x1f')](_0x388900+_0x3d3d('0x20'))){if(_0x4d2fe6[_0x388900+_0x3d3d('0x21')]>0x0&&_0x4d2fe6[_0x388900+_0x3d3d('0x20')]>=_0x4d2fe6[_0x388900+_0x3d3d('0x21')]){writeLog(_0x150a7b,_0x4d2fe6,_0x388900[_0x3d3d('0x22')]()+_0x3d3d('0x23'));return![];}}return!![];};exports['showNotification']=function(_0x49a2b7,_0x4b4e04,_0x566dd8,_0x5bf25b,_0x51c8fb){return sendNotification(!![],_0x49a2b7,_0x4b4e04,_0x566dd8,_0x5bf25b,_0x51c8fb);};exports[_0x3d3d('0x24')]=function(_0x8dadd6,_0x41464f,_0x45a836,_0x3bd2a2,_0xd39657){return sendNotification(![],_0x8dadd6,_0x41464f,_0x45a836,_0x3bd2a2,_0xd39657);};exports[_0x3d3d('0x25')]=writeLog;