AI Integration Quick Reference
AI Integration Quick Reference
@cometchat/cards-angular renderer and forwards every card action back to your application.
The UIKit is a render-only consumer of cards: it draws cards delivered by the SDK and forwards their actions to your app. It never parses or mutates the card body, and never sends or creates cards.
The render-only contract
The UIKit is a render-only consumer of cards. For every card surface, the rules are identical:- Pass the payload through unchanged. The raw card payload is read from the SDK and handed to
CometChatCardViewas acardJsonstring — an object payload is serialized withJSON.stringify, while a payload that is already a string is passed through as-is. The UIKit performs no transformation. - Forward actions, run no behavior. The renderer emits actions through callbacks. The UIKit forwards them on the
ccCardActionClickedevent bus. Your app implements all behavior (open a URL, start a chat, call an API, …). - Fall back gracefully. When a payload is empty or invalid, a single fallback line is shown instead of a broken card.
Three delivery paths
A card can reach the conversation in three ways. The UIKit routes each one to the correct renderer automatically.Developer cards
A message with category"card" is routed to CometChatCardBubbleComponent by CometChatMessageBubble, keyed on category (the developer type is arbitrary). The bubble renders message.getCard() and forwards taps on the ccCardActionClicked bus.
In the conversation list, a card message’s preview is its getText() if present, otherwise the localized "Card Message" label.
To react to incoming developer cards in real time, listen on the message bus:
Persisted agent cards
After an AI agent run completes, the persistedAIAssistantMessage exposes its content as an ordered list of blocks via getElements(). CometChatAIAssistantMessageBubble renders them in order:
- a
textblock renders as Markdown (viaCometChatMarkdownRenderer); - a
cardblock renders throughCometChatCardView, using the same render-only path as developer cards.
getAssistantMessageData().getText(). No additional wiring is required — the AI Assistant Chat flow instantiates this bubble for you. Taps on a nested agent card are forwarded on the same ccCardActionClicked bus.
Streaming agent cards
While an agent run is streaming, cards arrive progressively and are rendered byCometChatStreamMessageBubble, which subscribes to the streaming service’s messageStream$:
Because no persisted message exists yet during streaming, a tap on a streaming card is forwarded with
message: null on the ccCardActionClicked bus; the persisted bubble that follows is the source of truth.
Handling card actions
The Cards renderer emits actions but never executes them. The UIKit forwards each action untouched onCometChatMessageEvents.ccCardActionClicked. Subscribe once at app startup and dispatch by action type.
The event payload
Action types
action is a CometChatCardAction — a discriminated union (from @cometchat/cards-angular) narrowed by its type. The UIKit forwards all of them; your app decides what each one does:
Reference handler
Subscribe once (a root-provided service is the natural home) and dispatch bytype. The snippet below mirrors the sample app’s reference implementation:
ngOnInit:
customCallback actions
A customCallback action carries a callbackId (and optional payload). Map each callbackId to an app-defined handler, and use event.elementId / event.cardJson / event.message?.getId() for context. No server message is sent by the UIKit for a custom callback — it is entirely app-defined.
Fallback behavior
When a payload is empty or invalid, a single fallback line is shown instead of a broken card. The exact resolution depends on the surface:- Developer card —
getFallbackText()→getText()→ localized"Card Message". - Persisted agent card — the card’s own
fallbackText→ localized"Card Message". - Streaming agent card — no fallback line; an empty streamed card is simply not rendered (the run-complete persisted message is the source of truth).
Related
- Card Bubble — the developer card component reference.
- AI Assistant Chat — the agent chat experience that renders persisted and streaming agent cards.
- Events —
ccCardActionClickedandonCardMessageReceivedreference.