update
This commit is contained in:
@@ -48,8 +48,8 @@ define('USE_PRODUCTION', false); // Use test webhook for debugging
|
||||
define('DEBUG_MODE', true); // Enable debug to see errors
|
||||
|
||||
// N8N Webhooks
|
||||
define('WEBHOOK_TEST', 'https://n8n.profice.de/webhook-test/d94ef798-3f43-46dd-8207-1e335e64518f');
|
||||
define('WEBHOOK_PROD', 'https://n8n.profice.de/webhook/d94ef798-3f43-46dd-8207-1e335e64518f');
|
||||
define('WEBHOOK_TEST', 'https://n8n.profice.de/webhook-test/8658d57e-2348-4046-90a5-7551708f8d50');
|
||||
define('WEBHOOK_PROD', 'https://n8n.profice.de/webhook/8658d57e-2348-4046-90a5-7551708f8d50');
|
||||
define('WEBHOOK_URL', USE_PRODUCTION ? WEBHOOK_PROD : WEBHOOK_TEST);
|
||||
|
||||
// Google Analytics
|
||||
@@ -492,30 +492,6 @@ function handleContactForm($data) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleLoginForm($data) {
|
||||
$required = ['email', 'password'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($data[$field])) {
|
||||
sendResponse(false, "Pflichtfeld fehlt: {$field}", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Add your login logic here
|
||||
sendResponse(true, 'Login erfolgreich');
|
||||
}
|
||||
|
||||
function handleRegisterForm($data) {
|
||||
$required = ['name', 'email', 'password'];
|
||||
foreach ($required as $field) {
|
||||
if (empty($data[$field])) {
|
||||
sendResponse(false, "Pflichtfeld fehlt: {$field}", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Add your registration logic here
|
||||
sendResponse(true, 'Registrierung erfolgreich');
|
||||
}
|
||||
|
||||
function handleLeadForm($data) {
|
||||
// Handle lead form submissions
|
||||
$leadId = storeLead($data);
|
||||
@@ -549,6 +525,49 @@ function handleGetTrackingConfig($data) {
|
||||
sendResponse(true, 'Tracking-Konfiguration', $config);
|
||||
}
|
||||
|
||||
function handleChatMessage($data) {
|
||||
$message = sanitizeInput($data['message'] ?? '');
|
||||
$sessionId = sanitizeInput($data['session_id'] ?? uniqid('chat_'));
|
||||
|
||||
if (empty($message)) {
|
||||
sendResponse(false, 'Nachricht darf nicht leer sein', null, 400);
|
||||
}
|
||||
|
||||
$chatData = [
|
||||
'type' => 'chat_message',
|
||||
'session_id' => $sessionId,
|
||||
'message' => $message,
|
||||
'timestamp' => date('c'),
|
||||
'source' => 'website_chat',
|
||||
'ip_address' => getClientIP(),
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? ''
|
||||
];
|
||||
|
||||
// Send to webhook
|
||||
$webhookResult = sendToWebhook($chatData);
|
||||
|
||||
$debugData = DEBUG_MODE ? [
|
||||
'session_id' => $sessionId,
|
||||
'webhook_result' => $webhookResult,
|
||||
'webhook_url' => WEBHOOK_URL
|
||||
] : null;
|
||||
|
||||
if ($webhookResult['success']) {
|
||||
// Try to parse response from webhook
|
||||
$response = json_decode($webhookResult['response'], true);
|
||||
$aiResponse = $response['message'] ?? '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,
|
||||
'ai_response' => $aiResponse,
|
||||
'timestamp' => date('c')
|
||||
]));
|
||||
} else {
|
||||
error_log('Chat webhook failed: ' . json_encode($webhookResult));
|
||||
sendResponse(false, 'Chat-Service derzeit nicht verfügbar. Bitte versuchen Sie es später erneut.', $debugData, 503);
|
||||
}
|
||||
}
|
||||
|
||||
function handleTrackEvent($data) {
|
||||
$eventName = $data['event_name'] ?? '';
|
||||
$eventData = $data['event_data'] ?? [];
|
||||
@@ -605,12 +624,6 @@ try {
|
||||
case 'contact':
|
||||
handleContactForm($data);
|
||||
break;
|
||||
case 'login':
|
||||
handleLoginForm($data);
|
||||
break;
|
||||
case 'register':
|
||||
handleRegisterForm($data);
|
||||
break;
|
||||
case 'lead':
|
||||
handleLeadForm($data);
|
||||
break;
|
||||
@@ -626,6 +639,9 @@ try {
|
||||
case 'track_event':
|
||||
handleTrackEvent($data);
|
||||
break;
|
||||
case 'chat':
|
||||
handleChatMessage($data);
|
||||
break;
|
||||
default:
|
||||
sendResponse(false, 'Ungültiger Anfragetyp', null, 400);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user