Use the JavaScript API when you want to open/close Nobi from your own UI (buttons, forms, menu items) instead of—or in addition to—the built‑in UX elements.
Nobi exposes a small global on window.Nobi. Calls made before the app finishes booting are queued and replayed automatically, so you can call Nobi.openChat() as soon as your page loads.
<!-- 1) Load Nobi -->
<script async src="<https://assistant-script.nobi.ai/nobi.bundle.js>"></script>
<script>
// 2) Initialize (merchantId required)
Nobi.initialize({ merchantId: "YOUR_MERCHANT_ID" });
// 3) Anywhere in your code: open/close
Nobi.openChat();
// Or add an optional message:
// Nobi.openChat({ message: "Show me trail running shoes under $120" });
// Close the chat
// Nobi.closeChat();
</script>
Nobi.initialize(config)Boots the app and attaches the UI container to the page.
merchantId: stringassistantConfiguration: object, debugMode: booleanNobi.initialize({
accountId: "YOUR_ACCOUNT_ID",
assistantConfiguration: {/* optional */},
debugMode: false
});
Nobi.openChat(options?)Opens the assistant drawer. Accepts an optional payload to seed context.
// Options are all optional
{
message?: string; // preset shopper question
assistantMessage?: string | null; // preset assistant greeting/CTA
categories?: any; // pass category identifiers your setup expects
cartProductVariantInternalId?: string | number; // preattach a specific variant
cartProductInternalId?: string | number; // preattach a product
hideQuickAdd: true | false // setting this to true will hide the quick add overlay
}
Examples:
// Open empty
Nobi.openChat();
// Open with a preset question
Nobi.openChat({ message: "Show me gifts under $50" });
// Open targeting a context (categories/cart)
Nobi.openChat({
categories: ["running", "trail"],
cartProductInternalId: "12345",
cartProductVariantInternalId: "12345-RED-10"
});
// Force a specific entry point (falls back to your configured default)
Nobi.openChat({ entryPoint: "chat" });
Nobi.closeChat()Closes the assistant drawer.
Nobi.isChatOpen() → booleanReturns whether the drawer is currently open.
Nobi.addVisitorContext(text)Pushes a free-form context string about the current visitor into their Nobi profile. Use this to pass intent or situation signals that you have gathered on your own pages before the visitor opens a chat.
// Called from your blog, landing page, or any page that has the Nobi widget loaded.
// Text can be any plain-English description of the visitor's situation.
Nobi.addVisitorContext(
"Visitor clicked 'Actively evaluating tools right now' on the Klevu alternatives comparison page"
);
// Commonly paired with openChat so the AI opens with full context:
Nobi.addVisitorContext("Visitor indicated they are in the process of switching from a competitor");
Nobi.openChat({ assistantMessage: "Looks like you're comparing options -- happy to help you decide." });
What Nobi does with this text:
Each call appends a new entry. Entries age out after 12 months. The method is queue-safe: if called before Nobi.initialize(...) completes, the call is stored and replayed.
Safe to call early: Before the app binds its live handlers, openChat/closeChat calls are queued and replayed after initialization.
<button id="open-nobi">Shop with AI</button>
<script>
document.getElementById('open-nobi').addEventListener('click', () => {
Nobi.openChat();
});
</script>
<form id="ask-nobi">
<input id="nobi-msg" placeholder="Ask Nobi…" />
<button type="submit">Ask</button>
</form>
<script>
document.getElementById('ask-nobi').addEventListener('submit', (e) => {
e.preventDefault();
const msg = document.getElementById('nobi-msg').value.trim();
if (!msg) return;
Nobi.openChat({ message: msg });
});
</script>
Nobi.openChat({
assistantMessage: "Tell me who you're shopping for and a price range—I'll curate picks."
});
Nobi.openChat() before Nobi.initialize(...), the call is stored and replayed once the app is ready.nobi-app-container that is appended to <body> automatically.main.css) automatically.Nobi is undefined → Make sure the script tag is present before you call the API.isChatOpen() always false on first tick → Expected until the app binds live handlers; initialize first.merchantId is provided to Nobi.initialize(...).entryPoint selects a specific UI entry context if your configuration defines multiple. If unsure, omit and the default entry point will be used.