githubEdit

Custom Data

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:

  1. Personalization - Public metadata is available to the AI for context-aware responses

  2. 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:

circle-info

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

  1. Never expose sensitive credentials - Always use the _ prefix for tokens and secrets

  2. Rotate tokens - Use short-lived tokens when possible

  3. Validate on backend - Your API tools should still validate tokens server-side

  4. Limit metadata scope - Only pass data that's needed for personalization or integration


Last updated