W n8n attention warning

This commit is contained in:
alma 2025-05-24 09:52:07 +02:00
parent a2b3bcf72b
commit 854f3150cc

View File

@ -5,15 +5,22 @@ export class N8nService {
private readonly apiKey: string; private readonly apiKey: string;
constructor() { constructor() {
this.n8nUrl = process.env.N8N_URL || ''; this.n8nUrl = process.env.N8N_URL || 'https://brain.slm-lab.net';
this.apiKey = process.env.N8N_API_KEY || ''; this.apiKey = process.env.N8N_API_KEY || '';
if (!this.n8nUrl || !this.apiKey) { // Only log a warning if API key is missing
throw new Error('N8N_URL and N8N_API_KEY must be set in environment variables'); if (!this.apiKey) {
console.warn('N8N_API_KEY is not set in environment variables. n8n integration will be disabled.');
} }
} }
async triggerMissionCreation(data: any): Promise<{ success: boolean; error?: string }> { async triggerMissionCreation(data: any): Promise<{ success: boolean; error?: string }> {
// If API key is not set, skip n8n integration
if (!this.apiKey) {
console.log('Skipping n8n integration - API key not set');
return { success: true };
}
try { try {
const response = await fetch(`${this.n8nUrl}/webhook/mission-creation`, { const response = await fetch(`${this.n8nUrl}/webhook/mission-creation`, {
method: 'POST', method: 'POST',
@ -34,6 +41,7 @@ export class N8nService {
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
console.error('Error triggering n8n workflow:', error);
return { return {
success: false, success: false,
error: error instanceof Error ? error.message : 'Failed to trigger n8n workflow' error: error instanceof Error ? error.message : 'Failed to trigger n8n workflow'
@ -42,6 +50,12 @@ export class N8nService {
} }
async rollbackMissionCreation(data: any): Promise<{ success: boolean; error?: string }> { async rollbackMissionCreation(data: any): Promise<{ success: boolean; error?: string }> {
// If API key is not set, skip n8n integration
if (!this.apiKey) {
console.log('Skipping n8n rollback - API key not set');
return { success: true };
}
try { try {
const response = await fetch(`${this.n8nUrl}/webhook/mission-rollback`, { const response = await fetch(`${this.n8nUrl}/webhook/mission-rollback`, {
method: 'POST', method: 'POST',
@ -62,6 +76,7 @@ export class N8nService {
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
console.error('Error triggering n8n rollback workflow:', error);
return { return {
success: false, success: false,
error: error instanceof Error ? error.message : 'Failed to trigger n8n rollback workflow' error: error instanceof Error ? error.message : 'Failed to trigger n8n rollback workflow'