-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BTS Album order chatbot #292
Open
cholpoun
wants to merge
4
commits into
Technigo:main
Choose a base branch
from
cholpoun:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" | ||
rel="stylesheet" /> | ||
<title>Chatbot</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Welcome to my chatbot!</h1> | ||
<main> | ||
<section class="chat" id="chat"></section> | ||
<div class="input-wrapper" id="input-wrapper"> | ||
<form id="name-form"> | ||
<label for="name-input">Name</label> | ||
<input id="name-input" type="text" /> | ||
<button class="send-btn" type="submit"> | ||
Send | ||
</button> | ||
</form> | ||
</div> | ||
</main> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="stylesheet" href="./style.css" /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900&display=swap" | ||
rel="stylesheet" /> | ||
<title>Weverse chatbot</title> | ||
</head> | ||
|
||
<body> | ||
<h1>Weverse chatbot: Order your BTS album!</h1> | ||
|
||
<main> | ||
<section class="chat" id="chat"></section> | ||
|
||
<div class="input-wrapper" id="input-wrapper"> | ||
|
||
<form id="name-form"> | ||
<input id="name-input" type="text" /> | ||
|
||
|
||
|
||
|
||
<button class="send-btn" type="submit">Send</button> | ||
</form> | ||
</div> | ||
</main> | ||
|
||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,200 @@ | ||
// DOM selectors (variables that point to selected DOM elements) goes here 👇 | ||
const chat = document.getElementById('chat') | ||
const chat = document.getElementById('chat'); | ||
const form = document.getElementById('name-form'); | ||
const nameInput = document.getElementById('name-input'); | ||
const inputWrapper = document.querySelector('.input-wrapper'); // Wrapper for the input field | ||
|
||
// Functions goes here 👇 | ||
// Show album options function | ||
const showAlbumOptions = (name) => { | ||
showMessage(`Hello ${name}, welcome to Weverse! Which BTS album would you like to order?`, 'bot'); | ||
|
||
// A function that will add a chat bubble in the correct place based on who the sender is | ||
// Hide the input form and show the album options | ||
form.style.display = 'none'; // Hide the input field and send button | ||
|
||
// Add album option buttons | ||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<div class="bubble bot-bubble"> | ||
<button id="golden-btn">Golden</button> | ||
<button id="muse-btn">Muse</button> | ||
<button id="layover-btn">Layover</button> | ||
</div> | ||
</section> | ||
`; | ||
|
||
// Add event listeners to album option buttons | ||
document.getElementById('golden-btn').addEventListener('click', () => showSubtypes('Golden')); | ||
document.getElementById('muse-btn').addEventListener('click', () => showSubtypes('Muse')); | ||
document.getElementById('layover-btn').addEventListener('click', () => showSubtypes('Layover')); | ||
|
||
chat.scrollTop = chat.scrollHeight; | ||
}; | ||
|
||
// Show subtypes based on album selection | ||
const showSubtypes = (album) => { | ||
let subtypes = ''; | ||
|
||
// Subtypes for each album category | ||
if (album === 'Golden') { | ||
subtypes = ` | ||
<button id="golden-special-btn">Special edition</button> | ||
<button id="golden-vynil-btn">Vynil</button> | ||
<button id="golden-limited-btn">Limited edition</button> | ||
`; | ||
} else if (album === 'Muse') { | ||
subtypes = ` | ||
<button id="muse-weverse-btn">Weverse version</button> | ||
<button id="muse-limited-btn">Limited edition</button> | ||
<button id="muse-vynil-btn">Vynil</button> | ||
`; | ||
} else if (album === 'Layover') { | ||
subtypes = ` | ||
<button id="layover-vynil-btn">Vynil</button> | ||
<button id="layover-special-btn">Special edition</button> | ||
<button id="layover-limited-btn">Limited edition</button> | ||
`; | ||
} | ||
|
||
// Display the subtypes | ||
showMessage(`Which ${album} would you like to order?`, 'bot'); | ||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<div class="bubble bot-bubble"> | ||
${subtypes} | ||
</div> | ||
</section> | ||
`; | ||
|
||
// Add event listeners to the subtype buttons | ||
if (album === 'Golden') { | ||
document.getElementById('golden-special-btn').addEventListener('click', () => askRandomOrSet('Special edition')); | ||
document.getElementById('golden-vynil-btn').addEventListener('click', () => askRandomOrSet('Vynil')); | ||
document.getElementById('golden-limited-btn').addEventListener('click', () => askRandomOrSet('Limited edition')); | ||
} else if (album === 'Muse') { | ||
document.getElementById('muse-weverse-btn').addEventListener('click', () => askRandomOrSet('Weverse edition')); | ||
document.getElementById('muse-limited-btn').addEventListener('click', () => askRandomOrSet('Limited edition')); | ||
document.getElementById('muse-vynil-btn').addEventListener('click', () => askRandomOrSet('Vynil')); | ||
} else if (album === 'Layover') { | ||
document.getElementById('layover-vynil-btn').addEventListener('click', () => askRandomOrSet('Vynil')); | ||
document.getElementById('layover-special-btn').addEventListener('click', () => askRandomOrSet('Special edition')); | ||
document.getElementById('layover-limited-btn').addEventListener('click', () => askRandomOrSet('Limited edition')); | ||
} | ||
|
||
chat.scrollTop = chat.scrollHeight; | ||
}; | ||
|
||
// Ask if the order is for a Random or Set | ||
const askRandomOrSet = (album) => { | ||
showMessage(`Do you want the random or set collection of the ${album} album?`, 'bot'); | ||
|
||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<div class="bubble bot-bubble"> | ||
<button id="random-btn">Random</button> | ||
<button id="set-btn">Set</button> | ||
</div> | ||
</section> | ||
`; | ||
|
||
document.getElementById('random-btn').addEventListener('click', () => finalizeOrder(album, 'Random', 150)); | ||
document.getElementById('set-btn').addEventListener('click', () => finalizeOrder(album, 'Set', 200)); | ||
|
||
chat.scrollTop = chat.scrollHeight; | ||
}; | ||
|
||
// Finalize the order with the selected album and if it's for a Random or Set, and show the price | ||
const finalizeOrder = (album, person, price) => { | ||
showMessage(`I'd like to order ${person} collection of the ${album}. Thank you!`, 'user'); | ||
|
||
|
||
setTimeout(() => { | ||
showMessage(`You chose ${album} and ${person} option. The price is ${price} SEK.`, 'bot'); | ||
askForDeliveryAddress(); // Ask for the delivery address after confirming the price | ||
}, 1000); | ||
}; | ||
|
||
// Ask for the delivery address | ||
const askForDeliveryAddress = () => { | ||
showMessage("Please enter your delivery address.", 'bot'); | ||
|
||
// Show the input form to collect the address | ||
form.style.display = 'flex'; | ||
nameInput.placeholder = 'Enter delivery address'; // Change the placeholder for address input | ||
nameInput.value = ''; // Clear the input field | ||
|
||
// Change the form submission handler to collect the address | ||
form.removeEventListener('submit', handleNameInput); // Remove the name input handler | ||
form.addEventListener('submit', handleAddressInput); // Add address input handler | ||
}; | ||
|
||
// Handle delivery address input | ||
const handleAddressInput = (event) => { | ||
event.preventDefault(); | ||
|
||
const address = nameInput.value; // Capture the address | ||
showMessage(`My delivery address is: ${address}`, 'user'); | ||
|
||
// Clear the input field after the user submits the address | ||
nameInput.value = ''; | ||
|
||
setTimeout(() => { | ||
showMessage(`Thank you! Your order will be delivered to ${address}.`, 'bot'); | ||
displayContactInfo(); // Show contact info and hide the input bar after confirming the address | ||
}, 1000); | ||
}; | ||
|
||
// Display contact information and hide the input bar | ||
const displayContactInfo = () => { | ||
setTimeout(() => { | ||
showMessage("If you have any questions, reach out to [email protected]", 'bot'); | ||
form.style.display = 'none'; // Hide the input field and send button | ||
}, 1000); | ||
}; | ||
|
||
// Handle name input submission | ||
const handleNameInput = (event) => { | ||
event.preventDefault(); | ||
|
||
const name = nameInput.value; | ||
showMessage(name, 'user'); | ||
nameInput.value = ''; | ||
|
||
// Show album options after 1 second delay | ||
setTimeout(() => showAlbumOptions(name), 1000); | ||
}; | ||
|
||
// Show message function | ||
const showMessage = (message, sender) => { | ||
// The if statement checks if the sender is the user and if that's the case it inserts | ||
// an HTML section inside the chat with the posted message from the user | ||
if (sender === 'user') { | ||
chat.innerHTML += ` | ||
<section class="user-msg"> | ||
<div class="bubble user-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
<img src="assets/user.png" alt="User" /> | ||
<img src="https://images.fineartamerica.com/images/artworkimages/medium/3/bts-army-logo-angel-purpletete-transparent.png" alt="User" /> | ||
</section> | ||
` | ||
// The else if statement checks if the sender is the bot and if that's the case it inserts | ||
// an HTML section inside the chat with the posted message from the bot | ||
`; | ||
} else if (sender === 'bot') { | ||
chat.innerHTML += ` | ||
<section class="bot-msg"> | ||
<img src="assets/bot.png" alt="Bot" /> | ||
<img src="https://e7.pngegg.com/pngimages/307/249/png-clipart-bts-love-yourself-her-k-pop-logo-korean-language-bts-logo-purple-angle.png" alt="Bot" /> | ||
<div class="bubble bot-bubble"> | ||
<p>${message}</p> | ||
</div> | ||
</section> | ||
` | ||
`; | ||
} | ||
|
||
// This little thing makes the chat scroll to the last message when there are too many to | ||
// be shown in the chat box | ||
chat.scrollTop = chat.scrollHeight | ||
} | ||
chat.scrollTop = chat.scrollHeight; | ||
}; | ||
|
||
// A function to start the conversation | ||
// Greet the user at the start | ||
const greetUser = () => { | ||
// Here we call the function showMessage, that we declared earlier with the argument: | ||
// "Hello there, what's your name?" for message, and the argument "bot" for sender | ||
showMessage("Hello there, what's your name?", 'bot') | ||
// Just to check it out, change 'bot' to 'user' here 👆 and see what happens | ||
} | ||
|
||
// Eventlisteners goes here 👇 | ||
|
||
// Here we invoke the first function to get the chatbot to ask the first question when | ||
// the website is loaded. Normally we invoke functions like this: greeting() | ||
// To add a little delay to it, we can wrap it in a setTimeout (a built in JavaScript function): | ||
// and pass along two arguments: | ||
// 1.) the function we want to delay, and 2.) the delay in milliseconds | ||
// This means the greeting function will be called one second after the website is loaded. | ||
setTimeout(greetUser, 1000) | ||
showMessage("Hello BTS ARMY, welcome to Weverse! What's your name?", 'bot'); | ||
}; | ||
|
||
// Add event listener to the form submission | ||
form.addEventListener('submit', handleNameInput); | ||
|
||
// Initial greeting on page load | ||
setTimeout(greetUser, 1000); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all these buttons that the user should click, would fit better in the inputWrapper 👀