diff --git a/Profice WebSite/scripts/add/send.php b/Profice WebSite/scripts/add/send.php index 0cf0c8c..f576ef4 100644 --- a/Profice WebSite/scripts/add/send.php +++ b/Profice WebSite/scripts/add/send.php @@ -541,19 +541,29 @@ function handleChatMessage($data) { sendResponse(false, 'Nachricht darf nicht leer sein', null, 400); } + // Format data for n8n webhook - use 'chatInput' as the message field name + // which is commonly expected by n8n AI chat workflows $chatData = [ 'type' => 'chat_message', 'session_id' => $sessionId, 'message' => $message, + 'chatInput' => $message, // Alternative field name for n8n + 'query' => $message, // Another common n8n field name 'timestamp' => date('c'), 'source' => 'website_chat', 'ip_address' => getClientIP(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '' ]; + // Log the outgoing request for debugging + error_log('KI Chat Request - URL: ' . KI_CHAT_WEBHOOK_URL . ' - Data: ' . json_encode($chatData)); + // Send to KI Chat webhook $webhookResult = sendToWebhook($chatData, KI_CHAT_WEBHOOK_URL); + // Log the response for debugging + error_log('KI Chat Response: ' . json_encode($webhookResult)); + $debugData = DEBUG_MODE ? [ 'session_id' => $sessionId, 'webhook_result' => $webhookResult, @@ -561,9 +571,32 @@ function handleChatMessage($data) { ] : null; if ($webhookResult['success']) { - // Try to parse response from webhook + // Try to parse response from webhook - handle various n8n response formats $response = json_decode($webhookResult['response'], true); - $aiResponse = $response['message'] ?? $response['output'] ?? 'Vielen Dank für Ihre Nachricht. Ich melde mich so schnell wie möglich bei Ihnen.'; + $aiResponse = null; + + // Check common n8n response field names + if ($response) { + $aiResponse = $response['message'] + ?? $response['output'] + ?? $response['text'] + ?? $response['response'] + ?? $response['answer'] + ?? $response['result'] + ?? (is_array($response) && isset($response[0]['output']) ? $response[0]['output'] : null) + ?? (is_array($response) && isset($response[0]['message']) ? $response[0]['message'] : null) + ?? null; + } + + // If still no response, use the raw response if it's a string + if (!$aiResponse && is_string($webhookResult['response']) && !empty($webhookResult['response'])) { + $aiResponse = $webhookResult['response']; + } + + // Fallback message + if (!$aiResponse) { + $aiResponse = 'Vielen Dank für Ihre Nachricht. Ich melde mich so schnell wie möglich bei Ihnen.'; + } sendResponse(true, 'Nachricht gesendet', array_merge($debugData ?? [], [ 'session_id' => $sessionId, diff --git a/Profice WebSite/scripts/hex-background.js b/Profice WebSite/scripts/hex-background.js index 2f27fd0..809a480 100644 --- a/Profice WebSite/scripts/hex-background.js +++ b/Profice WebSite/scripts/hex-background.js @@ -14,9 +14,9 @@ maxLineWidth: 2.5, baseOpacity: 0.15, maxOpacity: 0.6, - magnetRadius: 200, - maxDisplacement: 12, - returnSpeed: 0.25, // Faster return to prevent color lag + magnetRadius: 350, // Larger radius for 16:9/16:10 monitors + maxDisplacement: 15, + returnSpeed: 0.35, // Faster return to reset colors quickly // Base color (neutral gray) baseR: 119, baseG: 119, baseB: 100, // Colors for proximity effect (teal to orange) @@ -63,7 +63,7 @@ const dy = mouseY - this.originY; const distance = Math.sqrt(dx * dx + dy * dy); - if (distance < CONFIG.magnetRadius && distance > 0) { + if (distance < CONFIG.magnetRadius && distance > 0 && mouseX > -500 && mouseY > -500) { // Calculate influence (stronger when closer) const influence = 1 - (distance / CONFIG.magnetRadius); const easedInfluence = easeOutCubic(influence); @@ -85,14 +85,20 @@ this.lineWidth = CONFIG.lineWidth + (CONFIG.maxLineWidth - CONFIG.lineWidth) * easedInfluence; this.colorInfluence = easedInfluence; } else { - // Return to origin with spring effect - this.currentX += (this.originX - this.currentX) * CONFIG.returnSpeed; - this.currentY += (this.originY - this.currentY) * CONFIG.returnSpeed; + // Return to origin with spring effect - use faster speed for reset + const resetSpeed = CONFIG.returnSpeed * 1.5; + this.currentX += (this.originX - this.currentX) * resetSpeed; + this.currentY += (this.originY - this.currentY) * resetSpeed; - // Fade back to default - this.opacity += (CONFIG.baseOpacity - this.opacity) * CONFIG.returnSpeed; - this.lineWidth += (CONFIG.lineWidth - this.lineWidth) * CONFIG.returnSpeed; - this.colorInfluence += (0 - this.colorInfluence) * CONFIG.returnSpeed; + // Fade back to default - faster color reset + this.opacity += (CONFIG.baseOpacity - this.opacity) * resetSpeed; + this.lineWidth += (CONFIG.lineWidth - this.lineWidth) * resetSpeed; + this.colorInfluence += (0 - this.colorInfluence) * resetSpeed; + + // Force reset if very close to default + if (this.colorInfluence < 0.005) this.colorInfluence = 0; + if (Math.abs(this.opacity - CONFIG.baseOpacity) < 0.005) this.opacity = CONFIG.baseOpacity; + if (Math.abs(this.lineWidth - CONFIG.lineWidth) < 0.01) this.lineWidth = CONFIG.lineWidth; } } @@ -239,10 +245,10 @@ const distance = Math.sqrt(dx * dx + dy * dy); // Check if position OR color needs to return to default - const isReturning = Math.abs(hex.currentX - hex.originX) > 0.1 || - Math.abs(hex.currentY - hex.originY) > 0.1 || - hex.colorInfluence > 0.01 || - hex.opacity > CONFIG.baseOpacity + 0.01; + const isReturning = Math.abs(hex.currentX - hex.originX) > 0.05 || + Math.abs(hex.currentY - hex.originY) > 0.05 || + hex.colorInfluence > 0.001 || + hex.opacity > CONFIG.baseOpacity + 0.001; if (distance < updateRadius || isReturning) { hex.update(mouse.x, mouse.y);