JavaScript API

Complete reference for the Alhena Website SDK JavaScript API including all methods, configuration options, and usage examples.

The Alhena Website SDK provides a JavaScript API for embedding and controlling the chat widget on your website. This page documents all available methods and configuration options.

Installation

Add the following snippet to your website's HTML, replacing company with your company key (found in your dashboard URL after /dashboard/):

circle-info

Your company key is the word after "dashboard" in your dashboard URL. For example, if your URL is https://app.alhena.ai/dashboard/acme/, your company key is acme.

<script>
document.gleenConfig = {
    company: 'your-company-key',
    apiBaseUrl: 'https://app.alhena.ai',
};
</script>
<script src="https://app.alhena.ai/sdk/gleenWidget.js"></script>

Regional API URLs

Choose the base URL for your region:

Region
Base URL

US

https://app.alhena.ai

EU

https://eu.alhena.ai

Complete Installation Example

You can also find your installation snippet in the Alhena dashboard under Integrations > Website > Installation.


Quick Reference

Methods

Method
Description

Opens the chat widget

Closes the chat widget

Toggles the chat widget open/closed

Sends a message as the user

Closes the current conversation and starts a new one

Returns the current ticket/conversation ID

Returns the chat message history

Hides the launcher button

Shows the launcher button

Displays a proactive nudge message

Hides any visible nudge

Updates widget styling dynamically

Sets a user metadata field

Sets a custom function to format product prices

Returns the visitor's unique fingerprint

Returns the FAQ widget fingerprint

Removes the widget from the page

Changes the company key dynamically

Subscribes to widget events

Opens the conversational search widget

Closes the conversational search widget

Toggles the conversational search widget

Initializes the conversational search widget


Widget Control Methods

open(options)

Opens the chat widget. If already open, has no effect.

Parameters:

Parameter
Type
Required
Description

options

object

No

Configuration options

options.expanded

boolean

No

Whether to open in expanded mode


close()

Closes the chat widget. If already closed, has no effect.


toggle(options)

Toggles the chat widget between open and closed states.

Parameters:

Parameter
Type
Required
Description

options

object

No

Configuration options

options.expanded

boolean

No

Whether to open in expanded mode (when toggling open)


sendMessage(message, options)

Opens the widget and sends a message from the user's perspective. Useful for triggering conversations based on user actions.

Parameters:

Parameter
Type
Required
Description

message

string

Yes

The message text to send

Use case: Trigger a support conversation when a user clicks a "Help" button:


Conversation Management

closeTicket()

Closes the current conversation/ticket and prepares the widget for a new conversation. The user will see the bot's welcome message again.

Use case: Reset the conversation after a support interaction is complete:


getTicketId()

Returns the unique identifier for the current conversation/ticket.

Returns: string | null — the ticket ID, or null if no active ticket.


getMessages()

Returns the message history for the current conversation.

Returns: Array — array of message objects.


Launcher Control

hideLauncher()

Hides the floating launcher button. The widget can still be opened programmatically.


showLauncher()

Shows the floating launcher button after it has been hidden.

Use case: Show the launcher only on certain pages:


Nudge Messages

Nudges are proactive messages that appear near the launcher to encourage users to start a conversation.

showNudge(options)

Displays a nudge message to the user.

Parameters:

Parameter
Type
Required
Description

options.message

string

Yes

The nudge message text

options.delay

number

No

Delay in milliseconds before showing


hideNudge()

Hides any currently visible nudge message.


Styling

setStyles(styles)

Dynamically updates the widget's visual appearance. See Styles API for all available options.


User Data

setUserMetadata(key, value)

Sets a single user metadata field for personalization. Call multiple times to set multiple fields. See Custom Data for details.

Parameters:

Parameter
Type
Required
Description

key

string

Yes

The metadata key to set

value

any

Yes

The value to associate with the key

circle-info

Keys starting with _ (underscore) are private and not exposed to the AI. Use these for sensitive data like API tokens.


Price Conversion

setConvertPriceHook(hook)

Sets a custom function to format product prices before they are displayed in the widget. Useful for currency conversion or localized formatting. Can also be set at initialization via document.gleenConfig.convertPrice.

Parameters:

Parameter
Type
Required
Description

hook

function

Yes

Receives (price, { variantId }) and returns the formatted price string

See Price Conversion Examples for more usage patterns.


Analytics & Tracking

getFingerprint()

Returns the visitor's unique fingerprint identifier, used for analytics and session tracking.

Returns: string — UUID fingerprint.


getFAQFingerprint()

Returns the Product FAQ widget's fingerprint identifier.

Returns: string — UUID fingerprint.


Widget Lifecycle

unload()

Completely removes the widget from the page. Useful for single-page applications when navigating away from pages where the widget should appear.


setCompanyKey(key)

Changes the company key dynamically. This reloads the widget with the new company's configuration.

Parameters:

Parameter
Type
Required
Description

key

string

Yes

The new company key


Event Subscription

on(eventName, callback)

Subscribes to widget events. See Events for a complete list of available events.

Parameters:

Parameter
Type
Required
Description

eventName

string

Yes

The event name to listen for

callback

function

Yes

Function called when event fires


Conversational Search Methods

These methods control the Conversational Search widget. The search widget must be set up on your page before these methods will work — see the Conversational Search setup guide for installation steps.

openSearch(query)

Opens the conversational search widget. Optionally sends a query immediately.

Parameters:

Parameter
Type
Required
Description

query

string

No

A search query to submit automatically when the widget opens

Use case: Connect to your existing search bar so users can switch to AI-powered search:


closeSearch()

Closes the conversational search widget.


toggleSearch(query)

Toggles the conversational search widget open or closed. When opening, optionally sends a query.

Parameters:

Parameter
Type
Required
Description

query

string

No

A search query to submit when the widget opens


initializeConversationalSearch()

Manually initializes the conversational search widget. The SDK automatically calls this on page load if the #alhena-conversational-search div is present. Use this method if you add the div dynamically after page load (e.g., in a single-page application).


Configuration Options

Configure the widget by setting document.gleenConfig before loading the SDK script.

Basic Configuration

Full Configuration Example

Configuration Options Reference

Option
Type
Default
Description

company

string

-

Your company key (required)

apiBaseUrl

string

-

Regional API URL (required)

styles

object

{}

Widget styling options

userMetadata

object

{}

User data for personalization

locale

string

auto

Language code (e.g., 'en', 'es', 'fr')

defaultExpanded

boolean

false

Open widget on page load

hideLauncher

boolean

false

Hide the launcher button

showExpandButton

boolean

true

Show button to expand widget

ticket_mode

string

'NORMAL'

'NORMAL' or 'BOT_ONLY'

convertPrice

function

-

Custom function to format product prices


Complete Example


Last updated