Widget Guide
The Agentix chat widget is an embeddable UI component that adds a conversational AI interface to any website. It loads asynchronously, is fully responsive, and can be customized to match your brand.
Quick Embed
Add this script tag to your HTML, just before the closing </body> tag:
<script
src="https://cdn.agentix.cl/widget/v1/embed.js"
data-agent-id="YOUR_AGENT_ID"
data-api-key="agx_live_YOUR_API_KEY"
></script>That’s it. The widget will appear as a floating button in the bottom-right corner of your page.
Configuration Options
Pass configuration as data-* attributes on the script tag:
| Attribute | Type | Default | Description |
|---|---|---|---|
data-agent-id | string | Required | Your agent’s ID |
data-api-key | string | Required | Your public API key |
data-api-url | string | https://app.agentix.cl | Custom API base URL |
data-position | string | bottom-right | Widget position: bottom-right, bottom-left, top-right, top-left |
data-language | string | es | UI language: es, en |
data-theme | string | light | Color scheme: light, dark |
data-auto-open | boolean | false | Open widget automatically on page load |
data-auto-open-delay | number | 3000 | Delay before auto-open (milliseconds) |
data-trigger-text | string | - | Custom text on the trigger button |
Example with Options
<script
src="https://cdn.agentix.cl/widget/v1/embed.js"
data-agent-id="abc123"
data-api-key="agx_live_YOUR_KEY"
data-position="bottom-left"
data-language="en"
data-theme="dark"
data-auto-open="true"
data-auto-open-delay="5000"
></script>Manual Initialization
For more control, load the script without auto-init and initialize manually:
<script src="https://cdn.agentix.cl/widget/v1/embed.js" data-manual-init="true"></script>
<script>
// Initialize when ready
window.AgentixWidget.init({
agentId: 'YOUR_AGENT_ID',
apiKey: 'agx_live_YOUR_KEY',
position: 'bottom-right',
language: 'en',
theme: 'light',
onReady: function() {
console.log('Widget is ready')
},
onMessage: function(message) {
console.log('New message:', message)
},
})
</script>Widget API
After initialization, the widget exposes a global API:
// Open the widget
window.AgentixWidget.open()
// Close the widget
window.AgentixWidget.close()
// Toggle open/close
window.AgentixWidget.toggle()
// Send a message programmatically
window.AgentixWidget.sendMessage('Hello!')
// Destroy the widget and clean up
window.AgentixWidget.destroy()
// Set visitor information
window.AgentixWidget.setVisitor({
email: 'user@example.com',
name: 'John Doe',
metadata: { plan: 'pro' }
})How It Works
- The embed script loads asynchronously (does not block page rendering)
- It fetches the agent’s widget configuration from
/api/public/agents/{id}/widget - It creates an isolated iframe to prevent CSS conflicts with your site
- Messages are sent via the Chat API with streaming responses
- Conversations persist via
sessionIdstored inlocalStorage
Domain Restrictions
For security, you can restrict which domains can load your widget:
- Go to your agent’s settings in the dashboard
- Under Widget Configuration > Allowed Domains
- Add your domains (supports wildcards:
*.example.com)
When domain restrictions are active, the widget will only load on approved domains. Requests from other origins receive a 403 DOMAIN_NOT_ALLOWED error.
Content Security Policy (CSP)
If your site uses a strict CSP, add these directives:
script-src 'self' https://cdn.agentix.cl;
frame-src 'self' https://cdn.agentix.cl;
connect-src 'self' https://app.agentix.cl;Next Steps
- Widget Customization - Theming, custom CSS, events
- Chat API - Understand the underlying API
- Authentication - API key security for widgets