Skip to main content

API Reference: window.homieBot

open()

Opens the chat (if closed).
window.homieBot.open();

close()

Closes the chat (if open).
window.homieBot.close();

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");
}

sendMessage(input, options?)Promise<boolean>

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)
FieldTypeDescription
textstringThe message to inject.
idstring(optional) Your own reference/tracking ID.
setIdstring(optional) Question set ID for tracking.
questionIdstring(optional) Question ID within the set.
newChatboolean(optional) Start a new conversation.
options
FieldTypeDefaultDescription
openbooleantrueOpen chat if closed.
maxRetriesnumber3Retries while the iFrame initializes.
retryDelaynumber300Milliseconds between retries.
timeoutnumber5000Total timeout in ms waiting for ACK.
relaxedOriginbooleanfalseDisable 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);

updateMessageMetadata(metadata)void

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
ConstraintLimit
Max Keys5 key-value pairs per call
Key LengthMax 50 characters
Value LengthMax 100 characters
Key TypeMust be string
Value TypeString 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,
});