Built motion from commit 64440dd5.|2.6.29
[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 _0xba87=['OFFLINE','Pause','hasOwnProperty','Capacity','CurrentCapacity','\x20MAXCAPACITY','showNotification','hideNotification','checkWaitingNotifications','interaction','UserId','some','QueuesWaitingInteractions','capitalize','InteractionId','channel','WaitingInteractions','saveWaitingNotification','agents','removeWaitingNotification','writeLog','lodash','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','routing','defaults','redis','localhost','socket.io-emitter','name','notificationSound','account','notificationShake','body','queue','notificationTemplate','msg','format','message','user:%s','notification:%s','save','remove','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','isAgentAvailable','busy','BUSY','online'];(function(_0x3517d9,_0x1e6703){var _0x29a2f4=function(_0x29efb9){while(--_0x29efb9){_0x3517d9['push'](_0x3517d9['shift']());}};_0x29a2f4(++_0x1e6703);}(_0xba87,0xe1));var _0x7ba8=function(_0x4ef34e,_0x11ac32){_0x4ef34e=_0x4ef34e-0x0;var _0x3a6f82=_0xba87[_0x4ef34e];return _0x3a6f82;};'use strict';var _=require(_0x7ba8('0x0'));var util=require('util');var utils=require(_0x7ba8('0x1'));var Redis=require(_0x7ba8('0x2'));var config=require(_0x7ba8('0x3'));var logger=require(_0x7ba8('0x4'))(_0x7ba8('0x5'));config['redis']=_[_0x7ba8('0x6')](config[_0x7ba8('0x7')],{'host':_0x7ba8('0x8'),'port':0x18eb});var io=require(_0x7ba8('0x9'))(new Redis(config[_0x7ba8('0x7')]));function sendNotification(_0x3b3533,_0x2d99f9,_0x5a94bc,_0x2584cc,_0x3e8626,_0x39dc36){var _0x2e106f=_0x39dc36||{};var _0x1fdc76=_0x5a94bc['split']('.');var _0x5577a7={'uniqueid':_0x2d99f9,'channel':_0x1fdc76[0x0],'id':_0x1fdc76[0x1],'title':_0x1fdc76[0x0]+'\x20interaction','interactionId':_0x1fdc76[0x2],'queue':_0x3e8626?_0x3e8626[_0x7ba8('0xa')]:null,'sound':_0x2e106f['account'][_0x7ba8('0xb')],'shake':_0x2e106f[_0x7ba8('0xc')][_0x7ba8('0xd')]};try{if(!_0x2e106f[_0x7ba8('0xe')]){_0x2e106f['body']={};}if(_0x3e8626){_0x2e106f[_0x7ba8('0xe')][_0x7ba8('0xf')]=_0x3e8626;}else if(_0x2e106f[_0x7ba8('0xe')][_0x7ba8('0xf')]){delete _0x2e106f['body'][_0x7ba8('0xf')];}_0x5577a7['msg']=utils['getMustacheRender'](_0x2e106f[_0x7ba8('0xc')][_0x7ba8('0x10')],_0x2e106f);}catch(_0x39e7c9){_0x5577a7[_0x7ba8('0x11')]='I\x20can\x27t\x20render\x20your\x20template';logger['error'](util[_0x7ba8('0x12')]('[%s][QUEUE]\x20%s',_0x2d99f9,_0x39e7c9[_0x7ba8('0x13')]));}io['to'](util[_0x7ba8('0x12')](_0x7ba8('0x14'),_0x2584cc[_0x7ba8('0xa')]))['emit'](util[_0x7ba8('0x12')](_0x7ba8('0x15'),_0x3b3533?_0x7ba8('0x16'):_0x7ba8('0x17')),_0x5577a7);}function writeLog(_0x3061fc,_0x52a898,_0x271da7){return logger[_0x7ba8('0x18')](util[_0x7ba8('0x12')](_0x7ba8('0x19'),_0x3061fc,_0x52a898[_0x7ba8('0xa')],_0x271da7));}exports[_0x7ba8('0x1a')]=function(_0x7c68e1,_0x1a86a6,_0x5bc415,_0x55c276){if(_0x1a86a6[_0x7ba8('0x1b')]){writeLog(_0x7c68e1,_0x1a86a6,_0x7ba8('0x1c'));return![];}if(!_0x1a86a6[_0x7ba8('0x1d')]){writeLog(_0x7c68e1,_0x1a86a6,_0x7ba8('0x1e'));return![];}if(_0x1a86a6[_0x5bc415+_0x7ba8('0x1f')]){writeLog(_0x7c68e1,_0x1a86a6,'PAUSE');return![];}if(_0x55c276&&_0x1a86a6['hasOwnProperty'](_0x5bc415+'Capacity')&&_0x1a86a6[_0x7ba8('0x20')](_0x5bc415+'CurrentCapacity')){if(_0x1a86a6[_0x5bc415+_0x7ba8('0x21')]>0x0&&_0x1a86a6[_0x5bc415+_0x7ba8('0x22')]>=_0x1a86a6[_0x5bc415+_0x7ba8('0x21')]){writeLog(_0x7c68e1,_0x1a86a6,_0x5bc415['toUpperCase']()+_0x7ba8('0x23'));return![];}}return!![];};exports[_0x7ba8('0x24')]=function(_0x52f387,_0x2ad996,_0x27096f,_0x45a2d9,_0x16799a){return sendNotification(!![],_0x52f387,_0x2ad996,_0x27096f,_0x45a2d9,_0x16799a);};exports[_0x7ba8('0x25')]=function(_0x3a05e7,_0x28f247,_0x3bc762,_0x30ef65,_0x1628b8){return sendNotification(![],_0x3a05e7,_0x28f247,_0x3bc762,_0x30ef65,_0x1628b8);};exports[_0x7ba8('0x26')]=function(_0x1efb58,_0x52dc05,_0x4d81ba){var _0x1a2321=_0x52dc05[_0x7ba8('0x27')][_0x7ba8('0x28')];if(!_0x1a2321&&_0x4d81ba){_0x1a2321=_0x4d81ba['id'];}var _0x132d0c=_[_0x7ba8('0x29')](_0x1efb58[_0x52dc05['channel']+_0x7ba8('0x2a')],function(_0xba4f0a){var _0x2a75b6=_[_0x7ba8('0x2b')](_0x52dc05['channel'])+_0x7ba8('0x2c');return _0xba4f0a[_0x2a75b6]===_0x52dc05['interaction']['id'];});if(!_0x132d0c&&_0x1a2321&&_0x1efb58['agents'][_0x1a2321]){_0x132d0c=_['some'](_0x1efb58['agents'][_0x1a2321][_0x52dc05[_0x7ba8('0x2d')]+_0x7ba8('0x2e')],function(_0x1cf518){return _0x1cf518['id']===_0x52dc05[_0x7ba8('0x27')]['id'];});}return _0x132d0c;};exports[_0x7ba8('0x2f')]=function(_0x3cf335,_0x344603,_0x4f061e,_0x54841f){if(_0x4f061e&&_0x4f061e['id']&&_0x3cf335['agents']&&_0x3cf335[_0x7ba8('0x30')][_0x4f061e['id']]){_0x3cf335[_0x7ba8('0x30')][_0x4f061e['id']][_0x54841f+_0x7ba8('0x2e')][_0x344603[_0x7ba8('0x13')]['id']]={'id':_0x344603['interaction']['id']};}};exports[_0x7ba8('0x31')]=function(_0x48f690,_0x535525,_0x59ad73,_0x3689b4){if(_0x59ad73&&_0x59ad73['id']&&_0x48f690[_0x7ba8('0x30')]&&_0x48f690['agents'][_0x59ad73['id']]){delete _0x48f690['agents'][_0x59ad73['id']][_0x3689b4+_0x7ba8('0x2e')][_0x535525[_0x7ba8('0x13')]['id']];}};exports[_0x7ba8('0x32')]=writeLog;