Pass user data and custom metadata to the Alhena chat widget for personalized AI interactions and custom tool integrations.
Alhena's Chat SDK lets you pass user metadata to personalize AI conversations and integrate with your backend systems. This page explains how to configure public metadata for AI prompts and private tokens for secure API calls.
Overview
User metadata serves two purposes:
Personalization - Public metadata is available to the AI for context-aware responses
Backend Integration - Private metadata (API tokens, user IDs) enables custom tools to call your APIs
Quick Reference
Configuration
Where
When to Use
document.gleenConfig.userMetadata
Initial config
Set data at widget load
window.gleenWidget.setUserMetadata()
Runtime
Update data dynamically
Key Prefix
Visibility
Example
No prefix
Public (AI can see)
email, name, plan
_ underscore
Private (hidden from AI)
_bearer_token, _user_id
Public vs. Private Metadata
Public Metadata
Keys without an underscore prefix are public. The AI can use this data to personalize responses.
How the AI uses public metadata:
Greet users by name: "Hi John, how can I help?"
Reference account type: "As a premium member, you have access to..."
Personalize recommendations based on preferences
Private Metadata
Keys starting with _ (underscore) are private. These are never exposed to the AI but are available to custom API tools configured in your dashboard.
Use private metadata for:
API authentication tokens
Internal user/session identifiers
Sensitive data that shouldn't appear in AI context
Setting Metadata
At Initialization
Pass metadata when the widget loads:
Dynamic Updates
Update metadata at runtime using setUserMetadata(key, value). Each call sets a single field:
Common Use Cases
User Identification
Pass user details after authentication for personalized support:
E-commerce Personalization
Provide shopping context for better product recommendations:
Multi-language Support
Combine with locale settings for proper language handling:
Backend API Integration
Pass tokens for custom tools that call your APIs:
Setting up API Tools: Create custom API tools in the Alhena dashboard under Settings > API Tools. These tools can use private metadata values to authenticate requests to your backend.
Data Persistence
Metadata is stored in the browser session
Data persists across page navigations within the same session
Clearing browser storage resets metadata
Call setUserMetadata() after page loads if you need to restore data
Complete Example
Security Best Practices
Never expose sensitive credentials - Always use the _ prefix for tokens and secrets
Rotate tokens - Use short-lived tokens when possible
Validate on backend - Your API tools should still validate tokens server-side
Limit metadata scope - Only pass data that's needed for personalization or integration
document.gleenConfig = {
company: 'your-company-key',
apiBaseUrl: 'https://app.alhena.ai',
userMetadata: {
email: 'john@example.com', // AI sees this
name: 'John Doe', // AI sees this
plan: 'premium', // AI sees this
locale: 'en-US' // AI sees this
}
};
document.gleenConfig = {
company: 'your-company-key',
apiBaseUrl: 'https://app.alhena.ai',
userMetadata: {
_bearer_token: 'eyJhbGciOiJIUzI1NiIs...', // Hidden from AI
_user_id: '12345', // Hidden from AI
_session_id: 'abc-123-xyz' // Hidden from AI
}
};
<script>
document.gleenConfig = {
company: 'your-company-key',
apiBaseUrl: 'https://app.alhena.ai',
userMetadata: {
// Public - available to AI
email: 'user@example.com',
name: 'Jane Smith',
membership: 'gold',
// Private - only for API tools
_api_token: 'secret-token-value',
_customer_id: 'cust_12345'
}
};
</script>
<script src="https://app.alhena.ai/sdk/gleenWidget.js"></script>
// After user logs in
window.gleenWidget.setUserMetadata('email', currentUser.email);
window.gleenWidget.setUserMetadata('name', currentUser.name);
window.gleenWidget.setUserMetadata('_session_token', currentUser.sessionToken);
// Update a specific field
window.gleenWidget.setUserMetadata('plan', 'enterprise');
// When user logs in
function onUserLogin(user) {
window.gleenWidget.setUserMetadata('email', user.email);
window.gleenWidget.setUserMetadata('name', user.displayName);
window.gleenWidget.setUserMetadata('account_type', user.accountType);
window.gleenWidget.setUserMetadata('signup_date', user.createdAt);
window.gleenWidget.setUserMetadata('_user_id', user.id);
}