Built motion from commit (unavailable).|2.4.3
[motion2.git] / server / services / routing / server / index.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 _0xf823=['agent','agents','busyQueue','hasOwnProperty','capacity','CurrentCapacity','updateRealtime','values','chatQueues','available','name','waiting','mailQueues','loggedIn','paused','openchannelQueues','smsQueues','faxQueues','chatQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','http','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','lodash','bluebird','uuid','../../../config/environment','../../../config/logger','routing','../rpc/openchannelQueueReport','../rpc/chatQueueReport','../rpc/smsQueueReport','../rpc/faxQueueReport','../lib/rule-engine','%s.%s.%s','isNil','IntervalId','Intervals','map','interval','listen','rules','message','interaction','applications','length','existsSync','join','.js','app','toLowerCase','autoreply','appdata','split','push','slice','dialogflow','tag','TagId','format','./interval','condition','intervals','./applications/','consequence','priority','info','Push\x20new\x20rule','\x20|\x20','error','Please\x20create\x20a\x20new\x20file\x20under','execute','Applications\x20executed','emit','No\x20applications\x20to\x20execute','stack','channel','end','QueueReport','update','UserId','catch','error\x20update\x20queue\x20report','message\x20is\x20empty'];(function(_0x1deb03,_0xd05ad8){var _0x189fe7=function(_0x321225){while(--_0x321225){_0x1deb03['push'](_0x1deb03['shift']());}};_0x189fe7(++_0xd05ad8);}(_0xf823,0xc2));var _0x3f82=function(_0x51d884,_0x2cd5ac){_0x51d884=_0x51d884-0x0;var _0x5a05d9=_0xf823[_0x51d884];return _0x5a05d9;};'use strict';var _=require(_0x3f82('0x0'));var util=require('util');var path=require('path');var fs=require('fs');var jayson=require('jayson/promise');var BPromise=require(_0x3f82('0x1'));var uuid=require(_0x3f82('0x2'));var config=require(_0x3f82('0x3'));var logger=require(_0x3f82('0x4'))(_0x3f82('0x5'));var rpc={'openchannelQueueReport':require(_0x3f82('0x6'))};var rpc={'openchannelQueueReport':require(_0x3f82('0x6')),'mailQueueReport':require('../rpc/mailQueueReport'),'chatQueueReport':require(_0x3f82('0x7')),'smsQueueReport':require(_0x3f82('0x8')),'faxQueueReport':require(_0x3f82('0x9'))};var RuleEngine=require(_0x3f82('0xa'));function getId(_0x2066a3,_0x1af6cd,_0x5bc6d2){return util['format'](_0x3f82('0xb'),_0x2066a3,_0x1af6cd||0x0,_0x5bc6d2||0x0);}function getIntervals(_0x64da83,_0x18cc30){var _0x5125db=[];if(!_[_0x3f82('0xc')](_0x18cc30['IntervalId'])&&!_[_0x3f82('0xc')](_0x64da83[_0x18cc30['IntervalId']])&&!_[_0x3f82('0xc')](_0x64da83[_0x18cc30[_0x3f82('0xd')]][_0x3f82('0xe')])){_0x5125db=_[_0x3f82('0xf')](_0x64da83[_0x18cc30[_0x3f82('0xd')]][_0x3f82('0xe')],'interval');}else if(!_['isNil'](_0x18cc30[_0x3f82('0x10')])){_0x5125db=[_0x18cc30['interval']];}return _0x5125db;}exports[_0x3f82('0x11')]=function(_0x11ad54){_0x11ad54[_0x3f82('0x12')]={};return new BPromise(function(_0x5223e4,_0x1cf166){var _0x3355ba={'Start':function(_0x2bb1db){var _0x2035e9=this;return new Promise(function(_0x28ace7,_0x245ccf){if(_0x2bb1db){try{var _0x484a32=[];var _0x3e83fa=getId(_0x2bb1db['channel'],_0x2bb1db[_0x3f82('0x13')]?_0x2bb1db[_0x3f82('0x13')]['id']:0x0,_0x2bb1db[_0x3f82('0x14')]?_0x2bb1db[_0x3f82('0x14')]['id']:0x0);if(_0x2bb1db[_0x3f82('0x15')]&&_['isArray'](_0x2bb1db['applications'])&&_0x2bb1db[_0x3f82('0x15')][_0x3f82('0x16')]){for(var _0x295497=0x0;_0x295497<_0x2bb1db[_0x3f82('0x15')][_0x3f82('0x16')];_0x295497+=0x1){var _0x22abad=_0x2bb1db['applications'][_0x295497];if(fs[_0x3f82('0x17')](path[_0x3f82('0x18')](__dirname,_0x3f82('0x15'),_0x22abad['app']+_0x3f82('0x19')))){var _0x149a55=[];switch(_0x22abad[_0x3f82('0x1a')][_0x3f82('0x1b')]()){case _0x3f82('0x1c'):var _0x80a00c=_0x22abad[_0x3f82('0x1d')][_0x3f82('0x1e')](',');_0x149a55['push'](_0x80a00c[0x0]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[_0x3f82('0x20')](0x1,_0x80a00c[_0x3f82('0x16')])[_0x3f82('0x18')](','));break;case _0x3f82('0x21'):var _0x80a00c=_0x22abad[_0x3f82('0x1d')][_0x3f82('0x1e')](',');_0x149a55[_0x3f82('0x1f')](_0x80a00c[0x0]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[0x1]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[_0x3f82('0x20')](0x2,_0x80a00c[_0x3f82('0x16')])[_0x3f82('0x18')](','));break;case'amazonlex':var _0x80a00c=_0x22abad[_0x3f82('0x1d')][_0x3f82('0x1e')](',');_0x149a55['push'](_0x80a00c[0x0]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[0x1]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[0x2]);_0x149a55[_0x3f82('0x1f')](_0x80a00c[0x3]);_0x149a55['push'](_0x80a00c[_0x3f82('0x20')](0x4,_0x80a00c[_0x3f82('0x16')])[_0x3f82('0x18')](','));break;case _0x3f82('0x13'):_0x149a55[_0x3f82('0x1f')](_0x22abad[_0x3f82('0x1d')]);break;case _0x3f82('0x22'):_0x149a55[_0x3f82('0x1f')](_0x22abad[_0x3f82('0x23')]);_0x149a55['push'](_0x22abad['appdata']);break;default:_0x149a55=_[_0x3f82('0xc')](_0x22abad[_0x3f82('0x1d')])?[]:_0x22abad[_0x3f82('0x1d')][_0x3f82('0x1e')](',');}var _0x3a79f2={'id':util[_0x3f82('0x24')]('%s:%s:%s',_0x3e83fa,_0x22abad['id'],_0x22abad[_0x3f82('0x1a')]),'condition':require(_0x3f82('0x25'))[_0x3f82('0x26')](_0x3e83fa,getIntervals(_0x11ad54[_0x3f82('0x27')],_0x22abad),_0x11ad54),'consequence':require(_0x3f82('0x28')+_0x22abad[_0x3f82('0x1a')])[_0x3f82('0x29')](_0x3e83fa,_0x149a55,_0x11ad54,_0x2bb1db),'p':_0x22abad[_0x3f82('0x2a')]||0x0};logger[_0x3f82('0x2b')](_0x3f82('0x2c'),_0x3a79f2['id'],'on\x20interval',getIntervals(_0x11ad54[_0x3f82('0x27')],_0x22abad)['join'](_0x3f82('0x2d')));_0x484a32[_0x3f82('0x1f')](_0x3a79f2);}else{logger[_0x3f82('0x2e')](_0x3f82('0x2f'),path['join'](__dirname,'applications',_0x22abad[_0x3f82('0x1a')]+'.js'));}}_0x11ad54[_0x3f82('0x12')][_0x3e83fa]=new RuleEngine(_0x484a32);_0x11ad54[_0x3f82('0x12')][_0x3e83fa][_0x3f82('0x30')](_0x2bb1db,function(_0x4bc659){logger['info'](_0x3f82('0x31'),JSON['stringify'](_0x4bc659['matchPath']));if(_0x11ad54[_0x3f82('0x12')][_0x3e83fa]){_0x11ad54['rules'][_0x3e83fa][_0x3f82('0x32')]('end');}});return _0x28ace7({'code':0xc8,'message':_0x2bb1db});}else{logger[_0x3f82('0x2b')](_0x3f82('0x33'));return _0x28ace7({'code':0xc8,'message':_0x2bb1db});}}catch(_0x112a56){logger[_0x3f82('0x2e')](_0x112a56[_0x3f82('0x34')]);return _0x245ccf(_0x2035e9[_0x3f82('0x2e')](0x1f4,_0x112a56));}}return _0x245ccf('routing\x20is\x20empty');});},'AcceptMessage':function(_0x561d6d){var _0x4080dc=this;return new Promise(function(_0xb10d3b,_0x13c558){if(_0x561d6d['message']&&_0x561d6d['message']['id']){try{var _0x20fff2=getId(_0x561d6d[_0x3f82('0x35')],_0x561d6d[_0x3f82('0x13')]?_0x561d6d['message']['id']:0x0,_0x561d6d['interaction']?_0x561d6d['interaction']['id']:0x0);if(_0x11ad54[_0x3f82('0x12')][_0x20fff2]){_0x11ad54['rules'][_0x20fff2][_0x3f82('0x32')](_0x3f82('0x36'));if(rpc[_0x561d6d[_0x3f82('0x35')]+_0x3f82('0x37')]){rpc[_0x561d6d['channel']+_0x3f82('0x37')][_0x3f82('0x38')](_0x20fff2,{'UserId':_0x561d6d[_0x3f82('0x13')][_0x3f82('0x39')]})[_0x3f82('0x3a')](function(_0x554127){logger[_0x3f82('0x2e')](_0x3f82('0x3b'));});}}return _0xb10d3b({'code':0xc8,'message':_0x561d6d});}catch(_0x16088a){logger[_0x3f82('0x2e')](_0x16088a['stack']);return _0x13c558(_0x4080dc['error'](0x1f4,_0x16088a));}}logger[_0x3f82('0x2e')]('message\x20is\x20empty');return _0x13c558(_0x4080dc[_0x3f82('0x2e')](0x1f4,_0x3f82('0x3c')));});},'RejectMessage':function(_0x4d7457){var _0x2b389b=this;return new Promise(function(_0x15ed3b,_0x2b1aac){if(_0x4d7457[_0x3f82('0x3d')]&&_0x4d7457[_0x3f82('0x3d')]['id']){try{if(_0x11ad54['agents'][_0x4d7457[_0x3f82('0x3d')]['id']]){_0x11ad54[_0x3f82('0x3e')][_0x4d7457[_0x3f82('0x3d')]['id']]['busy']=![];_0x11ad54['agents'][_0x4d7457[_0x3f82('0x3d')]['id']][_0x3f82('0x3f')]=undefined;}return _0x15ed3b({'code':0xc8,'message':_0x4d7457});}catch(_0x33efe9){logger['error'](_0x33efe9['stack']);return _0x2b1aac(_0x2b389b[_0x3f82('0x2e')](0x1f4,_0x33efe9));}}logger['error'](_0x3f82('0x3c'));return _0x2b1aac(_0x2b389b[_0x3f82('0x2e')](0x1f4,_0x3f82('0x3c')));});},'AbandonInteraction':function(_0x1ff6db){var _0x571349=this;return new Promise(function(_0x5509ba,_0x5ad9a3){if(_0x1ff6db[_0x3f82('0x35')]&&_0x1ff6db[_0x3f82('0x14')]&&_0x1ff6db[_0x3f82('0x14')]['id']){try{var _0x3b9d79=getId(_0x1ff6db[_0x3f82('0x35')],_0x1ff6db[_0x3f82('0x13')]?_0x1ff6db[_0x3f82('0x13')]['id']:0x0,_0x1ff6db[_0x3f82('0x14')]?_0x1ff6db[_0x3f82('0x14')]['id']:0x0);if(_0x11ad54[_0x3f82('0x12')][_0x3b9d79]){_0x11ad54[_0x3f82('0x12')][_0x3b9d79][_0x3f82('0x32')]('end');}return _0x5509ba({'code':0xc8,'message':_0x1ff6db});}catch(_0x23e3e0){logger['error'](_0x23e3e0[_0x3f82('0x34')]);return _0x5ad9a3(_0x571349[_0x3f82('0x2e')](0x1f4,_0x23e3e0));}}logger['error'](_0x3f82('0x3c'));return _0x5ad9a3(_0x571349[_0x3f82('0x2e')](0x1f4,_0x3f82('0x3c')));});},'AgentCapacity':function(_0x42eca0){var _0x50e840=this;return new Promise(function(_0x1bdfd3,_0x14be21){if(_0x11ad54['agents'][_0x3f82('0x40')](_0x42eca0['id'])){for(var _0x212eb9 in _0x42eca0['capacity']){if(_0x42eca0[_0x3f82('0x41')][_0x3f82('0x40')](_0x212eb9)){if(_0x11ad54[_0x3f82('0x3e')][_0x42eca0['id']][_0x3f82('0x40')](_0x212eb9+_0x3f82('0x42'))){_0x11ad54[_0x3f82('0x3e')][_0x42eca0['id']][_0x212eb9+_0x3f82('0x42')]=parseInt(_0x42eca0[_0x3f82('0x41')][_0x212eb9],0xa);}}}_0x11ad54[_0x3f82('0x3e')][_0x42eca0['id']][_0x3f82('0x43')]();return _0x1bdfd3({'code':0xc8,'message':_0x11ad54[_0x3f82('0x3e')][_0x42eca0['id']]});}else{return _0x14be21(_0x50e840[_0x3f82('0x2e')](0x1f4,'agent\x20not\x20found'));}});},'Agents':function(_0x480bee){return new Promise(function(_0x5ec83a,_0x4654a2){var _0x9b558b=_[_0x3f82('0x44')](_0x11ad54[_0x3f82('0x3e')]);_0x5ec83a({'count':_0x9b558b[_0x3f82('0x16')],'rows':_0x9b558b});});},'ChatQueues':function(_0x189e68){return new Promise(function(_0x38c160,_0x143f02){var _0x30f7f8=[];for(var _0x521d88 in _0x11ad54['chatQueues']){if(_0x11ad54[_0x3f82('0x45')][_0x3f82('0x40')](_0x521d88)){var _0x385817=_0x11ad54[_0x3f82('0x45')][_0x521d88];var _0x5eed2a={'id':_0x385817['id'],'available':_0x385817[_0x3f82('0x46')],'loggedIn':_0x385817['loggedIn'],'name':_0x385817[_0x3f82('0x47')],'paused':_0x385817['paused'],'waiting':_0x385817[_0x3f82('0x48')]};_0x30f7f8[_0x3f82('0x1f')](_0x5eed2a);}}_0x38c160({'count':_0x30f7f8[_0x3f82('0x16')],'rows':_0x30f7f8});});},'MailQueues':function(_0x20c9b7){return new Promise(function(_0x415d47,_0x10bea2){var _0x62b70=[];for(var _0x530ea4 in _0x11ad54[_0x3f82('0x49')]){if(_0x11ad54[_0x3f82('0x49')][_0x3f82('0x40')](_0x530ea4)){var _0x35a606=_0x11ad54[_0x3f82('0x49')][_0x530ea4];var _0x2b25c8={'id':_0x35a606['id'],'available':_0x35a606[_0x3f82('0x46')],'loggedIn':_0x35a606[_0x3f82('0x4a')],'name':_0x35a606[_0x3f82('0x47')],'paused':_0x35a606[_0x3f82('0x4b')],'waiting':_0x35a606[_0x3f82('0x48')]};_0x62b70['push'](_0x2b25c8);}}_0x415d47({'count':_0x62b70[_0x3f82('0x16')],'rows':_0x62b70});});},'OpenchannelQueues':function(_0x1661c6){return new Promise(function(_0x1375d3,_0x3f9e61){var _0x1fa280=[];for(var _0x19725b in _0x11ad54['openchannelQueues']){if(_0x11ad54[_0x3f82('0x4c')][_0x3f82('0x40')](_0x19725b)){var _0x4230b5=_0x11ad54['openchannelQueues'][_0x19725b];var _0x2989b3={'id':_0x4230b5['id'],'available':_0x4230b5[_0x3f82('0x46')],'loggedIn':_0x4230b5[_0x3f82('0x4a')],'name':_0x4230b5[_0x3f82('0x47')],'paused':_0x4230b5['paused'],'waiting':_0x4230b5['waiting']};_0x1fa280['push'](_0x2989b3);}}_0x1375d3({'count':_0x1fa280[_0x3f82('0x16')],'rows':_0x1fa280});});},'SmsQueues':function(_0x15d0f7){return new Promise(function(_0x1658af,_0x2cdd0a){var _0x56a979=[];for(var _0x41cfba in _0x11ad54[_0x3f82('0x4d')]){if(_0x11ad54['smsQueues']['hasOwnProperty'](_0x41cfba)){var _0x1e7f4f=_0x11ad54[_0x3f82('0x4d')][_0x41cfba];var _0x356b98={'id':_0x1e7f4f['id'],'available':_0x1e7f4f[_0x3f82('0x46')],'loggedIn':_0x1e7f4f[_0x3f82('0x4a')],'name':_0x1e7f4f[_0x3f82('0x47')],'paused':_0x1e7f4f[_0x3f82('0x4b')],'waiting':_0x1e7f4f['waiting']};_0x56a979[_0x3f82('0x1f')](_0x356b98);}}_0x1658af({'count':_0x56a979[_0x3f82('0x16')],'rows':_0x56a979});});},'FaxQueues':function(_0x44a1fa){return new Promise(function(_0x4e6a95,_0x568b4e){var _0x1bce28=[];for(var _0x12f040 in _0x11ad54['faxQueues']){if(_0x11ad54[_0x3f82('0x4e')][_0x3f82('0x40')](_0x12f040)){var _0x5ea0bc=_0x11ad54['faxQueues'][_0x12f040];var _0x2d5f75={'id':_0x5ea0bc['id'],'available':_0x5ea0bc[_0x3f82('0x46')],'loggedIn':_0x5ea0bc['loggedIn'],'name':_0x5ea0bc[_0x3f82('0x47')],'paused':_0x5ea0bc['paused'],'waiting':_0x5ea0bc['waiting']};_0x1bce28['push'](_0x2d5f75);}}_0x4e6a95({'count':_0x1bce28['length'],'rows':_0x1bce28});});},'ChatQueuesWaitingInteractions':function(_0x149e87){return new Promise(function(_0x9a59e0,_0x186f2e){var _0x40a81a=_[_0x3f82('0x44')](_0x11ad54[_0x3f82('0x4f')]);_0x9a59e0({'count':_0x40a81a['length'],'rows':_0x40a81a});});},'MailQueuesWaitingInteractions':function(_0x3ed9f6){return new Promise(function(_0x4b7b8e,_0x103906){var _0x3df0cd=_[_0x3f82('0x44')](_0x11ad54['mailQueuesWaitingInteractions']);_0x4b7b8e({'count':_0x3df0cd[_0x3f82('0x16')],'rows':_0x3df0cd});});},'OpenchannelQueuesWaitingInteractions':function(_0x3965d9){return new Promise(function(_0x17dad1,_0x45fb98){var _0x34bfde=_[_0x3f82('0x44')](_0x11ad54[_0x3f82('0x50')]);_0x17dad1({'count':_0x34bfde[_0x3f82('0x16')],'rows':_0x34bfde});});},'SmsQueuesWaitingInteractions':function(_0x1b3c24){return new Promise(function(_0x1d5b9f,_0x2627d0){var _0x25eb5e=_[_0x3f82('0x44')](_0x11ad54['smsQueuesWaitingInteractions']);_0x1d5b9f({'count':_0x25eb5e[_0x3f82('0x16')],'rows':_0x25eb5e});});},'FaxQueuesWaitingInteractions':function(_0x3cb426){return new Promise(function(_0x163667,_0x57dd74){var _0x43adc8=_[_0x3f82('0x44')](_0x11ad54['faxQueuesWaitingInteractions']);_0x163667({'count':_0x43adc8['length'],'rows':_0x43adc8});});}};var _0x2c66c6=jayson['server'](_0x3355ba)[_0x3f82('0x51')]();_0x2c66c6['on'](_0x3f82('0x2e'),function(_0x4ceb8c){logger['error'](JSON['stringify'](_0x4ceb8c));return _0x1cf166(_0x4ceb8c);});_0x2c66c6[_0x3f82('0x11')](0x232c,'127.0.0.1',function(){console[_0x3f82('0x52')](_0x3f82('0x53'),0x232c);return _0x5223e4(_0x3f82('0x54')+0x232c);});});};