1221
This commit is contained in:
@@ -541,19 +541,29 @@ function handleChatMessage($data) {
|
|||||||
sendResponse(false, 'Nachricht darf nicht leer sein', null, 400);
|
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 = [
|
$chatData = [
|
||||||
'type' => 'chat_message',
|
'type' => 'chat_message',
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
'chatInput' => $message, // Alternative field name for n8n
|
||||||
|
'query' => $message, // Another common n8n field name
|
||||||
'timestamp' => date('c'),
|
'timestamp' => date('c'),
|
||||||
'source' => 'website_chat',
|
'source' => 'website_chat',
|
||||||
'ip_address' => getClientIP(),
|
'ip_address' => getClientIP(),
|
||||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? ''
|
'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
|
// Send to KI Chat webhook
|
||||||
$webhookResult = sendToWebhook($chatData, KI_CHAT_WEBHOOK_URL);
|
$webhookResult = sendToWebhook($chatData, KI_CHAT_WEBHOOK_URL);
|
||||||
|
|
||||||
|
// Log the response for debugging
|
||||||
|
error_log('KI Chat Response: ' . json_encode($webhookResult));
|
||||||
|
|
||||||
$debugData = DEBUG_MODE ? [
|
$debugData = DEBUG_MODE ? [
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
'webhook_result' => $webhookResult,
|
'webhook_result' => $webhookResult,
|
||||||
@@ -561,9 +571,32 @@ function handleChatMessage($data) {
|
|||||||
] : null;
|
] : null;
|
||||||
|
|
||||||
if ($webhookResult['success']) {
|
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);
|
$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 ?? [], [
|
sendResponse(true, 'Nachricht gesendet', array_merge($debugData ?? [], [
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
maxLineWidth: 2.5,
|
maxLineWidth: 2.5,
|
||||||
baseOpacity: 0.15,
|
baseOpacity: 0.15,
|
||||||
maxOpacity: 0.6,
|
maxOpacity: 0.6,
|
||||||
magnetRadius: 200,
|
magnetRadius: 350, // Larger radius for 16:9/16:10 monitors
|
||||||
maxDisplacement: 12,
|
maxDisplacement: 15,
|
||||||
returnSpeed: 0.25, // Faster return to prevent color lag
|
returnSpeed: 0.35, // Faster return to reset colors quickly
|
||||||
// Base color (neutral gray)
|
// Base color (neutral gray)
|
||||||
baseR: 119, baseG: 119, baseB: 100,
|
baseR: 119, baseG: 119, baseB: 100,
|
||||||
// Colors for proximity effect (teal to orange)
|
// Colors for proximity effect (teal to orange)
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
const dy = mouseY - this.originY;
|
const dy = mouseY - this.originY;
|
||||||
const distance = Math.sqrt(dx * dx + dy * dy);
|
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)
|
// Calculate influence (stronger when closer)
|
||||||
const influence = 1 - (distance / CONFIG.magnetRadius);
|
const influence = 1 - (distance / CONFIG.magnetRadius);
|
||||||
const easedInfluence = easeOutCubic(influence);
|
const easedInfluence = easeOutCubic(influence);
|
||||||
@@ -85,14 +85,20 @@
|
|||||||
this.lineWidth = CONFIG.lineWidth + (CONFIG.maxLineWidth - CONFIG.lineWidth) * easedInfluence;
|
this.lineWidth = CONFIG.lineWidth + (CONFIG.maxLineWidth - CONFIG.lineWidth) * easedInfluence;
|
||||||
this.colorInfluence = easedInfluence;
|
this.colorInfluence = easedInfluence;
|
||||||
} else {
|
} else {
|
||||||
// Return to origin with spring effect
|
// Return to origin with spring effect - use faster speed for reset
|
||||||
this.currentX += (this.originX - this.currentX) * CONFIG.returnSpeed;
|
const resetSpeed = CONFIG.returnSpeed * 1.5;
|
||||||
this.currentY += (this.originY - this.currentY) * CONFIG.returnSpeed;
|
this.currentX += (this.originX - this.currentX) * resetSpeed;
|
||||||
|
this.currentY += (this.originY - this.currentY) * resetSpeed;
|
||||||
|
|
||||||
// Fade back to default
|
// Fade back to default - faster color reset
|
||||||
this.opacity += (CONFIG.baseOpacity - this.opacity) * CONFIG.returnSpeed;
|
this.opacity += (CONFIG.baseOpacity - this.opacity) * resetSpeed;
|
||||||
this.lineWidth += (CONFIG.lineWidth - this.lineWidth) * CONFIG.returnSpeed;
|
this.lineWidth += (CONFIG.lineWidth - this.lineWidth) * resetSpeed;
|
||||||
this.colorInfluence += (0 - this.colorInfluence) * CONFIG.returnSpeed;
|
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);
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
// Check if position OR color needs to return to default
|
// Check if position OR color needs to return to default
|
||||||
const isReturning = Math.abs(hex.currentX - hex.originX) > 0.1 ||
|
const isReturning = Math.abs(hex.currentX - hex.originX) > 0.05 ||
|
||||||
Math.abs(hex.currentY - hex.originY) > 0.1 ||
|
Math.abs(hex.currentY - hex.originY) > 0.05 ||
|
||||||
hex.colorInfluence > 0.01 ||
|
hex.colorInfluence > 0.001 ||
|
||||||
hex.opacity > CONFIG.baseOpacity + 0.01;
|
hex.opacity > CONFIG.baseOpacity + 0.001;
|
||||||
|
|
||||||
if (distance < updateRadius || isReturning) {
|
if (distance < updateRadius || isReturning) {
|
||||||
hex.update(mouse.x, mouse.y);
|
hex.update(mouse.x, mouse.y);
|
||||||
|
|||||||
Reference in New Issue
Block a user