This page documents the client-side Browser API exposed by the embed
script. For server-side REST endpoints, see your API Reference.
Overview
Once the Homie embed script is loaded, a global objectwindow.homieBot becomes available.
Use it to open/close the widget, check its state, send messages programmatically, and read the chat history.
Requirements
- The script must be embedded on your page.
chatbotIdanddomainmust be set.
API Reference: window.homieBot
open()
Opens the chat (if closed).
close()
Closes the chat (if open).
toggle()
Toggles between open/closed.
isOpen() → boolean
Returns whether the chat is currently open.
sendMessage(input, options?) → Promise<boolean>
Injects a message directly into the chat — ideal for PDPs or context-driven prompts.
input (required: text)
| Field | Type | Description |
|---|---|---|
text | string | The message to inject. |
id | string | (optional) Your own reference/tracking ID. |
setId | string | (optional) Question set ID for tracking. |
questionId | string | (optional) Question ID within the set. |
newChat | boolean | (optional) Start a new conversation. |
options
| Field | Type | Default | Description |
|---|---|---|---|
open | boolean | true | Open chat if closed. |
maxRetries | number | 3 | Retries while the iFrame initializes. |
retryDelay | number | 300 | Milliseconds between retries. |
timeout | number | 5000 | Total timeout in ms waiting for ACK. |
relaxedOrigin | boolean | false | Disable origin checks (special cases only). |
getHistory() → Promise<any>
Returns the current chat history (useful for Custom-Tracking).
Practical Examples
1) Auto-open after 10 seconds
2) Trigger an intent on a PDP
3) Open after scroll depth
Robust loading: waitForHomie()
If your code runs before the embed has finished loading, wait until window.homieBot exists:
Embedding & Configuration
At minimum, setchatbotId and domain on the script tag. Styling and behavior are managed from the Homie dashboard and pulled in automatically by the embed.
iconColor,iconRounded,iconImage,iconSize,iconImagePaddingiconBottomPadding,iconSidePadding,iconAlign(left|right)showHoverText,isPrivate,active
Advanced: Some customers provide
window.homieUserConfig to pass
user_id, user_hash, and user_metadata. The embed forwards
these safely to the iFrame (Base64‑encoded metadata).Troubleshooting
window.homieBotis undefined → Ensure the script actually loads (Network tab) and usewaitForHomie().- No response to
sendMessage→ Check if the site blocks iFrames, uses strict CSP, or delays third‑party scripts. Also, wait fordocument.readyState === "complete". - Chat opens but no replies → Verify API base access depending on the domain (
api.yourhomie.ai,staging.api.yourhomie.ai,dev.api.yourhomie.ai). - Checkout specific → The embed preloads the iFrame automatically when a configured
checkoutUrlmatches. Verify exact URLs during testing.
FAQ
Can I force a new conversation?Yes:
sendMessage({ text: "...", newChat: true }).
How are question events tracked?If
setId (and optionally questionId) are provided, the script sends a fire‑and‑forget tracking call to the public endpoint in the background. This does not affect the message injection itself.
Can I query the state without opening the chat?Yes,
isOpen() returns the state and does not alter the UI.
TL;DR
| Method | Purpose |
|---|---|
open() | Open the chat |
close() | Close the chat |
toggle() | Toggle open/closed |
isOpen() | Read current state |
sendMessage(input, options?) | Inject a message (with retry/timeout) |
getHistory() | Read the current history |