The User Context API allows you to send contextual information to the assistant from anywhere in your application. This works across all frameworks and provides real-time context to both voice and chat interactions.
import { sendUserContext } from "navi-web";// Silent contextual message (default) - provides background context to AIsendUserContext("User viewing order #12345, status: pending, total: $299.99");// User message - appears as an actual message in the chat conversationsendUserContext("I need help with this order", { silent: false });
Silent messages provide background context to the AI without appearing in the chat interface:
Copy
// These won't show up in the chat UI but inform the AI about user statesendUserContext("User on pricing page, viewing premium plan");sendUserContext("Form validation failed: email field empty");sendUserContext("User scrolled to testimonials section");
User messages appear as actual messages in the chat conversation:
Copy
// These will appear as user messages in the chatsendUserContext("I'm having trouble with checkout", { silent: false });sendUserContext("Can you help me find the refund policy?", { silent: false });
// Avoid over-detailed context// sendUserContext("Mouse moved to position 150,200"); // Too granular// sendUserContext("User scrolled 50px"); // Not meaningful// sendUserContext("Button hover state changed"); // Too frequent
In multi-page applications, context is queued and persists across page reloads:
Copy
// This works even before the widget is initializedsendUserContext("User came from Google search for 'product reviews'");// Context persists for ~5 minutes across page navigationsendUserContext("User previously viewed 5 products in Electronics category");
When using the CDN version, the API is available on window.Navi:
Copy
// Works anywhere after the CDN script loadsNavi.sendUserContext("User viewing order #123, total: $299");// User message modeNavi.sendUserContext("I need help with this order", { silent: false });