prepare("INSERT INTO service_requests (name, email, description, status) VALUES (?, ?, ?, 'New')"); $stmt->execute([ $session_data['name'], $session_data['email'], $session_data['description'] ]); send_whatsapp_reply($from, "Thank you! Your service request has been booked. We will contact you shortly."); // End of conversation, so delete the session file unlink($session_file); } catch (PDOException $e) { error_log("Database Error: " . $e->getMessage()); send_whatsapp_reply($from, "Sorry, there was a problem booking your service. Please try again later."); } // Reset state for the next conversation $session_data = ['state' => 'new']; file_put_contents($session_file, json_encode($session_data)); break; default: send_whatsapp_reply($from, "Sorry, I'm not sure how to respond. Let's start over. What is your full name?"); // Reset state $session_data = ['state' => 'waiting_for_name']; file_put_contents($session_file, json_encode($session_data)); break; } echo "OK";