Skip to main content
Tell the AI Agent what the visitor is doing, such as the product they’re viewing or what’s in their cart, and who they are once they sign in.

Two kinds of variables

variables

Set in the browser, so a visitor can change them. Use them for page context: the current page, the selected product, the cart.

signedVariables

A JWT your backend signs, so Typewise trusts the values. Use them for identity, such as the customer’s email.
Declare every variable you send in Context Variables. Typewise drops names you haven’t declared.

Send context when a conversation starts

Pass variables to createClient. Use a function so the SDK reads fresh values each time a conversation starts, and the first message already carries them:
Values can be strings, numbers, or booleans.

Update context as the page changes

Call setVariables when something changes, for example when the visitor picks a different product option. Before a conversation exists, the SDK holds the values and applies them to the next one.
The result tells you which values weren’t kept:
string[]
Names not declared in Context Variables. Log this during development: a non-empty list usually means a typo or a variable you forgot to declare.
string[]
Unsigned values that couldn’t overwrite a value that arrived verified.

Identify signed-in users

Pass signedVariables as a function. The SDK calls it every time it authenticates, so tokens can stay short-lived:
To sign the token on your backend, see Chat identity verification.

When the visitor signs in or out

When the visitor signs in, pass a new token. When they sign out, forget the session so the next person on the device starts fresh.