- 20 Ocak 2023
- 360
- 1
- 109
<!DOCTYPE html>
<html>
<head>
<title>Chatbot Uygulaması</title>
<style>
.chatbot-container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
background-color: #fff;
font-family: sans-serif;
}
.chatbot-header {
text-align: center;
margin-bottom: 20px;
}
.chatbot-messages-list {
list-style: none;
margin: 0;
padding: 0;
}
.chatbot-message {
margin-bottom: 10px;
}
.chatbot-message-text {
display: inline-block;
padding: 10px;
border-radius: 10px;
background-color: #f2f2f2;
color: #333;
}
</style>
</head>
<body>
<div class="chatbot-container">
<div class="chatbot-header">
<h2>Hoşgeldiniz, ben bir chatbot'um!</h2>
</div>
<div class="chatbot-messages-container">
<ul class="chatbot-messages-list">
<li class="chatbot-message">
<span class="chatbot-message-text">Merhaba, ben bir chatbot'um. Size nasıl yardımcı olabilirim?</span>
</li>
</ul>
</div>
<div class="chatbot-input-container">
<input type="text" id="message-input" placeholder="Mesajınızı buraya yazın...">
<button id="send-button">Gönder</button>
</div>
</div>
<script>
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
const chatbotMessagesList = document.querySelector('.chatbot-messages-list');
sendButton.addEventListener('click', () => {
const message = messageInput.value.trim();
if (message !== '') {
const url = `http://api.brainshop.ai/get?bid=153868&key=rcKonOgrUFmn5usX&uid=1&msg=${message}`;
fetch(url)
.then(response => response.json())
.then(data => {
let chatbotMessage;
if (message.toLowerCase() === "merhaba") {
chatbotMessage = "Merhaba! Size nasıl yardımcı olabilirim?";
} else {
chatbotMessage = data.cnt;
}
const messageItem = `
<li class="chatbot-message">
<span class="chatbot-message-text">${chatbotMessage}</span>
</li>
`;
chatbotMessagesList.insertAdjacentHTML('beforeend', messageItem);
})
.catch(error => console.error(error));
}
});
</script>
</body>
</html>
Arkadaşlar Web Siteme ChatBOT Kodlamiştim Birden Fazla Api denedim Göndere Tıklıyorum Ne Bot Cevap veriyor nede başka birşey oluyor yardım edermisiniz