Spaces:
Configuration error
Configuration error
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Makale Chatbot</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 20px; | |
} | |
.container { | |
max-width: 600px; | |
margin: auto; | |
} | |
form { | |
display: flex; | |
flex-direction: column; | |
} | |
label, input, button { | |
margin-bottom: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Bilgileri Doldurunuz!</h1> | |
<form id="dataForm"> | |
<label for="title">Başlık:</label> | |
<input type="text" id="title" name="title" required> | |
<label for="text">Metin:</label> | |
<textarea id="text" name="text" rows="4" required></textarea> | |
<label for="keywords">Anahtar Kelimeler:</label> | |
<input type="text" id="keywords" name="keywords" required> | |
<button type="submit">Sonuç</button> | |
</form> | |
<p id="responseMessage"></p> | |
</div> | |
<script> | |
// Kullanıcı ID'sini almak için GET isteği | |
async function getUserId() { | |
const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/user'; // Kullanıcı ID'si almak için API Gateway URL'nizi buraya koyun | |
try { | |
const response = await fetch(apiUrl); | |
const result = await response.json(); | |
return result.user_id; // API'nin döndürdüğü kullanıcı ID'sini döndürün | |
} catch (error) { | |
console.error('Error fetching user ID:', error); | |
return null; | |
} | |
} | |
document.getElementById('dataForm').addEventListener('submit', async (e) => { | |
e.preventDefault(); | |
const userId = await getUserId(); | |
if (!userId) { | |
document.getElementById('responseMessage').textContent = 'Unable to get user ID.'; | |
return; | |
} | |
const title = document.getElementById('title').value; | |
const text = document.getElementById('text').value; | |
const keywords = document.getElementById('keywords').value; | |
const apiUrl = 'https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/users'; // API Gateway URL'nizi buraya koyun | |
try { | |
const response = await fetch(apiUrl, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ user_id: userId, title: title, text: text, keywords: keywords }) | |
}); | |
const result = await response.json(); | |
document.getElementById('responseMessage').textContent = `Response: ${JSON.stringify(result)}`; | |
} catch (error) { | |
document.getElementById('responseMessage').textContent = `Error: ${error}`; | |
} | |
}); | |
</script> | |
</body> | |
</html> | |