Skip to content

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.

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>
BehaviourDetail
ValueA CSS selector that starts with #, . or [, or a bare element id such as ask-ai-button.
ClickOpens the chat; a second click closes it. The click’s default action, such as following a link, is cancelled.
Several matchesEvery element the selector matches opens the chat, such as a desktop and a mobile button.
Elements added laterNot bound: the selector is read once, when the assistant loads. Open the chat from code instead.
Hover or focusThe first one loads the chat in advance, so it opens without a wait.
The search overlayStays closed until the visitor clicks a category link under an answer.

Every other script attribute is listed in Embed options.

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

The search widget and the assistant are separate scripts. They talk through events on window, and your page can send or hear each one.

EventSent byHeard by
typemo:assistant:openThe search widget, or your pageThe assistant
typemo:assistant:closeThe search widget, or your pageThe assistant
typemo:assistant:stateThe assistantThe search widget, and your page
typemo:search:openThe assistant, or your pageThe catalog search widget
window.dispatchEvent(
new CustomEvent('typemo:assistant:open', {
detail: { query: 'Which size should I order?' }
})
);
detail fieldTypeWhat it does
querystringOptional. The question the chat asks as soon as it opens.
collectionIdstringOptional. The collection the chat starts in, as a search tab does.

Closes the chat. It carries no detail.

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 fieldTypeWhat it says
openbooleantrue while the chat is open.

A category link under an answer sends it. It opens the search overlay with exactly what it carries.

detail fieldTypeWhat it does
collectionIdstringThe collection to show.
pinsstring[]Item ids shown first.
pinsOnlybooleantrue shows only the pinned items.
facetsRecord<string, string[]>Filter values to apply, by field.
price{ field: string, min: number | null, max: number | null } or nullA price range to apply.
querystringOptional. Opens search on this query instead of the pinned items.

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.