Dashboard

Embed Chat on Your Website

Publish an agent and add a chat widget to any website with a single script tag. Time: ~10 minutes.

What You Will Build

  • A published agent accessible via embed code
  • A floating chat widget on your website
  • Custom branding (colors, title, welcome message)
  • Real-time streaming responses

Prerequisites

  • An agent already created in Fluxgate (see Support Agent Tutorial)
  • The agent should be in active lifecycle state
  • A website where you can add HTML/JavaScript

Step-by-Step Guide

1

Activate Your Agent

The agent must be in 'active' state before publishing. Promote it through the lifecycle.

# Promote from draft to testing
curl -X POST http://localhost:8000/api/v1/lifecycle/agents/AGENT_ID/transition \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "to_state": "testing" }'

# Promote from testing to active
curl -X POST http://localhost:8000/api/v1/lifecycle/agents/AGENT_ID/transition \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "to_state": "active" }'
2

Publish the Agent

Generate an embed code for your agent. This creates a public endpoint.

curl -X POST http://localhost:8000/api/v1/publish/agents/AGENT_ID/publish \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Customer Support",
    "welcome_message": "Hi! How can I help you today?",
    "theme_color": "#6366f1",
    "allowed_domains": ["yourdomain.com", "localhost"]
  }'

# Response includes:
# { "embed_code": "<script src=\"...\">...</script>", "widget_id": "wgt_xyz" }
3

Add the Embed Code to Your Website

Copy the embed code and paste it into your website's HTML, just before the closing </body> tag.

<!-- Add this just before </body> -->
<script
  src="http://localhost:3000/widget/WIDGET_ID.js"
  data-agent-id="AGENT_ID"
  data-theme-color="#6366f1"
  data-title="Customer Support"
  data-welcome="Hi! How can I help you today?"
  async
></script>
4

Customize the Widget Appearance

Update the widget configuration to match your brand.

curl -X PUT http://localhost:8000/api/v1/publish/agents/AGENT_ID \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Acme Support Bot",
    "welcome_message": "Welcome to Acme! Ask me anything about our products.",
    "theme_color": "#2563eb",
    "position": "bottom-right",
    "show_branding": false
  }'
5

Test the Widget

Open your website in a browser. You should see a chat bubble in the bottom-right corner.

# If testing locally, start a simple HTTP server:
python -m http.server 8080

# Then open http://localhost:8080 in your browser
# Click the chat bubble to open the widget
# Type a message and verify streaming responses
6

Monitor Widget Usage

Track how users interact with your embedded chat.

# View chat sessions
curl http://localhost:8000/api/v1/chat/sessions?agent_id=AGENT_ID \
  -H "Authorization: Bearer YOUR_API_KEY"

# View analytics
curl http://localhost:8000/api/v1/analytics/agents/AGENT_ID \
  -H "Authorization: Bearer YOUR_API_KEY"

Full HTML Example

index.htmlhtml
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Website</title>
</head>
<body>
  <h1>Welcome to My Website</h1>
  <p>Click the chat bubble in the bottom-right corner to talk to our AI assistant!</p>

  <!-- Fluxgate Chat Widget -->
  <script
    src="http://localhost:3000/widget/WIDGET_ID.js"
    data-agent-id="AGENT_ID"
    data-theme-color="#6366f1"
    data-title="AI Assistant"
    data-welcome="Hi! How can I help you?"
    data-position="bottom-right"
    async
  ></script>
</body>
</html>

Widget Configuration Options

AttributeDescriptionDefault
data-agent-idYour agent's ID (required)-
data-theme-colorPrimary color for the widget#6366f1
data-titleTitle shown in the chat headerAI Assistant
data-welcomeWelcome message shown on openHow can I help?
data-positionWidget position: bottom-right or bottom-leftbottom-right
data-show-brandingShow 'Powered by ACP' brandingtrue

Production Domains

Make sure to set allowed_domains when publishing. This prevents your agent from being embedded on unauthorized websites. Always include your production domain!