JavaScript API
Control the chat widget with a small and reliable set of methods.
The global object is window.LoopSmartAI.
Core methods
open()
window.LoopSmartAI.open();close()
window.LoopSmartAI.close();toggle()
window.LoopSmartAI.toggle();setProductContext(context)
window.LoopSmartAI.setProductContext({
productCode: "SKU-123",
productName: "Example Product",
});setUserContext(context)
window.LoopSmartAI.setUserContext({
id: "user-123",
email: "user@example.com",
});updateContext(productContext, userContext)
window.LoopSmartAI.updateContext(
{
productCode: "SKU-123",
},
{
id: "user-123",
},
);Calling pattern
window.LoopSmartAI.open();
window.LoopSmartAI.setProductContext({ productCode: "SKU-123" });window.LoopSmartAI = { q: [] };
window.LoopSmartAI.q.push(["init", { agentId: "YOUR_AGENT_ID" }]);TypeScript helper
interface LoopSmartAI {
open: () => void;
close: () => void;
toggle: () => void;
setProductContext: (context: Record<string, unknown>) => void;
setUserContext: (context: Record<string, unknown>) => void;
updateContext: (
productContext: Record<string, unknown>,
userContext: Record<string, unknown>,
) => void;
q?: Array<[string, unknown?]>;
live?: boolean;
}
declare global {
interface Window {
LoopSmartAI: LoopSmartAI;
}
}Continue to How It Works.