Skip to main content

Message types — Overview

Every message that arrives via IConnector.onMessage carries a type string. The widget looks that type up in MessageTypeRegistry and renders the matching LitElement.

interface IncomingMessage {
id: string;
type: string; // ← key into MessageTypeRegistry
from?: "bot" | "user";
data: Record<string, unknown>; // ← shape depends on type
timestamp?: number;
actions?: MessageAction[]; // optional quick-reply chips
}

Schema: schemas/messages/incoming-message.schema.json.

TopicPage
Built-in types and their data shapesBuilt-in
Register your own component for a typeCustom

Resolution order

  1. MessageTypeRegistry.get(type) — matches an explicitly registered renderer.
  2. Falls back to the built-in text renderer for safety.

Registries are singletons

import { MessageTypeRegistry } from "@chativa/core";

MessageTypeRegistry.register("product-card", ProductCardMessage);
MessageTypeRegistry.has("product-card"); // true
MessageTypeRegistry.get("product-card"); // ProductCardMessage
MessageTypeRegistry.list(); // ["text", "image", ..., "product-card"]
MessageTypeRegistry.clear(); // tests only

Built-in types are auto-registered on import of @chativa/ui. Re-registering a name overrides it — useful when you want to swap the default card renderer for your own.