stradaChat
object that you must add to your site to use any Web SDK functionality, along with corresponding settings and actions.
Settings
Configure the Web SDK by creating astradaSettings
object in the global window
scope.
stradaChat.start
method. (See Delay widget loading.)
The Web SDK requires that
window.stradaSettings
be defined before the script loads. You must therefore
define window.stradaSettings
before the script, or use the lazy
option and call start()
manually.organizationId
organizationId: string;
(required)
Your Strada organization ID. You can find this in the Strada dashboard.
agentId
agentId: string;
(required)
The ID of the agent to load in the chat widget. You can find this in the Strada dashboard.
agentVariables
agentVariables?: Record<string, unknown>;
Variables to inject into your agent’s chat conversations. These variables are accessible to the AI agent and can be used to customize agent behavior, provide context, or personalize the conversation experience.
metaFields
metaFields?: Record<string, string | number | boolean>;
Use metaFields
to pass information about a user to Strada for attribution and analytics purposes. This data is not accessible to the AI agent during conversations. For passing data that should be available in chat conversations, use agentVariables instead.
Meta field keys should not include whitespace, emojis, or special characters.
stradaReadyCallback
stradaReadyCallback?(params: { isLoaded: boolean }): void;
Callback invoked when the SDK completes initialization. Useful for asynchronous widget loading scenarios.
toggleCallback
toggleCallback?(isOpen: boolean): void;
Callback triggered whenever the widget opens or closes.
lazy
lazy?: boolean;
When set to true
, this will prevent the widget from loading until the stradaChat.start(...)
method is called. (See Delay widget loading.)
hideButton
hideButton?: boolean;
Hides the default floating button when set to true
, allowing you to trigger the widget through custom UI elements.
widgetUrl
widgetUrl?: string;
Specifies a custom widget URL. Unless directed by a Strada team member, you should not change this value.
getUserToken
getUserToken?(): Promise<string | null>;
Function that retrieves a JWT token from your backend for user authentication. Returns a token to establish a verified user identity for the chat session.
The
getUserToken
function should return a Promise that resolves to a JWT token string, or null
if
authentication should be skipped.Actions
All actions are called through the globalstradaChat
object.
start
start(settings: StradaSettings): Promise<void>;
Initializes the SDK. Automatically called on load unless lazy
mode is enabled, in which case you must call this method manually.
open
open(options?: { agentId?: string }): Promise<void>;
Opens the widget. Pass an agentId
to switch agents when opening.
close
close(): Promise<void>;
Closes the chat widget.
setMetaFields
setMetaFields(fields: Record<string, string | number | boolean>): Promise<void>;
Updates metaFields
after initialization. Primarily useful in Single Page Applications where user context changes while the widget remains active.
Meta field keys should not include whitespace, emojis, or special characters.
subscribeEvent
subscribeEvent(eventKey: string, callback: (data: object, context: object) => void): Promise<number>
Registers a callback for SDK events. Returns a subscription ID for later removal.
stradaReadyCallback
to ensure the SDK is loaded and no events are missed:
Event key | Data | Description |
---|---|---|
strada:ready | { isLoaded: boolean } | Triggered when the widget has finished loading and is ready to use. |
unsubscribeEvent
unsubscribeEvent(subscriptionId: number): void;
Removes an event subscription using its subscription ID.