window.twSdk. Use it to update variables during a conversation, open the
widget, or start a fresh conversation from your own buttons and page logic.
The widget initializes itself from window.twConfig, so you don’t call an init
function. See Installation to load
the script. Wait until window.twSdk exists before you call it.
Update variables
setVariables pushes context variables into the visitor’s live conversation
without a reload. Reach for it when data changes after the chat loads: the
visitor signs in, adds items to a cart, or opens a different order.
variables and signedVariables you set in
window.twConfig at install time. Pass either field, or both. The call returns
nothing and sends the update in the background.
What persists
Typewise keeps only the variables you declare in
Context Variables. It drops any
name you haven’t declared, and the call still succeeds. Declare every variable
you send.
- Declared only. Typewise drops undeclared names at ingest. A name like
order_numberpersists only when it’s declared for the workspace. - Active conversation only. The update lands on the conversation the visitor has open. When no conversation is active (before the first message, or after the current one closes), Typewise holds the values and applies them to the next conversation the visitor starts. It doesn’t change a conversation that already closed.
- Signed beats unsigned. An unsigned value can’t overwrite one that arrived verified. This stops a visitor from editing a value your backend already signed.
Rotate trusted values after login
A page often starts anonymous, the visitor signs in, and you then raise their identity to a verified value. Sign a new token on your backend and pass it:Open the chat
Open the widget from your own element:Start a new conversation
Close the current conversation and start a fresh one:Call the SDK safely
window.twSdk exists only after the widget script loads. Guard your calls so an
early one doesn’t throw:
See also
- Context Variables: declare the variables Typewise keeps
- Chat identity verification: sign variables so they arrive verified
- Chat configuration: install and configure the widget