34434-vm/api/chat.php
Flatlogic Bot 51699f43c2 Friend1.0
2025-09-27 11:05:52 +00:00

29 lines
1.1 KiB
PHP

<?php
header('Content-Type: application/json');
// Get the user's message from the POST request
$data = json_decode(file_get_contents('php://input'), true);
$userMessage = $data['message'] ?? '';
// Simple rule-based responses
$responses = [
'hello' => 'Hi there! How are you feeling today?',
'hi' => 'Hello! So glad you're here. What's on your mind?',
'how are you' => 'I'm just a humble chatbot, but I'm here for you! How can I help?',
'i feel sad' => 'I'm sorry to hear that. Remember that it's okay to feel sad sometimes. Talking about it can help.',
'i feel lonely' => 'I understand. Loneliness is a tough feeling. I'm here to keep you company.',
'thank you' => 'You're welcome! I'm always here if you need to talk.',
'bye' => 'Goodbye for now. Remember to take care of yourself!'
];
$response = 'I'm not sure how to respond to that yet, but I'm learning. Could you tell me more?';
foreach ($responses as $key => $value) {
if (stripos(strtolower($userMessage), $key) !== false) {
$response = $value;
break;
}
}
echo json_encode(['reply' => $response]);
?>