Your own Ask AI button
For developers. Typemo adds no chat button to your page. The chat opens from Ask AI in the search widget, or from your own element or code. This page lists the three ways to open it yourself.
All three work only while the assistant is on, with or without the search widget.
The data-ai-trigger attribute
Section titled “The data-ai-trigger attribute”Add data-ai-trigger to your install snippet, with a selector for your button:
<button id="ask-ai-button">Ask AI</button>
<script src="https://search.typemo.com/loader.js?k=YOUR_API_KEY" data-ai-trigger="#ask-ai-button" async></script>| Behaviour | Detail |
|---|---|
| Value | A CSS selector that starts with #, . or [, or a bare element id such as ask-ai-button. |
| Click | Opens the chat; a second click closes it. The click’s default action, such as following a link, is cancelled. |
| Several matches | Every element the selector matches opens the chat, such as a desktop and a mobile button. |
| Elements added later | Not bound: the selector is read once, when the assistant loads. Open the chat from code instead. |
| Hover or focus | The first one loads the chat in advance, so it opens without a wait. |
| The search overlay | Stays closed until the visitor clicks a category link under an answer. |
Every other script attribute is listed in Embed options.
Methods
Section titled “Methods”| Call | What it does |
|---|---|
typemoAssistant.open(question?) | Opens the chat. With a question, asks it right away. |
typemoAssistant.close() | Closes the chat. |
typemoAssistant.toggle() | Opens or closes it. |
typemoInstance.openChat() | The catalog search widget’s way to open the chat. |
typemoDocsInstance.openChat() | The docs search widget’s way to open the chat. |
window.typemoAssistant exists once the assistant script has loaded. The loader adds that script
only while the assistant is on.
Events
Section titled “Events”The search widget and the assistant are separate scripts. They talk through events on window,
and your page can send or hear each one.
| Event | Sent by | Heard by |
|---|---|---|
typemo:assistant:open | The search widget, or your page | The assistant |
typemo:assistant:close | The search widget, or your page | The assistant |
typemo:assistant:state | The assistant | The search widget, and your page |
typemo:search:open | The assistant, or your page | The catalog search widget |
typemo:assistant:open
Section titled “typemo:assistant:open”window.dispatchEvent( new CustomEvent('typemo:assistant:open', { detail: { query: 'Which size should I order?' } }));detail field | Type | What it does |
|---|---|---|
query | string | Optional. The question the chat asks as soon as it opens. |
collectionId | string | Optional. The collection the chat starts in, as a search tab does. |
typemo:assistant:close
Section titled “typemo:assistant:close”Closes the chat. It carries no detail.
typemo:assistant:state
Section titled “typemo:assistant:state”Sent each time the chat opens or closes. The search widget’s AI Assistant button shows itself pressed while the chat is open, and a second press closes it. Your own button can do the same.
window.addEventListener('typemo:assistant:state', (e) => { myButton.setAttribute('aria-pressed', String(e.detail.open));});detail field | Type | What it says |
|---|---|---|
open | boolean | true while the chat is open. |
typemo:search:open
Section titled “typemo:search:open”A category link under an answer sends it. It opens the search overlay with exactly what it carries.
detail field | Type | What it does |
|---|---|---|
collectionId | string | The collection to show. |
pins | string[] | Item ids shown first. |
pinsOnly | boolean | true shows only the pinned items. |
facets | Record<string, string[]> | Filter values to apply, by field. |
price | { field: string, min: number | null, max: number | null } or null | A price range to apply. |
query | string | Optional. Opens search on this query instead of the pinned items. |
Add to cart
Section titled “Add to cart”Product rows in an answer fire the same typemo:add-to-cart event on document as the search
results, so one cart handler serves both. See Events.
Next: Handle add to cart, or see every embed option.