🤖 AI Chatbot Widget

Easy integration for any website - Just like LiveChat, Intercom, and other popular chat widgets

✨ Features

🚀 Easy Integration

One-line installation with customizable configuration

🎨 Customizable Design

Match your brand colors, position, and messaging

📱 Mobile Responsive

Works perfectly on desktop, tablet, and mobile devices

🧠 AI-Powered

Advanced language models with context awareness

🔒 Secure

API key authentication and secure data handling

⚡ Fast Loading

Lightweight and optimized for performance

🚀 Quick Start

Step 1: Get your API key and session ID from your dashboard
Step 2: Add the integration code to your website
<!-- Add this before closing </body> tag -->
<script>
window.AIChatbotConfig = {
    apiKey: 'your-api-key-here',
    sessionId: 'your-session-id',
    apiEndpoint: 'https://your-api-domain.com',
    botName: 'Support Assistant',
    welcomeMessage: 'Hi! How can I help you today?',
    primaryColor: '#667eea',
    position: 'bottom-right'
};
</script>
<script src="https://cdn.example.com/chatbot-widget.js"></script>
Step 3: That's it! Your chatbot is now live on your website

🔧 Integration Examples

HTML/JavaScript Integration

For static websites or any HTML-based project:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Website</title>
</head>
<body>
    <!-- Your website content -->
    <h1>Welcome to My Website</h1>

    <!-- AI Chatbot Widget -->
    <script>
    window.AIChatbotConfig = {
        apiKey: 'sk-1234567890abcdef',
        sessionId: 'session-xyz789',
        apiEndpoint: 'https://api.example.com',
        botName: 'Website Assistant',
        welcomeMessage: 'Hello! Need help finding something?',
        primaryColor: '#0066cc',
        secondaryColor: '#004499',
        position: 'bottom-right',
        autoOpen: false,
        quickActions: [
            'What services do you offer?',
            'How can I contact you?',
            'Tell me about pricing'
        ]
    };
    </script>
    <script src="https://cdn.example.com/chatbot-widget.js"></script>
</body>
</html>

WordPress Integration

Add to your theme's functions.php or use a custom HTML widget:

<?php
// Add to functions.php
function add_ai_chatbot_widget() {
    $api_key = get_option('chatbot_api_key', '');
    $session_id = get_option('chatbot_session_id', '');

    if (empty($api_key) || empty($session_id)) {
        return;
    }

    ?>
    <script>
    window.AIChatbotConfig = {
        apiKey: '<?php echo esc_js($api_key); ?>',
        sessionId: '<?php echo esc_js($session_id); ?>',
        apiEndpoint: 'https://api.example.com',
        botName: '<?php echo esc_js(get_bloginfo('name')); ?> Assistant',
        welcomeMessage: 'Hi! How can I help you with <?php echo esc_js(get_bloginfo('name')); ?>?',
        primaryColor: '<?php echo get_theme_mod('primary_color', '#0073aa'); ?>'
    };
    </script>
    <script src="https://cdn.example.com/chatbot-widget.js"></script>
    <?php
}
add_action('wp_footer', 'add_ai_chatbot_widget');

// Add admin options
function chatbot_admin_menu() {
    add_options_page('AI Chatbot Settings', 'AI Chatbot', 'manage_options', 'ai-chatbot', 'chatbot_admin_page');
}
add_action('admin_menu', 'chatbot_admin_menu');

function chatbot_admin_page() {
    if (isset($_POST['submit'])) {
        update_option('chatbot_api_key', sanitize_text_field($_POST['api_key']));
        update_option('chatbot_session_id', sanitize_text_field($_POST['session_id']));
        echo '<div class="notice notice-success"><p>Settings saved!</p></div>';
    }

    $api_key = get_option('chatbot_api_key', '');
    $session_id = get_option('chatbot_session_id', '');
    ?>
    <div class="wrap">
        <h1>AI Chatbot Settings</h1>
        <form method="post">
            <table class="form-table">
                <tr>
                    <th scope="row">API Key</th>
                    <td><input type="text" name="api_key" value="<?php echo esc_attr($api_key); ?>" class="regular-text" /></td>
                </tr>
                <tr>
                    <th scope="row">Session ID</th>
                    <td><input type="text" name="session_id" value="<?php echo esc_attr($session_id); ?>" class="regular-text" /></td>
                </tr>
            </table>
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}
?>

React Integration

For React applications, use useEffect to initialize:

import React, { useEffect } from 'react';

const ChatbotWidget = ({ apiKey, sessionId, config = {} }) => {
  useEffect(() => {
    // Set global configuration
    window.AIChatbotConfig = {
      apiKey,
      sessionId,
      apiEndpoint: 'https://api.example.com',
      botName: 'React Assistant',
      welcomeMessage: 'Hi! I\'m here to help with your React app!',
      primaryColor: '#61dafb',
      ...config
    };

    // Load the chatbot script
    const script = document.createElement('script');
    script.src = 'https://cdn.example.com/chatbot-widget.js';
    script.async = true;

    document.head.appendChild(script);

    // Cleanup function
    return () => {
      if (window.AIChatbotWidget) {
        window.AIChatbotWidget.destroy();
      }
      document.head.removeChild(script);
    };
  }, [apiKey, sessionId]);

  return null; // This component doesn't render anything
};

// Usage in your App component
const App = () => {
  return (
    <div className="App">
      <header>
        <h1>My React App</h1>
      </header>

      <main>
        {/* Your app content */}
      </main>

      <ChatbotWidget
        apiKey="your-api-key"
        sessionId="your-session-id"
        config={{
          botName: 'React Support',
          primaryColor: '#0066cc',
          autoOpen: false
        }}
      />
    </div>
  );
};

export default App;

PHP Integration

Server-side integration with dynamic configuration:

<?php
class AIChatbotIntegration {
    private $api_key;
    private $session_id;
    private $config;

    public function __construct($api_key, $session_id, $config = []) {
        $this->api_key = $api_key;
        $this->session_id = $session_id;
        $this->config = array_merge([
            'botName' => 'Support Assistant',
            'welcomeMessage' => 'Hello! How can I help you today?',
            'primaryColor' => '#0066cc',
            'position' => 'bottom-right',
            'autoOpen' => false
        ], $config);
    }

    public function render() {
        $config_json = json_encode(array_merge([
            'apiKey' => $this->api_key,
            'sessionId' => $this->session_id,
            'apiEndpoint' => 'https://api.example.com'
        ], $this->config));

        echo "<script>window.AIChatbotConfig = {$config_json};</script>";
        echo '<script src="https://cdn.example.com/chatbot-widget.js"></script>';
    }

    public function createSession($domain, $website_url = null) {
        $data = [
            'domain' => $domain,
            'website_url' => $website_url,
            'groq_api_key' => $this->api_key,
            'model_name' => 'llama3-8b-8192',
            'max_links' => 10,
            'use_sitemap' => false,
            'embedding_model' => 'sentence-transformers/all-MiniLM-L6-v2'
        ];

        $ch = curl_init('https://api.example.com/sessions');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'Authorization: Bearer ' . $this->api_key
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        curl_close($ch);

        return json_decode($response, true);
    }
}

// Usage example
$chatbot = new AIChatbotIntegration(
    'your-api-key',
    'your-session-id',
    [
        'botName' => 'PHP Assistant',
        'primaryColor' => '#8892bf',
        'welcomeMessage' => 'Hi! Welcome to our PHP-powered website!'
    ]
);

// In your HTML template
?>
<!DOCTYPE html>
<html>
<head>
    <title>My PHP Website</title>
</head>
<body>
    <!-- Your content -->

    <!-- Before closing body tag -->
    <?php $chatbot->render(); ?>
</body>
</html>

Shopify Integration

Add to your Shopify theme's liquid templates:

<!-- Add to theme.liquid before </body> -->
<script>
window.AIChatbotConfig = {
    apiKey: '{{ settings.chatbot_api_key }}',
    sessionId: '{{ settings.chatbot_session_id }}',
    apiEndpoint: 'https://api.example.com',
    botName: '{{ shop.name }} Assistant',
    welcomeMessage: 'Hi! Welcome to {{ shop.name }}! How can I help you?',
    primaryColor: '{{ settings.colors_accent_1 }}',
    quickActions: [
        'Help me find a product',
        'What\'s your return policy?',
        'Track my order',
        'Contact support'
    ],
    {% if customer %}
    customerInfo: {
        name: '{{ customer.first_name }} {{ customer.last_name }}',
        email: '{{ customer.email }}',
        id: '{{ customer.id }}'
    }
    {% endif %}
};
</script>
<script src="https://cdn.example.com/chatbot-widget.js"></script>

<!-- Add custom styles to theme.scss.liquid -->
<style>
.ai-chatbot-widget {
    --chatbot-primary-color: {{ settings.colors_accent_1 }};
    --chatbot-secondary-color: {{ settings.colors_accent_2 }};
}

/* Hide on checkout pages if needed */
.template-cart .ai-chatbot-widget,
.template-checkout .ai-chatbot-widget {
    display: none;
}
</style>
Note: Add the API key and session ID settings to your theme's settings_schema.json for easy configuration through the Shopify admin.

⚙️ Configuration Options

Customize the chatbot widget to match your brand and requirements:

Option Type Default Description
apiKey string '' Your API authentication key
sessionId string '' Unique session identifier
apiEndpoint string 'http://localhost:8000' Your API server endpoint
botName string 'AI Assistant' Display name for your bot
welcomeMessage string 'Hi! How can I help you today?' Initial greeting message
position string 'bottom-right' 'bottom-right' or 'bottom-left'
primaryColor string '#667eea' Primary brand color (hex)
secondaryColor string '#764ba2' Secondary brand color (hex)
autoOpen boolean false Auto-open chat after page load
showPoweredBy boolean true Show "Powered by" attribution
enableSounds boolean false Play notification sounds
enableTypingIndicator boolean true Show typing animation
maxMessages number 100 Maximum stored messages
placeholder string 'Type your message...' Input field placeholder
quickActions array ['What can you help me with?', ...] Quick action buttons

🔌 API Integration

Connect the widget to your backend API:

// Example API endpoint structure
POST /sessions/{session_id}/chat
Content-Type: application/json
Authorization: Bearer your-api-key

{
    "session_id": "session-123",
    "message": "Hello, how can you help me?"
}

// Expected response
{
    "response": "Hi! I'm here to help. What can I assist you with today?",
    "session_id": "session-123",
    "timestamp": "2024-01-15T10:30:00Z",
    "error": null
}
Note: The widget automatically handles API calls, error handling, and message formatting. You just need to ensure your backend API follows the expected request/response format.

🚀 Advanced Features

Custom Event Callbacks

window.AIChatbotConfig = {
    // ... other config
    onReady: function(widget) {
        console.log('Chatbot is ready!', widget);
    },
    onOpen: function(widget) {
        console.log('Chat opened');
        // Track analytics event
        gtag('event', 'chat_opened');
    },
    onClose: function(widget) {
        console.log('Chat closed');
    },
    onMessage: function(sender, message, widget) {
        console.log(`${sender}: ${message}`);
        // Track user messages
        if (sender === 'user') {
            gtag('event', 'chat_message_sent');
        }
    },
    onError: function(error, widget) {
        console.error('Chatbot error:', error);
        // Send to error tracking service
    }
};

Programmatic Control

// Access the widget instance
const chatbot = window.AIChatbotWidget;

// Open/close chat programmatically
chatbot.openChat();
chatbot.closeChat();

// Send a message programmatically
chatbot.sendMessage('Hello from JavaScript!');

// Update configuration
chatbot.updateConfig({
    primaryColor: '#ff6b6b',
    botName: 'Updated Assistant'
});

// Clear chat history
chatbot.clearHistory();

// Get chat history
const history = chatbot.getHistory();

// Control typing indicator
chatbot.setTyping(true); // Show typing
chatbot.setTyping(false); // Hide typing

// Destroy widget
chatbot.destroy();

Multiple Widget Instances

// Create multiple chatbot instances
const supportBot = new AIChatbotWidgetClass({
    apiKey: 'support-api-key',
    sessionId: 'support-session',
    botName: 'Support Team',
    position: 'bottom-right',
    primaryColor: '#28a745'
});

const salesBot = new AIChatbotWidgetClass({
    apiKey: 'sales-api-key',
    sessionId: 'sales-session',
    botName: 'Sales Assistant',
    position: 'bottom-left',
    primaryColor: '#007bff'
});

Conditional Loading

// Load chatbot only on specific pages
if (window.location.pathname.includes('/support') ||
    window.location.pathname.includes('/contact')) {

    window.AIChatbotConfig = {
        apiKey: 'your-api-key',
        sessionId: 'support-session',
        botName: 'Support Assistant',
        autoOpen: true
    };

    // Load script
    const script = document.createElement('script');
    script.src = 'https://cdn.example.com/chatbot-widget.js';
    document.head.appendChild(script);
}

// Or based on user authentication
if (window.currentUser && window.currentUser.isPremium) {
    // Load premium support bot
    window.AIChatbotConfig = {
        apiKey: 'premium-api-key',
        sessionId: 'premium-session',
        botName: 'Premium Support',
        welcomeMessage: 'Welcome to Premium Support! How can we assist you today?'
    };
}

🎨 Styling & Customization

Custom CSS

window.AIChatbotConfig = {
    // ... other config
    customCSS: `
        /* Custom styles for the chatbot */
        .ai-chatbot-widget .chatbot-trigger {
            background: linear-gradient(45deg, #ff6b6b, #ee5a24) !important;
            animation: bounce 2s infinite;
        }

        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
            40% { transform: translateY(-10px); }
            60% { transform: translateY(-5px); }
        }

        .ai-chatbot-widget .chatbot-container {
            border-radius: 0 !important;
            box-shadow: 0 0 30px rgba(0,0,0,0.3) !important;
        }

        .ai-chatbot-widget .message.bot .message-content {
            background: linear-gradient(135deg, #667eea, #764ba2) !important;
            color: white !important;
        }

        /* Hide on mobile */
        @media (max-width: 768px) {
            .ai-chatbot-widget {
                display: none;
            }
        }
    `
};

Theme Integration

/* CSS Variables for easy theming */
:root {
    --chatbot-primary-color: #your-brand-color;
    --chatbot-secondary-color: #your-secondary-color;
    --chatbot-border-radius: 15px;
    --chatbot-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .ai-chatbot-widget {
        --chatbot-bg-color: #2d3748;
        --chatbot-text-color: #e2e8f0;
        --chatbot-input-bg: #4a5568;
    }
}

🔒 Security & Best Practices

Important: Never expose your API keys in client-side code for production websites.

Secure API Key Management

// ❌ DON'T: Hardcode API keys in frontend
window.AIChatbotConfig = {
    apiKey: 'sk-1234567890abcdef', // Visible to everyone!
};

// ✅ DO: Use server-side rendering or environment variables
<script>
window.AIChatbotConfig = {
    apiKey: '<?php echo $secure_api_key; ?>', // PHP example
    // or
    apiKey: process.env.REACT_APP_CHATBOT_KEY, // React example
};
</script>

Content Security Policy (CSP)

/* Add to your CSP header */
Content-Security-Policy:
    script-src 'self' https://cdn.example.com;
    connect-src 'self' https://api.example.com;
    style-src 'self' 'unsafe-inline';

GDPR Compliance

// GDPR-compliant configuration
window.AIChatbotConfig = {
    // ... other config
    gdprCompliance: true,
    privacyPolicyUrl: 'https://yoursite.com/privacy',
    onBeforeStart: function() {
        // Check for consent before initializing
        if (!getCookieConsent()) {
            return false; // Don't start chatbot
        }
        return true;
    }
};

🔧 Troubleshooting

Common Issues

Widget Not Appearing

  • Check if script is loaded correctly
  • Verify API key and session ID
  • Check browser console for errors
  • Ensure no CSS conflicts (z-index)

API Connection Failed

  • Verify API endpoint URL
  • Check CORS settings on server
  • Validate API key format
  • Check network tab in dev tools

Styling Issues

  • Check CSS specificity conflicts
  • Verify CSS custom properties
  • Test with !important declarations
  • Check mobile responsiveness

Performance Issues

  • Load script asynchronously
  • Implement lazy loading
  • Optimize message history limit
  • Consider CDN for script delivery

Debug Mode

// Enable debug mode for troubleshooting
window.AIChatbotConfig = {
    // ... other config
    debug: true, // Enables console logging
    testMode: true // Uses demo responses
};

// Debug commands in browser console
window.AIChatbotWidget.openChat();
window.AIChatbotWidget.sendMessage('Test message');
console.log(window.AIChatbotWidget.getHistory());

📞 Support & Resources

📚 Documentation

Complete API documentation and integration guides

View Documentation →

💬 Community Support

Join our community forum for help and discussions

Join Community →

🎯 Premium Support

Get priority support and custom integration help

Contact Support →

🔧 Professional Services

Custom development and integration services

Learn More →