Untitled

Programmatic API (JavaScript)


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.


Example

<!-- 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>


API

Nobi.initialize(config)

Boots the app and attaches the UI container to the page.

Nobi.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()boolean

Returns 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.


Common patterns

1) Button that opens Nobi

<button id="open-nobi">Shop with AI</button>
<script>
  document.getElementById('open-nobi').addEventListener('click', () => {
    Nobi.openChat();
  });
</script>

2) Form that submits a question and opens Nobi

<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>

3) Open with predefined assistant copy (promo/CTA)

Nobi.openChat({
  assistantMessage: "Tell me who you're shopping for and a price range—I'll curate picks."
});

Behavior & lifecycle


Troubleshooting


Notes for advanced setups