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.

  1. Enable Dynamic Context Ingestion for the agent.

  2. Review the configured variables.

  3. 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

window.AISeller.setContext(data)

Encrypts and stores visitor context for the next conversation.

window.AISeller.resetContext()

Replaces pending context with an empty object.

window.AISeller.show()

Makes the widget visible without starting a conversation.

window.AISeller.hide()

Hides the widget without explicitly ending a conversation.

window.AISeller.toggle(show)

Shows or hides the widget. Omit show to toggle the current state.

window.AISeller.connect(options)

Starts the agent connection without changing widget visibility.

window.AISeller.showAndConnect(options)

Shows the widget and starts the agent connection.

window.AISeller.hideAndDisconnect()

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

  1. Open the website in a private browser window.

  2. Confirm window.AISeller is available in the browser console.

  3. Call setContext() with documentation-only values and confirm the returned success value is true.

  4. Call showAndConnect() and start a test conversation.

  5. Confirm the agent uses only the context variables you configured.

  6. Call resetContext(), start a new conversation, and confirm the previous values are no longer used.

Troubleshooting

Problem

What to check

window.AISeller is undefined

Confirm the Docket script loaded successfully and call the API after it finishes loading.

success is false

Read the returned message. Confirm the payload is a non-null object and every value is a supported simple type.

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 resetContext() when the visitor logs out or changes identity.

The widget appears but does not connect

Use showAndConnect() rather than show().

The widget connects but remains hidden

Use showAndConnect() rather than connect().

Related Articles