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 |
|---|---|
| You want to show the widget and start the conversation. |
| You want to show the widget but let the visitor start the conversation. |
| You want to start the connection without changing visibility. |
| You want to hide the widget without explicitly disconnecting. |
| 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
Open the deployed page in a private browser window.
Confirm the widget does not open automatically when On Click (Function Call) is selected.
Select your website CTA.
Confirm the widget becomes visible and the conversation starts.
Repeat the test on mobile and desktop layouts.
Troubleshooting
Problem | What to check |
|---|---|
| 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 |
The connection starts but the widget remains hidden | Use |
Visitor context is missing | Await |