35409-vm/api/get_reply.php
Flatlogic Bot c5127ef2c4 smash 1
2025-11-02 05:02:40 +00:00

26 lines
785 B
PHP

<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../db/config.php';
try {
$pdo = db();
// Fetch one random message from the database
$stmt = $pdo->query("SELECT message FROM canned_replies ORDER BY RAND() LIMIT 1");
$result = $stmt->fetch();
$reply_message = "Thanks for your message! We'll be in touch shortly."; // Default message
if ($result) {
$reply_message = $result['message'];
}
echo json_encode(['reply' => $reply_message]);
} catch (Exception $e) {
// In case of error, return a default message
// For debugging, you might want to log the error: error_log($e->getMessage());
http_response_code(500);
echo json_encode(['reply' => 'Sorry, something went wrong. Please try again later.']);
}