AI Integration Quick Reference
AI Integration Quick Reference
Before using the SDK, set up your channels, categories, templates, and campaigns in the CometChat Dashboard. See the Dashboard Setup Guide for step-by-step instructions.
Card Messages
A Card Message is a structured, interactive message rendered as a card bubble inside a conversation. Cards are receive-only on the SDK: they are created through the Platform REST API or the Dashboard Bubble Builder and delivered to clients like any other message — the SDK does not send them.- Type:
CardMessage(cometchat_sdk) - Category:
"card"(CometChatMessageCategory.card)
Properties
Listening for card messages
To be notified when a card message arrives, implementonCardMessageReceived on your MessageListener.
- Dart
Key Concepts
How Cards Render in the Notification Feed
EachNotificationFeedItem has a content field containing a Map<String, dynamic> — this is the Card Schema JSON. This JSON is passed directly to the CometChat Cards renderer package (cometchat_cards).
The rendering flow:
- Fetch feed items via
NotificationFeedRequest - For each item, extract
item.content— this is the Card Schema JSON - Convert to string:
jsonEncode(item.content) - Pass to the Cards renderer (
CometChatCardView) - The renderer produces a native Flutter widget from the JSON
Card Schema JSON Structure
body array contains elements (text, image, button, row, column, etc.) rendered top-to-bottom. Interactive elements like buttons emit actions via a callback — the consumer handles navigation, deep links, or API calls.
Retrieve Notification Feed Items
UseNotificationFeedRequest to fetch a paginated list of feed items. Uses cursor-based pagination internally.
Build the Request
- Dart
Builder Parameters
Fetch Items
Starting with v5.1.0, `fetchNext()` accepts a
listener: parameter. Pass a `NotificationFeedFetchListener` to receive the on-device cached result. The listener: parameter requires cometchat_sdk 5.1.0 or later, so on 5.0.x keep using onSuccess/onError. With offline support off, the listener behaves exactly like the callbacks: onError is unchanged, and the server result arrives in the onServer… callback instead of onSuccess. With offline support on, the listener also delivers the cached result first, then the server result. onSuccess/onError keep working and receive only the server result. See Show Cached Data.- Dart
fetchNext() repeatedly for pagination. When the server has no more items, subsequent calls return an empty list.
NotificationFeedItem Fields
Offline Behaviour
With offline support enabled,NotificationFeedRequest.fetchNext() on a NotificationFeedFetchListener first delivers onCachedNotificationFeedItems from the device (empty when nothing was recorded), then onServerNotificationFeedItems with the live page to reconcile by item id. Offline, the read ends with onError (code ERR_CONNECTION, details ERROR_INTERNET_UNAVAILABLE) after the cached page. A fetchNext() call made while another fetch of the same request is still running ends with onError (code ERROR_REQUEST_IN_PROGRESS). Once the list has ended, a further fetchNext() asks the server again and delivers only items this request has not delivered before. See Show Cached Data.
Retrieve Notification Categories
UseNotificationCategoriesRequest to fetch available categories for filter chips.
- Dart
NotificationCategory Fields
Real-Time Notification Feed Listener
Listen for new feed items arriving via WebSocket. This listener is independent fromMessageListener, GroupListener, and CallListener.
- Dart
- Dart
Mark Feed Item as Read
Mark a single item as read. Idempotent — safe to call multiple times.- Dart
Mark Feed Item as Delivered
Mark a single item as delivered. Idempotent.- Dart
Report Engagement
Report that a user engaged with a feed item (e.g., viewed, clicked, interacted). Idempotent.- Dart
interactionString parameter is a free-form string describing the engagement (e.g., "viewed", "clicked", "interacted").
Get Unread Count
Fetch the total number of unread notification feed items.- Dart
Fetch Single Feed Item
Fetch a specific item by ID — useful for deep linking from push notifications.- Dart
Push Notification Tracking
When a campaign push notification arrives via FCM/APNs, use these methods to report delivery and click engagement.Mark Push Notification as Delivered
Call this when you receive the push notification payload:- Dart
Mark Push Notification as Clicked
Call this when the user taps the push notification:- Dart
PushNotification Fields
FeedReadState Enum
Rendering Cards
Thecontent field of each NotificationFeedItem is a Card Schema JSON map. To render it natively, use the CometChat Cards library.
Add the Cards Dependency
Add the cards package to yourpubspec.yaml:
Render a Card from a Feed Item
- Dart
The Cards library is a pure renderer — it does not execute actions. Your code must handle action callbacks (opening URLs, navigating to chats, making API calls, etc.).