Spaces:
Running
Running
Download index.html from proventimme/anycoder-951018ad: direct link, hf CLI and curl.
- Browser
- Download file 30.3 kB
-
https://huggingface.co/spaces/proventimme/anycoder-951018ad/resolve/main/index.html
- Command line
-
hf download hf://spaces/proventimme/anycoder-951018ad/index.html
-
curl -L -o index.html https://huggingface.co/spaces/proventimme/anycoder-951018ad/resolve/main/index.html
30.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Website Chatbot Builder</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| :root { | |
| --primary-color: #4a6bff; | |
| --primary-hover: #3a5bef; | |
| --secondary-color: #f8f9fa; | |
| --text-color: #333; | |
| --light-text: #666; | |
| --white: #ffffff; | |
| --shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| --border-radius: 12px; | |
| --transition: all 0.3s ease; | |
| } | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| } | |
| body { | |
| background-color: #f5f7ff; | |
| color: var(--text-color); | |
| line-height: 1.6; | |
| min-height: 100vh; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .container { | |
| max-width: 1200px; | |
| margin: 0 auto; | |
| padding: 0 20px; | |
| width: 100%; | |
| } | |
| /* Header */ | |
| header { | |
| background-color: var(--white); | |
| box-shadow: var(--shadow); | |
| padding: 15px 0; | |
| position: sticky; | |
| top: 0; | |
| z-index: 100; | |
| } | |
| .header-content { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .logo { | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| text-decoration: none; | |
| color: var(--text-color); | |
| } | |
| .logo-icon { | |
| font-size: 24px; | |
| color: var(--primary-color); | |
| } | |
| .logo-text { | |
| font-size: 18px; | |
| font-weight: 600; | |
| } | |
| .header-right { | |
| display: flex; | |
| align-items: center; | |
| gap: 20px; | |
| } | |
| .built-with { | |
| font-size: 14px; | |
| color: var(--light-text); | |
| } | |
| .built-with a { | |
| color: var(--primary-color); | |
| text-decoration: none; | |
| font-weight: 500; | |
| } | |
| /* Hero Section */ | |
| .hero { | |
| padding: 80px 0; | |
| text-align: center; | |
| background: linear-gradient(135deg, #f5f7ff 0%, #e8eaff 100%); | |
| } | |
| .hero h1 { | |
| font-size: 2.8rem; | |
| margin-bottom: 20px; | |
| line-height: 1.2; | |
| } | |
| .hero p { | |
| font-size: 1.2rem; | |
| color: var(--light-text); | |
| max-width: 700px; | |
| margin: 0 auto 40px; | |
| } | |
| .cta-button { | |
| display: inline-block; | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| padding: 12px 30px; | |
| border-radius: var(--border-radius); | |
| text-decoration: none; | |
| font-weight: 600; | |
| transition: var(--transition); | |
| box-shadow: var(--shadow); | |
| } | |
| .cta-button:hover { | |
| background-color: var(--primary-hover); | |
| transform: translateY(-2px); | |
| } | |
| /* Main Content */ | |
| .main-content { | |
| padding: 60px 0; | |
| display: grid; | |
| grid-template-columns: 1fr 1fr; | |
| gap: 60px; | |
| align-items: start; | |
| } | |
| .content-left { | |
| background-color: var(--white); | |
| padding: 40px; | |
| border-radius: var(--border-radius); | |
| box-shadow: var(--shadow); | |
| } | |
| .content-left h2 { | |
| margin-bottom: 20px; | |
| color: var(--primary-color); | |
| } | |
| .form-group { | |
| margin-bottom: 25px; | |
| } | |
| .form-group label { | |
| display: block; | |
| margin-bottom: 8px; | |
| font-weight: 500; | |
| } | |
| .form-group input { | |
| width: 100%; | |
| padding: 12px 15px; | |
| border: 1px solid #ddd; | |
| border-radius: 8px; | |
| font-size: 16px; | |
| transition: var(--transition); | |
| } | |
| .form-group input:focus { | |
| outline: none; | |
| border-color: var(--primary-color); | |
| box-shadow: 0 0 0 3px rgba(74, 107, 255, 0.1); | |
| } | |
| .form-group textarea { | |
| width: 100%; | |
| padding: 12px 15px; | |
| border: 1px solid #ddd; | |
| border-radius: 8px; | |
| font-size: 16px; | |
| min-height: 120px; | |
| resize: vertical; | |
| transition: var(--transition); | |
| } | |
| .form-group textarea:focus { | |
| outline: none; | |
| border-color: var(--primary-color); | |
| box-shadow: 0 0 0 3px rgba(74, 107, 255, 0.1); | |
| } | |
| .submit-btn { | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| border: none; | |
| padding: 12px 30px; | |
| border-radius: var(--border-radius); | |
| font-size: 16px; | |
| font-weight: 600; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| width: 100%; | |
| } | |
| .submit-btn:hover { | |
| background-color: var(--primary-hover); | |
| transform: translateY(-2px); | |
| } | |
| .content-right { | |
| position: sticky; | |
| top: 100px; | |
| } | |
| .chatbot-preview { | |
| background-color: var(--white); | |
| border-radius: var(--border-radius); | |
| box-shadow: var(--shadow); | |
| overflow: hidden; | |
| } | |
| .chatbot-header { | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| padding: 15px 20px; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| } | |
| .chatbot-title { | |
| font-weight: 600; | |
| } | |
| .chatbot-body { | |
| height: 400px; | |
| padding: 20px; | |
| overflow-y: auto; | |
| background-color: #f8f9fa; | |
| } | |
| .chat-message { | |
| margin-bottom: 15px; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .user-message { | |
| align-items: flex-end; | |
| } | |
| .bot-message { | |
| align-items: flex-start; | |
| } | |
| .message-bubble { | |
| max-width: 80%; | |
| padding: 10px 15px; | |
| border-radius: 18px; | |
| margin-bottom: 5px; | |
| position: relative; | |
| word-wrap: break-word; | |
| } | |
| .user-message .message-bubble { | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| border-bottom-right-radius: 4px; | |
| } | |
| .bot-message .message-bubble { | |
| background-color: var(--white); | |
| color: var(--text-color); | |
| border-bottom-left-radius: 4px; | |
| } | |
| .message-time { | |
| font-size: 12px; | |
| color: var(--light-text); | |
| padding: 0 10px; | |
| } | |
| .chatbot-footer { | |
| padding: 15px; | |
| background-color: var(--white); | |
| border-top: 1px solid #eee; | |
| display: flex; | |
| gap: 10px; | |
| } | |
| .chat-input { | |
| flex: 1; | |
| padding: 10px 15px; | |
| border: 1px solid #ddd; | |
| border-radius: 20px; | |
| outline: none; | |
| } | |
| .send-btn { | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| border: none; | |
| border-radius: 50%; | |
| width: 40px; | |
| height: 40px; | |
| cursor: pointer; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| transition: var(--transition); | |
| } | |
| .send-btn:hover { | |
| background-color: var(--primary-hover); | |
| } | |
| /* Features Section */ | |
| .features { | |
| padding: 60px 0; | |
| background-color: var(--white); | |
| } | |
| .features-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | |
| gap: 30px; | |
| } | |
| .feature-card { | |
| background-color: var(--secondary-color); | |
| padding: 30px; | |
| border-radius: var(--border-radius); | |
| text-align: center; | |
| transition: var(--transition); | |
| } | |
| .feature-card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: var(--shadow); | |
| } | |
| .feature-icon { | |
| font-size: 40px; | |
| color: var(--primary-color); | |
| margin-bottom: 20px; | |
| } | |
| .feature-card h3 { | |
| margin-bottom: 15px; | |
| color: var(--primary-color); | |
| } | |
| /* How It Works */ | |
| .how-it-works { | |
| padding: 60px 0; | |
| background: linear-gradient(135deg, #f5f7ff 0%, #e8eaff 100%); | |
| } | |
| .steps { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); | |
| gap: 40px; | |
| } | |
| .step { | |
| text-align: center; | |
| padding: 20px; | |
| } | |
| .step-number { | |
| width: 60px; | |
| height: 60px; | |
| background-color: var(--primary-color); | |
| color: var(--white); | |
| border-radius: 50%; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 24px; | |
| font-weight: 600; | |
| margin: 0 auto 20px; | |
| } | |
| .step h3 { | |
| margin-bottom: 10px; | |
| color: var(--primary-color); | |
| } | |
| /* Footer */ | |
| footer { | |
| background-color: #333; | |
| color: var(--white); | |
| padding: 40px 0 20px; | |
| margin-top: auto; | |
| } | |
| .footer-content { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); | |
| gap: 40px; | |
| margin-bottom: 30px; | |
| } | |
| .footer-column h3 { | |
| margin-bottom: 20px; | |
| font-size: 18px; | |
| position: relative; | |
| padding-bottom: 10px; | |
| } | |
| .footer-column h3::after { | |
| content: ''; | |
| position: absolute; | |
| left: 0; | |
| bottom: 0; | |
| width: 50px; | |
| height: 2px; | |
| background-color: var(--primary-color); | |
| } | |
| .footer-column ul { | |
| list-style: none; | |
| } | |
| .footer-column ul li { | |
| margin-bottom: 10px; | |
| } | |
| .footer-column ul li a { | |
| color: #ccc; | |
| text-decoration: none; | |
| transition: var(--transition); | |
| } | |
| .footer-column ul li a:hover { | |
| color: var(--primary-color); | |
| } | |
| .footer-bottom { | |
| text-align: center; | |
| padding-top: 20px; | |
| border-top: 1px solid #444; | |
| color: #ccc; | |
| font-size: 14px; | |
| } | |
| /* Responsive Design */ | |
| @media (max-width: 992px) { | |
| .main-content { | |
| grid-template-columns: 1fr; | |
| gap: 40px; | |
| } | |
| .content-right { | |
| position: static; | |
| } | |
| .hero h1 { | |
| font-size: 2.2rem; | |
| } | |
| .hero p { | |
| font-size: 1rem; | |
| } | |
| } | |
| @media (max-width: 768px) { | |
| .header-content { | |
| flex-direction: column; | |
| gap: 15px; | |
| } | |
| .hero { | |
| padding: 60px 0; | |
| } | |
| .hero h1 { | |
| font-size: 2rem; | |
| } | |
| .chatbot-body { | |
| height: 300px; | |
| } | |
| } | |
| @media (max-width: 576px) { | |
| .hero h1 { | |
| font-size: 1.8rem; | |
| } | |
| .hero p { | |
| font-size: 0.9rem; | |
| } | |
| .cta-button { | |
| padding: 10px 20px; | |
| font-size: 14px; | |
| } | |
| .chatbot-body { | |
| height: 250px; | |
| } | |
| } | |
| /* Loading Animation */ | |
| .loading { | |
| display: none; | |
| text-align: center; | |
| padding: 20px; | |
| } | |
| .spinner { | |
| border: 4px solid rgba(0, 0, 0, 0.1); | |
| border-radius: 50%; | |
| border-top: 4px solid var(--primary-color); | |
| width: 40px; | |
| height: 40px; | |
| animation: spin 1s linear infinite; | |
| margin: 0 auto 15px; | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| /* Success Message */ | |
| .success-message { | |
| display: none; | |
| background-color: #d4edda; | |
| color: #155724; | |
| padding: 15px; | |
| border-radius: var(--border-radius); | |
| margin-top: 20px; | |
| text-align: center; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <div class="container"> | |
| <div class="header-content"> | |
| <a href="#" class="logo"> | |
| <i class="fas fa-robot logo-icon"></i> | |
| <span class="logo-text">Website Chatbot Builder</span> | |
| </a> | |
| <div class="header-right"> | |
| <span class="built-with">Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a></span> | |
| </div> | |
| </div> | |
| </div> | |
| </header> | |
| <section class="hero"> | |
| <div class="container"> | |
| <h1>Create an AI Chatbot from Any Website</h1> | |
| <p>Transform your website content into an intelligent chatbot that can answer questions, provide information, and engage with your visitors 24/7.</p> | |
| <a href="#builder" class="cta-button">Get Started</a> | |
| </div> | |
| </section> | |
| <section class="main-content" id="builder"> | |
| <div class="container"> | |
| <div class="content-left"> | |
| <h2>Build Your Chatbot</h2> | |
| <form id="chatbotForm"> | |
| <div class="form-group"> | |
| <label for="websiteUrl">Website URL</label> | |
| <input type="url" id="websiteUrl" placeholder="https://example.com" required> | |
| </div> | |
| <div class="form-group"> | |
| <label for="chatbotName">Chatbot Name</label> | |
| <input type="text" id="chatbotName" placeholder="My Website Assistant" required> | |
| </div> | |
| <div class="form-group"> | |
| <label for="welcomeMessage">Welcome Message</label> | |
| <textarea id="welcomeMessage" placeholder="Hello! How can I help you today?" required></textarea> | |
| </div> | |
| <div class="form-group"> | |
| <label for="additionalInfo">Additional Information (Optional)</label> | |
| <textarea id="additionalInfo" placeholder="Any specific instructions or additional content for the chatbot..."></textarea> | |
| </div> | |
| <button type="submit" class="submit-btn" id="generateBtn"> | |
| <i class="fas fa-magic"></i> Generate Chatbot | |
| </button> | |
| </form> | |
| <div class="loading" id="loading"> | |
| <div class="spinner"></div> | |
| <p>Building your chatbot...</p> | |
| <p>This may take a moment as we analyze your website content.</p> | |
| </div> | |
| <div class="success-message" id="successMessage"> | |
| <i class="fas fa-check-circle"></i> | |
| <p>Your chatbot has been successfully created!</p> | |
| <p>You can now interact with it in the preview panel.</p> | |
| </div> | |
| </div> | |
| <div class="content-right"> | |
| <div class="chatbot-preview"> | |
| <div class="chatbot-header"> | |
| <div class="chatbot-title">Preview Chatbot</div> | |
| <i class="fas fa-robot"></i> | |
| </div> | |
| <div class="chatbot-body" id="chatbotBody"> | |
| <div class="chat-message bot-message"> | |
| <div class="message-bubble"> | |
| Hello! I'm your website assistant. I can help answer questions about your website content. | |
| </div> | |
| <div class="message-time">Just now</div> | |
| </div> | |
| </div> | |
| <div class="chatbot-footer"> | |
| <input type="text" class="chat-input" id="chatInput" placeholder="Type your message..." disabled> | |
| <button class="send-btn" id="sendBtn" disabled> | |
| <i class="fas fa-paper-plane"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <section class="features"> | |
| <div class="container"> | |
| <h2 style="text-align: center; margin-bottom: 50px;">Powerful Features</h2> | |
| <div class="features-grid"> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-globe"></i> | |
| </div> | |
| <h3>Website Integration</h3> | |
| <p>Seamlessly integrate with any website by simply providing the URL. Our AI will analyze and understand your content.</p> | |
| </div> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-brain"></i> | |
| </div> | |
| <h3>AI Powered</h3> | |
| <p>Advanced natural language processing to understand and respond to user queries accurately.</p> | |
| </div> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-mobile-alt"></i> | |
| </div> | |
| <h3>Responsive Design</h3> | |
| <p>Works perfectly on all devices - desktop, tablet, and mobile phones.</p> | |
| </div> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-cog"></i> | |
| </div> | |
| <h3>Customizable</h3> | |
| <p>Personalize your chatbot's appearance and behavior to match your brand.</p> | |
| </div> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-chart-line"></i> | |
| </div> | |
| <h3>Analytics</h3> | |
| <p>Track conversations and get insights about your visitors' questions and needs.</p> | |
| </div> | |
| <div class="feature-card"> | |
| <div class="feature-icon"> | |
| <i class="fas fa-lock"></i> | |
| </div> | |
| <h3>Secure</h3> | |
| <p>All conversations are encrypted and your data remains private and secure.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <section class="how-it-works"> | |
| <div class="container"> | |
| <h2 style="text-align: center; margin-bottom: 50px;">How It Works</h2> | |
| <div class="steps"> | |
| <div class="step"> | |
| <div class="step-number">1</div> | |
| <h3>Enter Website URL</h3> | |
| <p>Provide the URL of the website you want to create a chatbot for.</p> | |
| </div> | |
| <div class="step"> | |
| <div class="step-number">2</div> | |
| <h3>Customize Settings</h3> | |
| <p>Set your chatbot's name, welcome message, and any additional instructions.</p> | |
| </div> | |
| <div class="step"> | |
| <div class="step-number">3</div> | |
| <h3>Generate Chatbot</h3> | |
| <p>Our AI will analyze your website content and create an intelligent chatbot.</p> | |
| </div> | |
| <div class="step"> | |
| <div class="step-number">4</div> | |
| <h3>Deploy & Engage</h3> | |
| <p>Add the chatbot to your website and start engaging with your visitors.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </section> | |
| <footer> | |
| <div class="container"> | |
| <div class="footer-content"> | |
| <div class="footer-column"> | |
| <h3>About</h3> | |
| <p>Website Chatbot Builder helps businesses create intelligent chatbots from their website content, providing 24/7 customer support and engagement.</p> | |
| </div> | |
| <div class="footer-column"> | |
| <h3>Quick Links</h3> | |
| <ul> | |
| <li><a href="#">Home</a></li> | |
| <li><a href="#builder">Builder</a></li> | |
| <li><a href="#">Features</a></li> | |
| <li><a href="#">How It Works</a></li> | |
| </ul> | |
| </div> | |
| <div class="footer-column"> | |
| <h3>Resources</h3> | |
| <ul> | |
| <li><a href="#">Documentation</a></li> | |
| <li><a href="#">FAQ</a></li> | |
| <li><a href="#">Support</a></li> | |
| <li><a href="#">Blog</a></li> | |
| </ul> | |
| </div> | |
| <div class="footer-column"> | |
| <h3>Legal</h3> | |
| <ul> | |
| <li><a href="#">Privacy Policy</a></li> | |
| <li><a href="#">Terms of Service</a></li> | |
| <li><a href="#">Cookie Policy</a></li> | |
| </ul> | |
| </div> | |
| </div> | |
| <div class="footer-bottom"> | |
| <p>© 2023 Website Chatbot Builder. All rights reserved.</p> | |
| </div> | |
| </div> | |
| </footer> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const form = document.getElementById('chatbotForm'); | |
| const loading = document.getElementById('loading'); | |
| const successMessage = document.getElementById('successMessage'); | |
| const chatbotBody = document.getElementById('chatbotBody'); | |
| const chatInput = document.getElementById('chatInput'); | |
| const sendBtn = document.getElementById('sendBtn'); | |
| const generateBtn = document.getElementById('generateBtn'); | |
| // Sample responses for the chatbot | |
| const sampleResponses = { | |
| "hello": "Hello! How can I assist you today?", | |
| "hi": "Hi there! What would you like to know?", | |
| "help": "I can help answer questions about this website. What information are you looking for?", | |
| "what can you do": "I can provide information about this website, answer questions about its content, and help visitors find what they're looking for.", | |
| "thanks": "You're welcome! Feel free to ask if you have more questions.", | |
| "thank you": "You're welcome! Is there anything else I can help with?", | |
| "default": "I'm not sure I understand. Could you rephrase your question or ask about something specific on this website?" | |
| }; | |
| // Form submission | |
| form.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Get form values | |
| const websiteUrl = document.getElementById('websiteUrl').value; | |
| const chatbotName = document.getElementById('chatbotName').value; | |
| const welcomeMessage = document.getElementById('welcomeMessage').value; | |
| // Validate URL | |
| if (!isValidUrl(websiteUrl)) { | |
| alert('Please enter a valid URL (include http:// or https://)'); | |
| return; | |
| } | |
| // Show loading state | |
| form.style.display = 'none'; | |
| loading.style.display = 'block'; | |
| // Simulate AI processing | |
| setTimeout(() => { | |
| // Hide loading and show success | |
| loading.style.display = 'none'; | |
| successMessage.style.display = 'block'; | |
| // Update chatbot preview | |
| document.querySelector('.chatbot-title').textContent = chatbotName; | |
| // Add welcome message to chat | |
| const welcomeMsg = document.createElement('div'); | |
| welcomeMsg.className = 'chat-message bot-message'; | |
| welcomeMsg.innerHTML = ` | |
| <div class="message-bubble">${welcomeMessage}</div> | |
| <div class="message-time">${getCurrentTime()}</div> | |
| `; | |
| chatbotBody.appendChild(welcomeMsg); | |
| // Scroll to bottom | |
| chatbotBody.scrollTop = chatbotBody.scrollHeight; | |
| // Enable chat input | |
| chatInput.disabled = false; | |
| sendBtn.disabled = false; | |
| chatInput.focus(); | |
| // Show initial instructions | |
| setTimeout(() => { | |
| const instructions = document.createElement('div'); | |
| instructions.className = 'chat-message bot-message'; | |
| instructions.innerHTML = ` | |
| <div class="message-bubble"> | |
| This is a preview of your chatbot. In a real implementation, I would be trained on your website content. | |
| Try asking me questions like: | |
| <ul style="margin-top: 10px; padding-left: 20px;"> | |
| <li>"What services do you offer?"</li> | |
| <li>"Tell me about your company"</li> | |
| <li>"How can I contact you?"</li> | |
| </ul> | |
| </div> | |
| <div class="message-time">${getCurrentTime()}</div> | |
| `; | |
| chatbotBody.appendChild(instructions); | |
| chatbotBody.scrollTop = chatbotBody.scrollHeight; | |
| }, 1000); | |
| }, 2000); | |
| }); | |
| // Chat functionality | |
| sendBtn.addEventListener('click', sendMessage); | |
| chatInput.addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| sendMessage(); | |
| } | |
| }); | |
| function sendMessage() { | |
| const message = chatInput.value.trim(); | |
| if (message === '') return; | |
| // Add user message to chat | |
| const userMsg = document.createElement('div'); | |
| userMsg.className = 'chat-message user-message'; | |
| userMsg.innerHTML = ` | |
| <div class="message-bubble">${message}</div> | |
| <div class="message-time">${getCurrentTime()}</div> | |
| `; | |
| chatbotBody.appendChild(userMsg); | |
| // Clear input | |
| chatInput.value = ''; | |
| chatInput.focus(); | |
| // Scroll to bottom | |
| chatbotBody.scrollTop = chatbotBody.scrollHeight; | |
| // Simulate bot response | |
| setTimeout(() => { | |
| const botMsg = document.createElement('div'); | |
| botMsg.className = 'chat-message bot-message'; | |
| // Generate response | |
| let response = getBotResponse(message); | |
| botMsg.innerHTML = ` | |
| <div class="message-bubble">${response}</div> | |
| <div class="message-time">${getCurrentTime()}</div> | |
| `; | |
| chatbotBody.appendChild(botMsg); | |
| chatbotBody.scrollTop = chatbotBody.scrollHeight; | |
| }, 1000); | |
| } | |
| function getBotResponse(message) { | |
| const lowerMessage = message.toLowerCase(); | |
| // Check for specific keywords | |
| for (const [key, response] of Object.entries(sampleResponses)) { | |
| if (lowerMessage.includes(key)) { | |
| return response; | |
| } | |
| } | |
| // Default response | |
| return sampleResponses.default; | |
| } | |
| function isValidUrl(url) { | |
| try { | |
| new URL(url); | |
| return true; | |
| } catch (e) { | |
| return false; | |
| } | |
| } | |
| function getCurrentTime() { | |
| const now = new Date(); | |
| return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); | |
| } | |
| // Auto-scroll chat to bottom when new messages are added | |
| const observer = new MutationObserver(function(mutations) { | |
| chatbotBody.scrollTop = chatbotBody.scrollHeight; | |
| }); | |
| observer.observe(chatbotBody, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |