Overview
Embed your assistant directly into your website using an iframe. This creates a seamless chat experience within your existing pages. The iframe will automatically adapt to different screen sizes and provides a native chat interface for your users.Basic Implementation
Recommended Iframe Attributes
src (Required)
The URL of your assistant. This is automatically generated and includes your assistant ID.width
Width of the iframe. Use100%
for responsive design or specific pixel values like 400px
for fixed width.
height
Height of the iframe. Recommended minimum is600px
for optimal chat experience.
style
CSS styles for the iframe. Includes border removal, rounded corners, and shadow for a polished look.User Authentication
The
user_hash
parameter must be generated on your backend using your assistant’s secret key. Never expose the secret key to the client or generate the hash in frontend code.Understanding User Authentication vs Contact Updates
There are two distinct features for managing user information:-
Manual User Authentication (described in this section)
- Requires both
user_id
anduser_hash
to be provided together as URL parameters - Used for authenticated sessions with your application users
- Enables personalized experiences and session management
- The hash validates the user’s identity securely
- Requires both
-
Automatic Contact Updates (AI feature)
- The assistant can automatically update contact information (name, email, phone) when detected in conversations
- Works independently of authentication
- No hash required for this feature
- Available for all sessions, authenticated or anonymous
Secret Key
Generate a secret key to enable user authentication for your assistant. This key is required to create secure user hashes for authenticated sessions.- Navigate to your assistant settings in the Invent dashboard
- Click Generate Secret Key
- Store this key securely on your backend server
URL Parameters
To authenticate users from your application, add these parameters to the iframe URL. This enables personalized experiences, session management, and user-specific analytics. If no authentication is provided, an anonymous session will be created automatically.user_hash
Required for authentication. HMAC-SHA256 hash of theuser_id
using your assistant’s secret_key
. This ensures secure authentication and must be generated on your backend.
user_id
The unique user identifier from your application. Used for session management, analytics, and maintaining conversation history across sessions.user_name
Display name for the user (full name, first name, username, etc.). Used for personalization in chat messages and Invent Contacts. URL-encode special characters.user_avatar
URL to the user’s avatar image. Will be displayed in chat messages and Invent Contacts. Must be a publicly accessible HTTPS URL.Authenticated Implementation
Frontend Code
Backend Hash Generation
Complete Example
Full HTML Page with Authentication
Responsive Design
Mobile-Friendly Layout
Full-Height Chat Experience
Content Security Policy (CSP)
If your website uses Content Security Policy headers, add these directives:Best Practices
Security
Always generate user hashes on your backend. Never expose your secret key in client-side code.
Responsive Design
Use percentage-based widths and appropriate heights for mobile devices.
Loading State
Consider adding a loading indicator while the iframe loads.
Accessibility
Always include a descriptive title attribute for screen readers.
Troubleshooting
Iframe not loading
Iframe not loading
Possible causes:
- Invalid assistant ID
- CSP blocking the iframe
- Network connectivity issues
- Verify assistant ID is correct
- Check Content Security Policy settings
- Inspect browser console for errors
Authentication not working
Authentication not working
Possible causes:
- Invalid user hash
- Incorrect URL parameter encoding
- Secret key mismatch
- Verify hash generation code
- Ensure proper URL encoding of parameters
- Check secret key matches your assistant
Display issues
Display issues
Possible causes:
- Incorrect dimensions
- CSS conflicts
- Responsive design problems
- Set minimum height of 600px
- Use CSS isolation techniques
- Test on multiple screen sizes
Cross-origin issues
Cross-origin issues
Possible causes:
- Restrictive CSP headers
- Browser security settings
- Update CSP to allow useinvent.com
- Verify X-Frame-Options headers