Built motion from commit 3c2ce842.|2.6.31
[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 _0xce2f=['message','writeLog','util','../utils','ioredis','../../../../../config/environment','../../../../../config/logger','routing','defaults','localhost','redis','name','notificationSound','notificationShake','body','queue','msg','getMustacheRender','account','notificationTemplate','I\x20can\x27t\x20render\x20your\x20template','format','[%s][QUEUE]\x20%s','user:%s','notification:%s','save','remove','debug','[%s][QUEUE][AGENT:%s][STATUS:%s]','busy','BUSY','online','OFFLINE','PAUSE','hasOwnProperty','Capacity','CurrentCapacity','toUpperCase','showNotification','hideNotification','interaction','UserId','channel','capitalize','InteractionId','agents','some','WaitingInteractions','saveWaitingNotification'];(function(_0x231ee9,_0x517eab){var _0x385ff9=function(_0xc6cb78){while(--_0xc6cb78){_0x231ee9['push'](_0x231ee9['shift']());}};_0x385ff9(++_0x517eab);}(_0xce2f,0x18a));var _0xfce2=function(_0x1c73ba,_0x11bfe9){_0x1c73ba=_0x1c73ba-0x0;var _0x58e09a=_0xce2f[_0x1c73ba];return _0x58e09a;};'use strict';var _=require('lodash');var util=require(_0xfce2('0x0'));var utils=require(_0xfce2('0x1'));var Redis=require(_0xfce2('0x2'));var config=require(_0xfce2('0x3'));var logger=require(_0xfce2('0x4'))(_0xfce2('0x5'));config['redis']=_[_0xfce2('0x6')](config['redis'],{'host':_0xfce2('0x7'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xfce2('0x8')]));function sendNotification(_0xeffde2,_0x13c378,_0x741a25,_0x442065,_0x458b85,_0x27f1d1){var _0x23af14=_0x27f1d1||{};var _0x5155a4=_0x741a25['split']('.');var _0x2141d1={'uniqueid':_0x13c378,'channel':_0x5155a4[0x0],'id':_0x5155a4[0x1],'title':_0x5155a4[0x0]+'\x20interaction','interactionId':_0x5155a4[0x2],'queue':_0x458b85?_0x458b85[_0xfce2('0x9')]:null,'sound':_0x23af14['account'][_0xfce2('0xa')],'shake':_0x23af14['account'][_0xfce2('0xb')]};try{if(!_0x23af14[_0xfce2('0xc')]){_0x23af14[_0xfce2('0xc')]={};}if(_0x458b85){_0x23af14['body'][_0xfce2('0xd')]=_0x458b85;}else if(_0x23af14['body'][_0xfce2('0xd')]){delete _0x23af14[_0xfce2('0xc')][_0xfce2('0xd')];}_0x2141d1[_0xfce2('0xe')]=utils[_0xfce2('0xf')](_0x23af14[_0xfce2('0x10')][_0xfce2('0x11')],_0x23af14);}catch(_0x4fdcc2){_0x2141d1[_0xfce2('0xe')]=_0xfce2('0x12');logger['error'](util[_0xfce2('0x13')](_0xfce2('0x14'),_0x13c378,_0x4fdcc2['message']));}io['to'](util['format'](_0xfce2('0x15'),_0x442065[_0xfce2('0x9')]))['emit'](util[_0xfce2('0x13')](_0xfce2('0x16'),_0xeffde2?_0xfce2('0x17'):_0xfce2('0x18')),_0x2141d1);}function writeLog(_0x2ad9f5,_0x30d38b,_0x270e52){return logger[_0xfce2('0x19')](util[_0xfce2('0x13')](_0xfce2('0x1a'),_0x2ad9f5,_0x30d38b['name'],_0x270e52));}exports['isAgentAvailable']=function(_0x3c4f1f,_0x3ea07b,_0x312c10,_0x24a13e){if(_0x3ea07b[_0xfce2('0x1b')]){writeLog(_0x3c4f1f,_0x3ea07b,_0xfce2('0x1c'));return![];}if(!_0x3ea07b[_0xfce2('0x1d')]){writeLog(_0x3c4f1f,_0x3ea07b,_0xfce2('0x1e'));return![];}if(_0x3ea07b[_0x312c10+'Pause']){writeLog(_0x3c4f1f,_0x3ea07b,_0xfce2('0x1f'));return![];}if(_0x24a13e&&_0x3ea07b[_0xfce2('0x20')](_0x312c10+_0xfce2('0x21'))&&_0x3ea07b['hasOwnProperty'](_0x312c10+'CurrentCapacity')){if(_0x3ea07b[_0x312c10+_0xfce2('0x21')]>0x0&&_0x3ea07b[_0x312c10+_0xfce2('0x22')]>=_0x3ea07b[_0x312c10+_0xfce2('0x21')]){writeLog(_0x3c4f1f,_0x3ea07b,_0x312c10[_0xfce2('0x23')]()+'\x20MAXCAPACITY');return![];}}return!![];};exports[_0xfce2('0x24')]=function(_0x5cd9b2,_0x992b0f,_0x47ed7f,_0x20af10,_0x13129d){return sendNotification(!![],_0x5cd9b2,_0x992b0f,_0x47ed7f,_0x20af10,_0x13129d);};exports[_0xfce2('0x25')]=function(_0x4c63ea,_0x5a8b8a,_0x2358dc,_0x175bcc,_0x112f0a){return sendNotification(![],_0x4c63ea,_0x5a8b8a,_0x2358dc,_0x175bcc,_0x112f0a);};exports['checkWaitingNotifications']=function(_0x6c8a47,_0xef1b38,_0x58022e){var _0x31649e=_0xef1b38[_0xfce2('0x26')][_0xfce2('0x27')];if(!_0x31649e&&_0x58022e){_0x31649e=_0x58022e['id'];}var _0x1f48ba=_['some'](_0x6c8a47[_0xef1b38[_0xfce2('0x28')]+'QueuesWaitingInteractions'],function(_0x1b211c){var _0x468739=_[_0xfce2('0x29')](_0xef1b38[_0xfce2('0x28')])+_0xfce2('0x2a');return _0x1b211c[_0x468739]===_0xef1b38[_0xfce2('0x26')]['id'];});if(!_0x1f48ba&&_0x31649e&&_0x6c8a47[_0xfce2('0x2b')][_0x31649e]){_0x1f48ba=_[_0xfce2('0x2c')](_0x6c8a47['agents'][_0x31649e][_0xef1b38[_0xfce2('0x28')]+_0xfce2('0x2d')],function(_0x254206){return _0x254206['id']===_0xef1b38['interaction']['id'];});}return _0x1f48ba;};exports[_0xfce2('0x2e')]=function(_0x4c08d3,_0x4d453e,_0x42b3d0,_0x4fd253){if(_0x42b3d0&&_0x42b3d0['id']&&_0x4c08d3[_0xfce2('0x2b')]&&_0x4c08d3[_0xfce2('0x2b')][_0x42b3d0['id']]){_0x4c08d3[_0xfce2('0x2b')][_0x42b3d0['id']][_0x4fd253+_0xfce2('0x2d')][_0x4d453e['message']['id']]={'id':_0x4d453e['interaction']['id']};}};exports['removeWaitingNotification']=function(_0x1d24d1,_0x10f855,_0x3d313a,_0x3c7305){if(_0x3d313a&&_0x3d313a['id']&&_0x1d24d1[_0xfce2('0x2b')]&&_0x1d24d1['agents'][_0x3d313a['id']]){delete _0x1d24d1['agents'][_0x3d313a['id']][_0x3c7305+_0xfce2('0x2d')][_0x10f855[_0xfce2('0x2f')]['id']];}};exports[_0xfce2('0x30')]=writeLog;