Skip to content

Commit

Permalink
add chatbot to website
Browse files Browse the repository at this point in the history
  • Loading branch information
MariferVL committed Sep 19, 2023
1 parent af6d6f2 commit 41821e7
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 3 deletions.
77 changes: 77 additions & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ body {
padding: 0;
}


header {
background-color: transparent;
color: #fff;
Expand Down Expand Up @@ -121,6 +122,82 @@ h2 {
margin-bottom: 1rem;
}

/* Chatbot */

#chat-button {
background-color: #37a21f;
color: #ffffff;
border: none;
border-radius: 50%;
width: 50px;
height: 50px;
position: fixed;
bottom: 20px;
right: 20px;
cursor: pointer;
}

#chat-container {
width: 400px;
margin: 20px auto;
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}

#chat-header {
background-color: #37a21f;
color: #ffffff;
padding: 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}

#chat-messages {
padding: 10px;
max-height: 400px;
overflow-y: auto;
}

.message {
margin-bottom: 10px;
padding: 10px;
border-radius: 5px;
}

.user-message {
background-color: #37a21f;
color: #ffffff;
align-self: flex-end;
}

.bot-message {
background-color: #f7f8ff;
color: #303235;
}

#input-container {
display: flex;
padding: 10px;
}

#user-input {
flex-grow: 1;
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
}

#send-button {
background-color: #37a21f;
color: #ffffff;
border: none;
border-radius: 5px;
padding: 5px 10px;
margin-left: 5px;
cursor: pointer;
}


footer {
text-align: center;
Expand Down
23 changes: 20 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<meta name="description" content="Sitio web sobre la Ley REP en Chile y el reciclaje con un chatbot de consulta.">
<title>Recicla Chile</title>

<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="./css/styles.css">

<meta name="keywords" content="Ley REP, reciclaje, Chile">
<link rel="icon" href="images/favicon/favicon-32x32.png" type="image/x-icon">

<meta property="og:title" content="Recicla Chile">
<meta property="og:description"
content="Sitio web sobre la Ley REP en Chile y el reciclaje con un chatbot de consulta.">
Expand All @@ -28,6 +28,21 @@
</head>

<body>
<button id="chat-button">Chat</button>

<div id="chat-container" style="display: none;">
<div id="chat-header">
Chatbot
</div>
<div id="chat-messages">
<!-- Aquí se mostrarán los mensajes -->
</div>
<div id="input-container">
<input type="text" id="user-input" placeholder="Type your question">
<button id="send-button">Send</button>
</div>
</div>

<header>
<div class="navbar">
<div class="navbar-left">
Expand Down Expand Up @@ -106,7 +121,9 @@ <h2>Enlaces de Interés</h2>
<p>&copy; 2023 Recicla Chile. Todos los derechos reservados.</p>
</footer>

<script src="../src/firebase.js"></script>
<script src="/src/firebase.js"></script>
<script src="/src/index.js"></script>
<script src="/src/chatbot.js"></script>
</body>

</html>
40 changes: 40 additions & 0 deletions src/chatbot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');

function addUserMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.classList.add('message', 'user-message');
messageDiv.textContent = message;
chatMessages.appendChild(messageDiv);
}

function addBotMessage(message) {
const messageDiv = document.createElement('div');
messageDiv.classList.add('message', 'bot-message');
messageDiv.textContent = message;
chatMessages.appendChild(messageDiv);
}

sendButton.addEventListener('click', () => {
const userMessage = userInput.value;
if (userMessage.trim() !== '') {
addUserMessage(userMessage);
// Aquí puedes agregar lógica para responder como un bot
// Por ejemplo: addBotMessage("Respuesta del bot...");
userInput.value = '';
}
});


const chatContainer = document.getElementById('chat-container');
const chatButton = document.getElementById('chat-button');

chatButton.addEventListener('click', () => {
if (chatContainer.style.display === 'none') {
chatContainer.style.display = 'block';
} else {
chatContainer.style.display = 'none';
}
});

0 comments on commit 41821e7

Please sign in to comment.