API Reference: window.homieBot
open()
Opens the chat (if closed).
close()
Closes the chat (if open).
toggle()
Toggles between open/closed.
window.homieBot.toggle();
isOpen() → boolean
Returns whether the chat is currently open.
if (window.homieBot.isOpen()) {
console.log("Chat is open");
}
Injects a message directly into the chat — ideal for PDPs or context-driven prompts.
await window.homieBot.sendMessage(
{ text: "Do you have this product in grey?" },
{ open: true } // opens the chat before sending
);
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).
const history = await window.homieBot.getHistory();
console.log("Chat history:", history);
Adds metadata to the next user message as key-value pairs. The metadata is sent to the chat widget. If the widget is not yet initialized, the metadata is stored in a pending state and automatically sent once the widget is ready.
window.homieBot.updateMessageMetadata({
productId: "12345",
category: "power-tools",
source: "pdp",
});
Limits & Validation
| Constraint | Limit |
|---|
| Max Keys | 5 key-value pairs per call |
| Key Length | Max 50 characters |
| Value Length | Max 100 characters |
| Key Type | Must be string |
| Value Type | String or null (to remove a key) |
Overwriting Metadata
- Existing keys can be overwritten with new values
- Keys can be removed by passing
null as the value
- Multiple calls to
updateMessageMetadata() are merged — new keys are added, existing keys are updated
// Set initial metadata
window.homieBot.updateMessageMetadata({
productId: "12345",
category: "power-tools",
});
// Update existing key and add new one
window.homieBot.updateMessageMetadata({
category: "hand-tools", // overwrites existing
brand: "Bosch", // adds new key
});
// Remove a key
window.homieBot.updateMessageMetadata({
brand: null, // removes the key
});
Single-Page Applications (SPAs): Metadata keys persist across navigation
since they are stored in the global window context. When navigating between
pages, you must manually clear the metadata by calling
updateMessageMetadata() with null values to avoid
unintended persistence.
// Clear metadata on route change in SPA
window.homieBot.updateMessageMetadata({
productId: null,
category: null,
source: null,
});