Using the AISeller JavaScript API
Last updated: August 11, 2026
Use the window.AISeller API to pass visitor context to a Marketing Agent and control the Docket widget from your website code.
Before You Begin
Install the Docket widget script on your website.
Deploy the agent to the domain where you will call the API.
Configure every visitor field the agent should use under Agent > Dynamic Context Ingestion.
Call the API only after the Docket script has loaded.
Configure Dynamic Context
Open the agent's Agent tab and expand Dynamic Context Ingestion.
Enable Dynamic Context Ingestion for the agent.
Review the configured variables.
Select Add Variable to define another visitor field.
The keys passed to setContext() should match the configured variable names so the agent knows how to use them.
Available Methods
Method | What it does |
|---|---|
| Encrypts and stores visitor context for the next conversation. |
| Replaces pending context with an empty object. |
| Makes the widget visible without starting a conversation. |
| Hides the widget without explicitly ending a conversation. |
| Shows or hides the widget. Omit |
| Starts the agent connection without changing widget visibility. |
| Shows the widget and starts the agent connection. |
| Disconnects the agent and hides the widget. |
Set Visitor Context
Call setContext() before the conversation starts. Each field value must be a string, number, boolean, or null. Nested objects, arrays, functions, dates, and undefined values are rejected.
const result = await window.AISeller.setContext({
name: "Jordan",
email: "jordan@example.com",
company: "Northstar Labs",
plan: "Enterprise",
isCustomer: true
});
if (!result.success) {
console.warn("Docket context was not stored:", result.message);
}setContext() returns a Promise that resolves to:
{
success: true | false,
message: "Context stored successfully"
}Each call replaces the pending encrypted context payload. Include the complete context object that the next conversation should receive.
Context is encrypted in the browser and stored temporarily until the conversation starts. The pending context is cleared after the backend acknowledges it.
Reset Visitor Context
Call resetContext() when the visitor logs out, changes identity, or when previously stored context is no longer valid.
const result = await window.AISeller.resetContext();
if (!result.success) {
console.warn("Docket context was not reset:", result.message);
}Resetting context does not change an in-progress conversation. It prepares an empty context object for the next conversation.
Start and Control the Widget
Use the built-in widget methods after the Docket script has loaded.
async function startSalesConversation() {
if (!window.AISeller?.setContext || !window.AISeller?.showAndConnect) {
console.warn("The Docket widget is not ready.");
return;
}
const result = await window.AISeller.setContext({
name: "Jordan",
company: "Northstar Labs",
source: "pricing-page"
});
if (!result.success) {
console.warn(result.message);
return;
}
window.AISeller.showAndConnect();
}To show the widget without starting a conversation:
window.AISeller.show();To end the connection and hide the widget:
window.AISeller.hideAndDisconnect();Verify the Implementation
Open the website in a private browser window.
Confirm
window.AISelleris available in the browser console.Call
setContext()with documentation-only values and confirm the returnedsuccessvalue istrue.Call
showAndConnect()and start a test conversation.Confirm the agent uses only the context variables you configured.
Call
resetContext(), start a new conversation, and confirm the previous values are no longer used.
Troubleshooting
Problem | What to check |
|---|---|
| Confirm the Docket script loaded successfully and call the API after it finishes loading. |
| Read the returned |
The agent ignores a field | Confirm the key matches a variable configured under Dynamic Context Ingestion and that context was set before the conversation started. |
Previous visitor data appears | Call |
The widget appears but does not connect | Use |
The widget connects but remains hidden | Use |