Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-docs-react-js-campaigns-notification-feed.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

CometChat Campaigns lets you deliver targeted, rich notifications to users via an in-app notification feed. Each notification is a Card Schema JSON — a structured layout rendered natively by the CometChat Cards library. The SDK provides APIs to fetch feed items, listen for real-time delivery, mark items as read/delivered, report engagement, and retrieve unread counts.

Key Concepts

ConceptDescription
NotificationFeedItemA single notification in the feed. Contains Card Schema JSON in its content field, a category for filtering, timestamps, and metadata.
NotificationCategoryA category label used for filter chips (e.g., “Promotions”, “Updates”).
Card Schema JSONThe fully rendered card layout (images, text, buttons) inside NotificationFeedItem.getContent(). Passed directly to the CometChat Cards renderer.
PushNotificationRepresents a campaign push notification payload received via FCM/APNs or Web Push.

How Cards Render in the Notification Feed

Each NotificationFeedItem has a content field containing an object — this is the Card Schema JSON. This JSON is passed directly to the CometChat Cards renderer library (@cometchat/cards-react). The rendering flow:
  1. Fetch feed items via NotificationFeedRequestBuilder
  2. For each item, extract item.getContent() — this is the Card Schema JSON
  3. Convert to string: JSON.stringify(item.getContent())
  4. Pass to the Cards renderer (CometChatCardView)
  5. The renderer produces a native DOM element from the JSON

Card Schema JSON Structure

{
  "version": "1.0",
  "body": [
    { "type": "image", "id": "img_1", "url": "https://...", "height": 200 },
    { "type": "text", "id": "txt_1", "content": "Flash Sale!", "variant": "heading2" },
    { "type": "button", "id": "btn_1", "label": "Shop Now", "action": { "type": "openUrl", "url": "https://..." } }
  ],
  "style": { "background": {"light": "#FFFFFF", "dark": "#1E1E1E"}, "borderRadius": 12, "padding": 16 },
  "fallbackText": "Flash Sale! Shop Now: https://..."
}
The 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

Use NotificationFeedRequestBuilder to fetch a paginated list of feed items. Uses cursor-based pagination internally.

Build the Request

const request = new CometChat.NotificationFeedRequestBuilder()
  .setLimit(20)
  .build();

Builder Parameters

MethodTypeDefaultDescription
setLimit(limit)number20Items per page (max 100)
setReadState(state)FeedReadState"all"Filter by "read", "unread", or "all"
setCategory(category)stringnullFilter by category label
setChannelId(channelId)stringnullFilter by channel
setTags(tags)string[]nullFilter by tags
setDateFrom(date)stringnullISO 8601 date — items sent on or after
setDateTo(date)stringnullISO 8601 date — items sent on or before

Fetch Items

request.fetchNext().then(
  (items) => {
    for (const item of items) {
      const cardJson = JSON.stringify(item.getContent());
      // Pass cardJson to CometChatCardView
    }
  },
  (error) => {
    console.error("Feed fetch error:", error.message);
  }
);
Call fetchNext() repeatedly for pagination. When the server has no more items, subsequent calls return an empty array.

NotificationFeedItem Fields

FieldTypeDescription
getId()stringUnique item identifier
getCategory()stringNotification category (e.g., “promotions”)
getContent()objectCard Schema JSON — pass to CometChat Cards renderer
getReadAt()number | nullUnix timestamp when read, or null if unread
getDeliveredAt()number | nullUnix timestamp when delivered, or null
getSentAt()numberUnix timestamp when sent
getMetadata()Record<string, any>Custom key-value metadata
getTags()string[]Tags for filtering
getSender()stringSender identifier
getReceiver()stringReceiver identifier
getReceiverType()stringReceiver type
getIsRead()booleanWhether the item has been read

Retrieve Notification Categories

Use NotificationCategoriesRequestBuilder to fetch available categories for filter chips.
const categoriesRequest = new CometChat.NotificationCategoriesRequestBuilder()
  .setLimit(50)
  .build();

categoriesRequest.fetchNext().then(
  (categories) => {
    for (const category of categories) {
      console.log("Category:", category.getLabel());
    }
  },
  (error) => {
    console.error("Categories fetch error:", error.message);
  }
);

NotificationCategory Fields

FieldTypeDescription
getId()stringCategory identifier
getLabel()stringDisplay name for filter UI

Real-Time Notification Feed Listener

Listen for new feed items arriving via WebSocket. This listener is independent from MessageListener, GroupListener, and CallListener.
CometChat.addNotificationFeedListener("feedListener", {
  onFeedItemReceived: (feedItem) => {
    console.log("New item:", feedItem.getId());
    const cardJson = JSON.stringify(feedItem.getContent());
    // Insert at top of feed and render
  },
});
Remove the listener when no longer needed:
CometChat.removeNotificationFeedListener("feedListener");

Mark Feed Item as Read

Mark a single item as read. Idempotent — safe to call multiple times.
CometChat.markFeedItemAsRead(feedItem).then(
  () => { console.log("Marked as read"); },
  (error) => { console.error("Error:", error.message); }
);

Mark Feed Item as Delivered

Mark a single item as delivered. Idempotent.
CometChat.markFeedItemAsDelivered(feedItem).then(
  () => { /* Success */ },
  (error) => { console.error("Error:", error.message); }
);

Mark Multiple Items as Delivered (Batch)

CometChat.markFeedItemsAsDelivered(feedItems).then(
  () => { /* Success */ },
  (error) => { console.error("Error:", error.message); }
);

Report Engagement

Report that a user engaged with a feed item (e.g., viewed, clicked, interacted). Idempotent.
CometChat.reportFeedEngagement(feedItem, "clicked").then(
  () => { /* Success */ },
  (error) => { console.error("Error:", error.message); }
);
The 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.
CometChat.getNotificationFeedUnreadCount().then(
  (result) => { console.log("Unread:", result.count); },
  (error) => { console.error("Error:", error.message); }
);

Fetch Single Feed Item

Fetch a specific item by ID — useful for deep linking from push notifications.
CometChat.getNotificationFeedItem("item-id-123").then(
  (item) => {
    const cardJson = JSON.stringify(item.getContent());
    // Render the card
  },
  (error) => { console.error("Error:", error.message); }
);

Push Notification Tracking

When a campaign push notification arrives via Web Push or FCM, use these methods to report delivery and click engagement.

Mark Push Notification as Delivered

Call this when the push notification is received:
const pushNotification = new CometChat.PushNotification(pushPayloadJson);

CometChat.markPushNotificationDelivered(pushNotification).then(
  () => { /* Success */ },
  (error) => { console.error("Error:", error.message); }
);

Mark Push Notification as Clicked

Call this when the user taps the push notification:
CometChat.markPushNotificationClicked(pushNotification).then(
  () => { /* Success */ },
  (error) => { console.error("Error:", error.message); }
);

PushNotification Fields

FieldTypeDescription
getId()stringAnnouncement ID from the push payload
getAnnouncementId()stringSame as id (for clarity)
getCampaignId()string | nullCampaign ID if from a campaign
getSource()stringAlways "campaign" for notification feed pushes

FeedReadState

ValueDescription
"read"Only read items
"unread"Only unread items
"all"All items (default)

Rendering Cards

The content field of each NotificationFeedItem is a Card Schema JSON object. To render it natively, use the CometChat Cards library.

Add the Cards Dependency

npm install @cometchat/cards-react
If you’re using @cometchat/chat-uikit-react v6.5.0+, the cards library is included automatically as a dependency.

Render a Card from a Feed Item

import { CometChatCardView } from "@cometchat/cards-react";

function NotificationCard({ item }) {
  const cardJson = JSON.stringify(item.getContent());

  return (
    <CometChatCardView
      cardJson={cardJson}
      themeMode="auto"
      onAction={(event) => {
        const { action, elementId } = event;
        switch (action.type) {
          case "openUrl":
            // Open URL in browser
            window.open(action.url, "_blank");
            break;
          case "chatWithUser":
            // Navigate to chat with action.uid
            break;
          case "chatWithGroup":
            // Navigate to group chat with action.guid
            break;
        }
      }}
    />
  );
}
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.).

Supported Card Actions

When a user taps a button or link inside a card, the action callback receives one of these action types:
Action TypeParametersDescription
openUrlurl, openInOpen a URL in browser or webview
chatWithUseruidNavigate to 1:1 chat
chatWithGroupguidNavigate to group chat
sendMessagetext, receiverUid, receiverGuidSend a text message
copyToClipboardvalueCopy text to clipboard
downloadFileurl, filenameDownload a file
initiateCallcallType (audio/video), uid, guidStart a call
apiCallurl, method, headers, bodyMake an HTTP request
customCallbackcallbackId, payloadApp-specific logic