2278c044e41b42678074dc980e0c27d3bab4db13
[motion2.git] / server / api / realtime / realtime.controller.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 _0x7b84=['user','role','userProfileId','outbound','QueueCampaigns','filter','UserProfile','getResources','Queues','format','loggedIn','available','push','pTalking','originated','message','dialActive','dialMethod','startProgressive','erlangCalls','erlangBusyFactor','dialPredictiveInterval','dialPredictiveIntervalMaxThreshold','predictiveIntervalAvailable','predictiveIntervalTotalCalls','predictiveIntervalAvgTalktime','rows','loggedInDb','talking','find','merge','pick','getMembers','length','UserId','online','paused','agents','findAll','QueueId','User','agent','all','catch','util','lodash','jayson/promise','../../components/parsers/qs','../../config/logger','api','../../mysqldb','http','client','offset','undefined','limit','count','status','set','Content-Range','json','error','stack','name','send','getQueues','mail','chat','sms','openchannel','fax','voice','resolve','then','query','channel','Invalid\x20channel','toLowerCase','startCase','Queue','map','rawAttributes','type','key'];(function(_0x5e6ea3,_0x9addd2){var _0x4048b5=function(_0x9092e4){while(--_0x9092e4){_0x5e6ea3['push'](_0x5e6ea3['shift']());}};_0x4048b5(++_0x9addd2);}(_0x7b84,0x17c));var _0x47b8=function(_0x4152be,_0x2c8f78){_0x4152be=_0x4152be-0x0;var _0x53e518=_0x7b84[_0x4152be];return _0x53e518;};'use strict';var util=require(_0x47b8('0x0'));var _=require(_0x47b8('0x1'));var jayson=require(_0x47b8('0x2'));var qs=require(_0x47b8('0x3'));var logger=require(_0x47b8('0x4'))(_0x47b8('0x5'));var db=require(_0x47b8('0x6'))['db'];var client=jayson['client'][_0x47b8('0x7')]({'port':0x232a});var routingClient=jayson[_0x47b8('0x8')][_0x47b8('0x7')]({'port':0x232c});function respondWithFilteredResult(_0x7013d7,_0x2e6853){return function(_0xafe88a){if(_0xafe88a){var _0x53e656=typeof _0x2e6853[_0x47b8('0x9')]===_0x47b8('0xa')&&typeof _0x2e6853[_0x47b8('0xb')]===_0x47b8('0xa');var _0x2289d5=_0xafe88a[_0x47b8('0xc')];var _0x24d240=_0x53e656?0x0:_0x2e6853[_0x47b8('0x9')];var _0x9414c2=_0x53e656?_0xafe88a[_0x47b8('0xc')]:_0x2e6853[_0x47b8('0x9')]+_0x2e6853[_0x47b8('0xb')];var _0x26a7b4;if(_0x9414c2>=_0x2289d5){_0x9414c2=_0x2289d5;_0x26a7b4=0xc8;}else{_0x26a7b4=0xce;}_0x7013d7[_0x47b8('0xd')](_0x26a7b4);return _0x7013d7[_0x47b8('0xe')](_0x47b8('0xf'),_0x24d240+'-'+_0x9414c2+'/'+_0x2289d5)[_0x47b8('0x10')](_0xafe88a);}return null;};}function handleError(_0x2a10d2,_0x25a224){_0x25a224=_0x25a224||0x1f4;return function(_0x289ac7){logger[_0x47b8('0x11')](_0x289ac7[_0x47b8('0x12')]);if(_0x289ac7[_0x47b8('0x13')]){delete _0x289ac7[_0x47b8('0x13')];}_0x2a10d2[_0x47b8('0xd')](_0x25a224)[_0x47b8('0x14')](_0x289ac7);};}exports[_0x47b8('0x15')]=function(_0x51cc56,_0x1fe3b7){var _0x340da0=[_0x47b8('0x16'),_0x47b8('0x17'),_0x47b8('0x18'),_0x47b8('0x19'),_0x47b8('0x1a'),'whatsapp',_0x47b8('0x1b')];var _0x5c2b2c={'count':0x0,'rows':[]},_0x525fd6={},_0x4f7317;Promise[_0x47b8('0x1c')]()[_0x47b8('0x1d')](function(){if(_0x51cc56[_0x47b8('0x1e')]['channel']){if(!_['includes'](_0x340da0,_0x51cc56['query'][_0x47b8('0x1f')]['toLowerCase']()))throw new Error(_0x47b8('0x20'));_0x4f7317=_0x51cc56[_0x47b8('0x1e')][_0x47b8('0x1f')][_0x47b8('0x21')]();}var _0x4eba33=_[_0x47b8('0x22')](_0x4f7317)+_0x47b8('0x23');var _0x2840c3=_[_0x47b8('0x24')](db[_0x4eba33][_0x47b8('0x25')],function(_0x232708){return{'name':_0x232708['fieldName'],'type':_0x232708[_0x47b8('0x26')][_0x47b8('0x27')]};});_0x525fd6=qs['getOptions'](_0x2840c3,_0x51cc56);if(_0x51cc56[_0x47b8('0x28')][_0x47b8('0x29')]===_0x47b8('0x28')){var _0x142fb6={'params':{'id':_0x51cc56['user'][_0x47b8('0x2a')]},'query':{'section':_0x4f7317===_0x47b8('0x1b')&&_0x51cc56[_0x47b8('0x1e')][_0x47b8('0x26')]===_0x47b8('0x2b')?_0x47b8('0x2c'):_[_0x47b8('0x22')](_0x4f7317)+'Queues','type':_0x51cc56[_0x47b8('0x1e')][_0x47b8('0x26')],'nolimit':!![],'sort':'name','filter':_0x51cc56[_0x47b8('0x1e')][_0x47b8('0x2d')]}};return db[_0x47b8('0x2e')][_0x47b8('0x2f')](_0x142fb6);}return db[_0x4eba33]['findAndCountAll'](_0x525fd6);})[_0x47b8('0x1d')](function(_0x5c347f){_0x5c2b2c[_0x47b8('0xc')]=_0x5c347f[_0x47b8('0xc')];var _0x33e653=_0x4f7317===_0x47b8('0x1b')?client:routingClient;return _0x33e653['request'](_[_0x47b8('0x22')](_0x4f7317)+_0x47b8('0x30'),_0x51cc56)[_0x47b8('0x1d')](function(_0x1b6c0a){if(_0x1b6c0a[_0x47b8('0x11')])throw new Error(util[_0x47b8('0x31')]('Unable\x20to\x20retrieve\x20RPC\x20%s\x20queues',_0x4f7317));var _0x49326d=_0x1b6c0a['result'];var _0x12fc03=[_0x47b8('0x32'),_0x47b8('0x33'),'waiting','talking','paused'];if(_0x4f7317==='voice'&&_0x51cc56[_0x47b8('0x1e')][_0x47b8('0x26')]===_0x47b8('0x2b')){_0x12fc03[_0x47b8('0x34')](_0x47b8('0x35'),_0x47b8('0x36'),_0x47b8('0x37'),_0x47b8('0x38'),_0x47b8('0x39'),'Trunk','startPredictive',_0x47b8('0x3a'),_0x47b8('0x3b'),'erlangCallToSecond','erlangAbandonmentRate',_0x47b8('0x3c'),_0x47b8('0x3d'),_0x47b8('0x3e'),'dialPredictiveIntervalMinThreshold',_0x47b8('0x3f'),_0x47b8('0x40'),'predictiveIntervalAnsweredCalls','predictiveIntervalDroppedCallsTimeout','predictiveIntervalDroppedCallsCallersExit','predictiveIntervalAvgHoldtime',_0x47b8('0x41'));}var _0x12078e=_0x5c347f[_0x47b8('0x42')][_0x47b8('0x24')](function(_0xed7a2b){var _0x3c24c1=_0xed7a2b['get']({'plain':!![]});_0x3c24c1['paused']=0x0;_0x3c24c1[_0x47b8('0x43')]=0x0;_0x3c24c1[_0x47b8('0x32')]=0x0;_0x3c24c1[_0x47b8('0x33')]=0x0;_0x3c24c1['paused']=0x0;_0x3c24c1['waiting']=0x0;if(_0x4f7317===_0x47b8('0x1b')){_0x3c24c1[_0x47b8('0x44')]=0x0;if(_0x51cc56['query'][_0x47b8('0x26')]===_0x47b8('0x2b')){_0x3c24c1['pTalking']=0x0;_0x3c24c1['originated']=0x0;}}_0x3c24c1['agents']=[];var _0x508947=_[_0x47b8('0x45')](_0x49326d[_0x47b8('0x42')],['id',_0x3c24c1['id']]);if(_0x508947)_[_0x47b8('0x46')](_0x3c24c1,_[_0x47b8('0x47')](_0x508947,_0x12fc03));if(_0x4f7317===_0x47b8('0x1b')){return _0xed7a2b['getAgents']({'attributes':['id',_0x47b8('0x13'),'online'],'joinTableAttributes':[],'raw':!![]})[_0x47b8('0x1d')](function(_0x8dc3fd){return _0xed7a2b[_0x47b8('0x48')]({'raw':!![]})['then'](function(_0x433659){for(var _0x217be1=0x0;_0x217be1<_0x8dc3fd[_0x47b8('0x49')];_0x217be1++){var _0xf22edb=_[_0x47b8('0x45')](_0x433659,[_0x47b8('0x4a'),_0x8dc3fd[_0x217be1]['id']]);var _0x2d2971={'id':_0x8dc3fd[_0x217be1]['id'],'name':_0x8dc3fd[_0x217be1]['name'],'online':Boolean(_0x8dc3fd[_0x217be1][_0x47b8('0x4b')]),'paused':_0xf22edb?Boolean(_0xf22edb['paused']):![]};if(_0x2d2971[_0x47b8('0x4b')])_0x3c24c1[_0x47b8('0x43')]++;if(_0x2d2971[_0x47b8('0x4c')])_0x3c24c1[_0x47b8('0x4c')]++;_0x3c24c1[_0x47b8('0x4d')][_0x47b8('0x34')](_0x2d2971);}return _0x3c24c1;});});}else{var _0x51ff29='User'+_[_0x47b8('0x22')](_0x4f7317)+_0x47b8('0x23');var _0x932c71=_0x4f7317+'Pause';return db[_0x51ff29][_0x47b8('0x4e')]({'where':{[_['startCase'](_0x4f7317)+_0x47b8('0x4f')]:_0xed7a2b['id']},'raw':!![]})[_0x47b8('0x1d')](function(_0x41f42f){return db[_0x47b8('0x50')][_0x47b8('0x4e')]({'attributes':['id','name',_0x47b8('0x4b'),_0x932c71],'where':{'id':_[_0x47b8('0x24')](_0x41f42f,_0x47b8('0x4a')),'role':_0x47b8('0x51')},'raw':!![]});})[_0x47b8('0x1d')](function(_0x324a2b){for(var _0x46e648=0x0;_0x46e648<_0x324a2b['length'];_0x46e648++){var _0xe94c08={'id':_0x324a2b[_0x46e648]['id'],'name':_0x324a2b[_0x46e648]['name'],'online':Boolean(_0x324a2b[_0x46e648][_0x47b8('0x4b')]),'paused':Boolean(_0x324a2b[_0x46e648][_0x932c71])};if(_0xe94c08[_0x47b8('0x4b')])_0x3c24c1['loggedInDb']++;if(_0xe94c08[_0x47b8('0x4c')])_0x3c24c1[_0x47b8('0x4c')]++;_0x3c24c1[_0x47b8('0x4d')][_0x47b8('0x34')](_0xe94c08);}return _0x3c24c1;});}});return Promise[_0x47b8('0x52')](_0x12078e);});})[_0x47b8('0x1d')](function(_0x1b1733){_0x5c2b2c[_0x47b8('0x42')]=_0x1b1733;return _0x5c2b2c;})['then'](respondWithFilteredResult(_0x1fe3b7,_0x525fd6))[_0x47b8('0x53')](handleError(_0x1fe3b7,null));};