A beautiful, reusable AI chatbot widget that can be easily integrated into any HTML page.
Add this in your HTML <head>
section:
<link rel="stylesheet" href="chatbot-widget.css">
Add this before the closing </body>
tag:
<script src="chatbot-widget.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
new ChatbotWidget();
});
</script>
const chatbot = new ChatbotWidget({
model: 'gpt-4', // OpenAI model to use
maxTokens: 200, // Maximum tokens per response
temperature: 0.8, // Response creativity (0-1)
contextScanning: true, // Enable automatic context scanning (default: true)
apiKey: 'your-base64-encoded-key' // Your OpenAI API key (base64 encoded)
});
Instead of automatic scanning, you can manually define the chatbot's behavior:
const chatbot = new ChatbotWidget({
manualContext: true, // Disable auto-scanning
customSystemPrompt: 'You are a helpful assistant for our premium consulting firm. Help users with business inquiries, service information, and scheduling appointments. Be professional and knowledgeable about business strategy.',
customWelcomeMessage: 'Welcome to ConsultPro! I\'m here to help you with our consulting services. How can I assist you today?',
businessType: 'corporate' // Optional: for suggestions
});
const chatbot = new ChatbotWidget({
customSystemPrompt: 'You are a customer service agent for TechStore. Help customers with product information, orders, returns, and technical support. Be friendly and solution-oriented.'
});
// Show/hide the widget
chatbot.show();
chatbot.hide();
// Clear conversation history
chatbot.clearConversation();
// Remove widget completely
chatbot.destroy();
// Context-aware features
chatbot.getWebsiteContext(); // Get scanned website information
chatbot.getContextualSuggestions(); // Get relevant conversation starters
chatbot.refreshContext(); // Re-scan context (useful for SPAs)
// Manual context control
chatbot.updateSystemPrompt('New system prompt here'); // Update AI behavior
chatbot.updateWelcomeMessage('New welcome message'); // Update greeting
chatbot.setManualMode(true, { // Enable manual mode
systemPrompt: 'Custom system prompt',
welcomeMessage: 'Custom welcome message',
businessType: 'corporate'
});
chatbot.setManualMode(false); // Disable manual mode, re-enable auto-scanning
chatbot.getMode(); // Get current mode and settings
You can switch between automatic and manual modes at runtime:
// Start with automatic context scanning
const chatbot = new ChatbotWidget({
contextScanning: true
});
// Later, switch to manual mode with custom behavior
chatbot.setManualMode(true, {
systemPrompt: 'You are now a specialized customer support agent for our software platform. Help users with technical issues, account problems, and feature questions.',
welcomeMessage: 'Hi! I\'m your technical support assistant. How can I help you today?',
businessType: 'corporate'
});
// Update just the system prompt while keeping manual mode
chatbot.updateSystemPrompt('You are now focused on sales inquiries. Help potential customers understand our products and pricing.');
// Switch back to automatic context detection
chatbot.setManualMode(false);
The widget automatically scans your website to understand:
You have complete control over the chatbot's behavior:
index.html
- Main landing page with widget showcasemanual-context-demo.html
- Interactive demo page with manual context controlexample-integration.html
- Simple integration examplechatbot-widget.css
- Widget styling and responsive designchatbot-widget.js
- Widget functionality and AI integrationlanding-page.css
- Landing page specific stylesdocumentation.html
- This comprehensive documentation pageREADME.md
- Original markdown documentation (legacy)The widget uses your OpenAI API key to communicate with the AI. For security, the API key is base64 encoded. To use your own key:
apiKey
in the widget optionsCheck out our demo pages to see the widget in action:
Try the widget on our demo pages or integrate it into your own website!
Live Demo Learn More