Triggering the Widget Programmatically

Last updated: August 11, 2026

Use the built-in window.AISeller methods to open or connect the Docket widget from a button, form submission, or another event on your website.

Before You Begin

  • Install the Docket widget script.

  • Deploy the agent to the target domain.

  • Set the domain's widget behavior to On Click (Function Call) when the widget should not appear automatically.

  • Run your trigger code only after the Docket script has loaded.

Configure On-Click Behavior

Method

Use it when

showAndConnect()

You want to show the widget and start the conversation.

show()

You want to show the widget but let the visitor start the conversation.

connect()

You want to start the connection without changing visibility.

hide()

You want to hide the widget without explicitly disconnecting.

hideAndDisconnect()

You want to end the connection and hide the widget.

Trigger from a Button

<button id="talk-to-sales" type="button">Talk to Sales</button>

<script>
  document.getElementById("talk-to-sales").addEventListener("click", () => {
    if (!window.AISeller?.showAndConnect) {
      console.warn("The Docket widget is not ready.");
      return;
    }

    window.AISeller.showAndConnect();
  });
</script>

Set Context Before Opening

Wait for setContext() and check its result before starting the conversation.

async function startConversation(visitor) {
  if (!window.AISeller?.setContext || !window.AISeller?.showAndConnect) {
    console.warn("The Docket widget is not ready.");
    return;
  }

  const result = await window.AISeller.setContext({
    name: visitor.name,
    company: visitor.company,
    source: "pricing-page"
  });

  if (!result.success) {
    console.warn(result.message);
    return;
  }

  window.AISeller.showAndConnect();
}

Verify the Trigger

  1. Open the deployed page in a private browser window.

  2. Confirm the widget does not open automatically when On Click (Function Call) is selected.

  3. Select your website CTA.

  4. Confirm the widget becomes visible and the conversation starts.

  5. Repeat the test on mobile and desktop layouts.

Troubleshooting

Problem

What to check

window.AISeller is undefined

Confirm the Docket script loaded before your event handler runs.

The widget opens before the click

Confirm the domain is set to On Click (Function Call) rather than an automatic page rule.

The widget appears but does not connect

Use showAndConnect() instead of show().

The connection starts but the widget remains hidden

Use showAndConnect() instead of connect().

Visitor context is missing

Await setContext(), confirm result.success, and then call showAndConnect().

Related Articles