githubEdit

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

open()

Opens the chat widget

close()

Closes the chat widget

toggle()

Toggles the chat widget open/closed

sendMessage(message)

Sends a message as the user

closeTicket()

Closes the current conversation and starts a new one

getTicketId()

Returns the current ticket/conversation ID

getMessages()

Returns the chat message history

hideLauncher()

Hides the launcher button

showLauncher()

Shows the launcher button

showNudge(options)

Displays a proactive nudge message

hideNudge()

Hides any visible nudge

setStyles(styles)

Updates widget styling dynamically

setUserMetadata(key, value)

Sets a user metadata field

getFingerprint()

Returns the visitor's unique fingerprint

getFAQFingerprint()

Returns the FAQ widget fingerprint

unload()

Removes the widget from the page

setCompanyKey(key)

Changes the company key dynamically

on(event, callback)

Subscribes to widget events

Configuration Options

Option
Type
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

Language code for UI strings

defaultExpanded

boolean

Whether widget starts expanded

hideLauncher

boolean

Hide the launcher button on load


Widget Control Methods

open(options)

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

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.

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.

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.

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.

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.


Analytics & Tracking

getFingerprint()

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

Returns: string - UUID fingerprint.

getFAQFingerprint()

Returns the 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.

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.

Parameter
Type
Required
Description

eventName

string

Yes

The event name to listen for

callback

function

Yes

Function called when event fires


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'


Complete Example


Last updated