Quickstart
Create an assistant, set up OAuth authentication, and embed the widget on your website.
Widget Overview
The widget app is hosted at widget.companin.tech and provides an easy way to embed an AI assistant into your website. To get started, you'll need to create an assistant and an OAuth application.
1. Create an Assistant
First, create an AI assistant in your dashboard:
- Go to your dashboard and navigate to the "Data Sources" page
- Click the "Add" button in the Assistants section
- Fill in the assistant details (name, description, tone, etc.)
- Save the assistant and note its ID
2. Create an OAuth Application
Create an OAuth application to authenticate your widget:
- Go to the "OAuth" page in your dashboard
- Click "Create Application"
- Fill in the application name and description
- Copy the
client_idfrom the created application
3. Embed the Widget via Iframe
The simplest way to integrate the widget is by embedding it directly using an iframe. This method requires no JavaScript initialization and works out of the box.
<iframe src="https://widget.companin.tech/embed/session?clientId=YOUR_CLIENT_ID&assistantId=YOUR_ASSISTANT_ID&startOpen=true&locale=en" style="border: none; position: fixed; bottom: 32px; right: 32px; z-index: 1000; background-color: transparent; width: 400px; height: 600px; border-radius: 8px;" title="AI Assistant Widget"></iframe>Replace YOUR_CLIENT_ID and YOUR_ASSISTANT_ID with your actual values. The locale parameter can be set to match your site's language.
Advanced: JavaScript Initialization
For more control, you can initialize the widget programmatically. First, obtain a widget token from your server.
Obtain a Widget Token
Call the widget token endpoint with the client_id to receive a short-lived JWT.
curl -X POST https://your-api.example.com/api/auth/widget-token \ -H "Content-Type: application/json" \ -d '{"client_id":"YOUR_CLIENT_ID"}'Initialize the Widget
Fetch the token from your server and initialize the widget.
// Get token from your serverconst res = await fetch('/my-server/get-widget-token');const { token } = await res.json();// Initialize widgetwindow.MyAssistantWidget.init({ container: '#assistant', assistantId: 'ASSISTANT_UUID', auth: { type: 'bearer', token },});Notes
- Do not expose client secrets in the browser; keep them on the server.
- Tokens are short-lived (1 hour); refresh as necessary server-side.