File size: 2,014 Bytes
6494aa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
license: artistic-2.0
---
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ChatBot</title>
    <link href="https://cdn.jsdelivr.net/npm/daisyui@3.9.4/dist/full.css" rel="stylesheet" type="text/css" />
    <script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 h-screen flex items-center justify-center">
    <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
        <h1 class="text-2xl font-bold mb-4 text-center">Your Friendly ChatBot</h1>
        <div id="chatbox" class="chat chat-start h-96 overflow-y-auto mb-4"></div>
        <div class="flex">
            <input type="text" id="inputMessage" placeholder="Type your message here..." class="input input-bordered flex-grow">
            <button id="sendMessage" class="btn btn-primary ml-2">Send</button>
        </div>
    </div>

    <script>
        var inputMessage = document.getElementById("inputMessage");
        var sendMessage = document.getElementById("sendMessage");
        var chatbox = document.getElementById("chatbox");

        sendMessage.addEventListener("click", function() {
            var message = inputMessage.value;
            if (message.trim() !== "") {
                sendMessageToChat(message, "user");
                inputMessage.value = "";
                sendMessageToChat("Sorry, the chatbot is unavailable at the moment. Please try again later.", "assistant"); 
            }
        });

        function sendMessageToChat(message, role) {
            var messageElement = document.createElement("div");
            messageElement.classList.add("chat-bubble", role === "user" ? "chat-bubble-primary" : "chat-bubble-secondary");
            messageElement.innerHTML = "<p><strong>" + role + ":</strong> " + message + "</p>";
            chatbox.appendChild(messageElement);
            chatbox.scrollTop = chatbox.scrollHeight;
        }
    </script>
</body>
</html>