Context enrichment
The backend already gets your catalog from your e-com backend (ingest). Your app can supplement it with live client-side context so the bot answers without asking — what screen the user is on, what product they're viewing, what's in the cart.
Both methods reuse existing backend frames — there is no backend change required.
The whole payload reaches the model. Never put a buyer's name, email, phone, address, payment data, or any
personally-identifying order id in AppContext / CartEvent. Keep it to catalog/UI coordinates and a
loggedIn boolean (never a user id).
updateContext(AppContext)
Send it on every screen change, or let the navigation helpers send it. Carries the current
screen/route, current product id, viewed category, locale, an auth loggedIn boolean, and merchant custom
key/values. The client keeps the last context and sends it to every session it opens.
- React Native
- Flutter
client.updateContext({
screen: 'ProductDetails',
currentProductId: 'sku-42',
category: 'phones',
locale: 'uk',
loggedIn: true,
custom: { promoActive: true },
});
client.updateContext(const AppContext(
screen: 'product',
route: '/product/42',
currentProductId: '42',
category: 'laptops',
locale: 'uk',
custom: {'promo': 'summer'}, // arbitrary non-PII signals
));
The latest context is retained and re-sent automatically after a reconnect or resume, so the bot stays oriented across a backgrounding round-trip.
Navigation
The navigation helpers send the current screen for you, 300 ms after the last move, so most apps never call
updateContext by hand.
- React Native
- Flutter
React Navigation:
import { createNavigationContainerRef, NavigationContainer } from '@react-navigation/native';
import { useMonoverseNavigation } from '@monoverse/react-native';
const navigationRef = createNavigationContainerRef();
function Root() {
useMonoverseNavigation(navigationRef);
return <NavigationContainer ref={navigationRef}>{/* screens */}</NavigationContainer>;
}
The default map sends { screen: route.name, currentProductId: params.productId ?? params.id }, so moving to
Product with { id: 42 } sends { screen: 'Product', currentProductId: '42' }. Pass mapRoute as the
second argument to send your own AppContext.
Expo Router, an optional peer that the main entry never imports:
import { useMonoverseExpoRouter } from '@monoverse/react-native/expo-router';
export default function Layout() {
useMonoverseExpoRouter();
return <Stack />;
}
It sends { screen: pathname }, plus currentProductId for a /product/<id> path; mapPath overrides it.
Both hooks read the client from the nearest MonoverseProvider.
final observer = MonoverseNavigatorObserver(client);
MaterialApp(navigatorObservers: [observer]);
GoRouter(observers: [observer], routes: [...]);
The screen is the route's settings.name, the route is that name with its :parameters filled from a map
argument, and the product is the argument's productId or id: GoRoute(path: '/product/:id') reports the
route /product/42. Pass mapRoute to build the AppContext yourself; a null sends nothing for that
screen. Dialogs are not screens.
sendCartEvent(...)
Send a cart snapshot on start, then deltas (add / remove / quantity change), so the bot knows what's in the cart without a round-trip.
- React Native
- Flutter
// Snapshot on start:
session.sendCartEvent({
type: 'snapshot',
currency: 'UAH',
items: [{ productId: 'sku-42', quantity: 1, price: 14999 }],
});
// Deltas afterward:
session.sendCartEvent({ type: 'add', items: [{ productId: 'sku-7', quantity: 2 }] });
session.sendCartEvent(const CartEvent(
type: CartEventType.added,
items: [CartLineItem(productId: '42', quantity: 1, price: 15000, currency: 'UAH')],
));
pricehere is a catalog price, not order/payment data — it stays within the zero-PII contract.
What this maps to on the wire
| SDK call | Wire frame |
|---|---|
updateContext(...) | { "type": "client_context", "page_context": {…}, "discovered_urls": [...] } |
sendCartEvent(...) | { "type": "cart_event", … } |
| (registered handlers) | declared in { "type": "hello", "capabilities": { … } } |
See Wire protocol §10 for the frame details.