a
This commit is contained in:
@@ -604,18 +604,12 @@ 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
|
// Format data for n8n webhook - simplified format that n8n expects
|
||||||
// which is commonly expected by n8n AI chat workflows
|
|
||||||
$chatData = [
|
$chatData = [
|
||||||
'type' => 'chat_message',
|
'chatInput' => $message, // Main field for n8n AI Agent
|
||||||
'session_id' => $sessionId,
|
'session_id' => $sessionId,
|
||||||
'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(),
|
|
||||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? ''
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Log the outgoing request for debugging
|
// Log the outgoing request for debugging
|
||||||
@@ -734,11 +728,33 @@ $requestType = $data['type'] ?? 'contact';
|
|||||||
|
|
||||||
// Debug endpoint to test webhook connectivity
|
// Debug endpoint to test webhook connectivity
|
||||||
if ($requestType === 'test_webhook') {
|
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);
|
$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', [
|
sendResponse(true, 'Webhook test completed', [
|
||||||
'webhook_url' => KI_CHAT_WEBHOOK_URL,
|
'webhook_url' => KI_CHAT_WEBHOOK_URL,
|
||||||
'result' => $result,
|
'result' => $result,
|
||||||
|
'raw_curl' => [
|
||||||
|
'response' => $rawResponse,
|
||||||
|
'http_code' => $rawHttpCode,
|
||||||
|
'error' => $rawError
|
||||||
|
],
|
||||||
'curl_available' => function_exists('curl_init'),
|
'curl_available' => function_exists('curl_init'),
|
||||||
'allow_url_fopen' => ini_get('allow_url_fopen')
|
'allow_url_fopen' => ini_get('allow_url_fopen')
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user