From 0ecc994df450224fe4964a795d7534d490dd1c4d Mon Sep 17 00:00:00 2001 From: Ihor_Zhekov Date: Thu, 19 Feb 2026 12:56:01 +0100 Subject: [PATCH] a --- Profice WebSite/scripts/add/send.php | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/Profice WebSite/scripts/add/send.php b/Profice WebSite/scripts/add/send.php index d0d8704..73d48d3 100644 --- a/Profice WebSite/scripts/add/send.php +++ b/Profice WebSite/scripts/add/send.php @@ -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') ]);