This commit is contained in:
2026-02-19 12:56:01 +01:00
parent 00cc9635ae
commit 0ecc994df4

View File

@@ -604,18 +604,12 @@ 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
// Format data for n8n webhook - simplified format that n8n expects
$chatData = [
'type' => 'chat_message',
'chatInput' => $message, // Main field for n8n AI Agent
'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'] ?? ''
'source' => 'website_chat'
];
// Log the outgoing request for debugging
@@ -734,11 +728,33 @@ $requestType = $data['type'] ?? 'contact';
// Debug endpoint to test webhook connectivity
if ($requestType === 'test_webhook') {
$testData = ['test' => true, 'timestamp' => date('c')];
// Test with simple curl command
$testData = ['chatInput' => 'Test message', 'timestamp' => date('c')];
$result = sendToWebhook($testData, KI_CHAT_WEBHOOK_URL);
// Also test raw curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, KI_CHAT_WEBHOOK_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($testData));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$rawResponse = curl_exec($ch);
$rawHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$rawError = curl_error($ch);
curl_close($ch);
sendResponse(true, 'Webhook test completed', [
'webhook_url' => KI_CHAT_WEBHOOK_URL,
'result' => $result,
'raw_curl' => [
'response' => $rawResponse,
'http_code' => $rawHttpCode,
'error' => $rawError
],
'curl_available' => function_exists('curl_init'),
'allow_url_fopen' => ini_get('allow_url_fopen')
]);