mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-26 13:19:34 +07:00
✨ feat: support Discord IM bot intergration (#12517)
* clean fix tools calling results improve display support discord bot finish bot integration * improve next config * support queue callback mode * support queue callback mode * improve error * fix build * support serverless gateway * support serverless gateway * support serverless enable * improve ui * improve ui * add credentials config * improve and refactor data working * update config * fix integration * fix types * fix types * fix types * fix types * move files * fix update * fix update * fix update
This commit is contained in:
@@ -126,6 +126,43 @@ const runScript = (scriptPath, useProxy = false) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Function to start the bot gateway by calling the local API endpoint
|
||||
const startGateway = async () => {
|
||||
const KEY_VAULTS_SECRET = process.env.KEY_VAULTS_SECRET;
|
||||
if (!KEY_VAULTS_SECRET) return;
|
||||
|
||||
const port = process.env.PORT || 3210;
|
||||
const url = `http://localhost:${port}/api/agent/gateway/start`;
|
||||
const maxRetries = 10;
|
||||
const retryDelay = 3000;
|
||||
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${KEY_VAULTS_SECRET}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log('✅ Gateway: Started successfully.');
|
||||
return;
|
||||
}
|
||||
|
||||
console.warn(`⚠️ Gateway: Received status ${res.status}, retrying...`);
|
||||
} catch {
|
||||
if (i < maxRetries - 1) {
|
||||
await new Promise((r) => setTimeout(r, retryDelay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.error('❌ Gateway: Failed to start after retries.');
|
||||
};
|
||||
|
||||
// Main function to run the server with optional proxy
|
||||
const runServer = async () => {
|
||||
const PROXY_URL = process.env.PROXY_URL || ''; // Default empty string to avoid undefined errors
|
||||
@@ -164,6 +201,9 @@ const runServer = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Start gateway in background after server is ready
|
||||
startGateway();
|
||||
|
||||
// Run the server in either database or non-database mode
|
||||
await runServer();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user