Frontend API (JavaScript)
Control the Widget and wire navigation + identity.
Get a Widget instance
import { createWidget, getWidget } from 'https://cdn.chatbyte.ai/spark.min.js';
const widget = await createWidget('your-agent-id');
const existing = getWidget('your-agent-id');Widget controls
widget.open();
widget.close();
widget.toggle();Contextual notifications
widget.showNotification({
id: 'pricing-page',
text: 'Ask us about this page.',
oncePerSession: true,
});
widget.hideNotification('pricing-page');
// Temporarily prevent launcher notifications from overlapping a host UI.
widget.setNotificationsSuppressed(true);
widget.setNotificationsSuppressed(false);Saved automatic prompts are configured in Chatbyte settings. Use showNotification for page-specific runtime context.
Navigation handling
widget.setNavigationHandler((url) => {
router.push(url);
});Identity methods
widget.identify({ token });
widget.onRequestToken(async () => {
const response = await fetch('/api/widget-token');
const { token } = await response.json();
return token;
});For JWT requirements, see JWT & Identity.