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:

Passing Cart Data

Pass the customer's current cart to enable the AI to answer questions about items in their cart, provide checkout assistance, or make recommendations.

circle-info

Shopify stores: Cart data is passed automatically when you install the Alhena widget. No additional configuration needed.

For other platforms, fetch cart data and pass it using setUserMetadata:

WooCommerce:

Magento:

Custom Platform / Generic:

Cart data structure:

Field
Type
Description

items

Array

List of cart items

items[].title

String

Product name

items[].quantity

Number

Quantity in cart

items[].price

Number

Unit price

items[].options

Array

Selected variants/options

currency

String

Currency code (USD, EUR, etc.)

subtotal

Number

Cart subtotal amount

checkout_url

String

URL to checkout page

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.


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