5547861f8568397770fcea994737e1cc867f96fa
[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 _0x21c9=['account','notificationSound','body','queue','getMustacheRender','notificationTemplate','msg','I\x20can\x27t\x20render\x20your\x20template','[%s][QUEUE]\x20%s','message','save','info','isAgentAvailable','busy','online','Pause','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','toUpperCase','\x20MAXCAPACITY','showNotification','hideNotification','lodash','util','../../../../../config/logger','routing','defaults','redis','localhost','socket.io-emitter','emit','format','user:%s','user:save','split','\x20interaction','name'];(function(_0x444325,_0x168fb2){var _0x45d573=function(_0x359558){while(--_0x359558){_0x444325['push'](_0x444325['shift']());}};_0x45d573(++_0x168fb2);}(_0x21c9,0x19e));var _0x921c=function(_0x1db674,_0x83f8dd){_0x1db674=_0x1db674-0x0;var _0x1ff680=_0x21c9[_0x1db674];return _0x1ff680;};'use strict';var _=require(_0x921c('0x0'));var util=require(_0x921c('0x1'));var utils=require('../utils');var Mustache=require('mustache');var Redis=require('ioredis');var config=require('../../../../../config/environment');var logger=require(_0x921c('0x2'))(_0x921c('0x3'));config['redis']=_[_0x921c('0x4')](config[_0x921c('0x5')],{'host':_0x921c('0x6'),'port':0x18eb});var io=require(_0x921c('0x7'))(new Redis(config['redis']));function emit(_0x1b0c84,_0x1ab777,_0x496501){io['to'](_0x1b0c84)[_0x921c('0x8')](_0x1ab777,_0x496501);}function sendNotification(_0x382544,_0x457b16,_0x5f5b93,_0xeb39a7,_0x5d0c1e,_0x34a413){io['to'](util[_0x921c('0x9')](_0x921c('0xa'),_0xeb39a7['name']))['emit'](_0x921c('0xb'),_0xeb39a7);var _0x169d0a=_0x34a413||{};var _0xd5c978=_0x5f5b93[_0x921c('0xc')]('.');var _0x29a7c1={'uniqueid':_0x457b16,'channel':_0xd5c978[0x0],'id':_0xd5c978[0x1],'title':_0xd5c978[0x0]+_0x921c('0xd'),'interactionId':_0xd5c978[0x2],'queue':_0x5d0c1e?_0x5d0c1e[_0x921c('0xe')]:null,'sound':_0x169d0a[_0x921c('0xf')][_0x921c('0x10')],'shake':_0x169d0a['account']['notificationShake']};try{if(!_0x169d0a[_0x921c('0x11')]){_0x169d0a[_0x921c('0x11')]={};}if(_0x5d0c1e){_0x169d0a[_0x921c('0x11')][_0x921c('0x12')]=_0x5d0c1e;}else if(_0x169d0a[_0x921c('0x11')]['queue']){delete _0x169d0a[_0x921c('0x11')][_0x921c('0x12')];}_0x29a7c1['msg']=utils[_0x921c('0x13')](_0x169d0a['account'][_0x921c('0x14')],_0x169d0a);}catch(_0x37c083){_0x29a7c1[_0x921c('0x15')]=_0x921c('0x16');logger['error'](util['format'](_0x921c('0x17'),_0x457b16,_0x37c083[_0x921c('0x18')]));}io['to'](util[_0x921c('0x9')]('user:%s',_0xeb39a7[_0x921c('0xe')]))['emit'](util[_0x921c('0x9')]('notification:%s',_0x382544?_0x921c('0x19'):'remove'),_0x29a7c1);}function writeLog(_0x269383,_0x3de1ba,_0x270e2c){return logger[_0x921c('0x1a')](util[_0x921c('0x9')]('[%s][QUEUE][AGENT:%s][STATUS:%s]',_0x269383,_0x3de1ba[_0x921c('0xe')],_0x270e2c));}exports[_0x921c('0x1b')]=function(_0x572512,_0xc06e1d,_0x17178e,_0xc82ef4){if(_0xc06e1d[_0x921c('0x1c')]){writeLog(_0x572512,_0xc06e1d,'BUSY');return![];}if(!_0xc06e1d[_0x921c('0x1d')]){writeLog(_0x572512,_0xc06e1d,'OFFLINE');return![];}if(_0xc06e1d[_0x17178e+_0x921c('0x1e')]){writeLog(_0x572512,_0xc06e1d,_0x921c('0x1f'));return![];}if(_0xc82ef4&&_0xc06e1d[_0x921c('0x20')](_0x17178e+_0x921c('0x21'))&&_0xc06e1d[_0x921c('0x20')](_0x17178e+_0x921c('0x22'))){if(_0xc06e1d[_0x17178e+'Capacity']>0x0&&_0xc06e1d[_0x17178e+_0x921c('0x22')]>=_0xc06e1d[_0x17178e+_0x921c('0x21')]){writeLog(_0x572512,_0xc06e1d,_0x17178e[_0x921c('0x23')]()+_0x921c('0x24'));return![];}}return!![];};exports[_0x921c('0x25')]=function(_0x4a8ebc,_0x5b32f0,_0x239f2d,_0x1d356b,_0x36cf2e){return sendNotification(!![],_0x4a8ebc,_0x5b32f0,_0x239f2d,_0x1d356b,_0x36cf2e);};exports[_0x921c('0x26')]=function(_0x4ffd88,_0x2564b5,_0x3e4481,_0x352df7,_0x5c8541){return sendNotification(![],_0x4ffd88,_0x2564b5,_0x3e4481,_0x352df7,_0x5c8541);};exports['writeLog']=writeLog;