Docs menu

React Native SDK

Push notifications

Send push notifications for unread replies through your own push provider.

The SDK has no native code and sends no pushes. When a user has an unread reply, the Mentiora platform sends a message.missed webhook to your backend, and your backend sends the push through APNs or FCM.

Set up

  1. Enable the webhook. In Mentiora admin, enable message.missed under Integrations → Webhooks.

  2. Store device tokens by user. The webhook names a signed-in user by externalUserId (the sub of your identity token) and an anonymous user by installRef. Get installRef from Mentiora.getInstallRef(), and re-key the device token on every installRefChanged event. null means detach it.

  3. Send the push. Send an alert push, collapsed by threadId, with this data block (top-level keys beside aps on APNs, inside data on FCM):

    JSON
    { "mentiora": "1", "threadId": "<threadId from the webhook>" }
  4. Handle the tap. Pass the push data to Mentiora.handleNotificationTap(data). It opens the chat on that thread and returns true, or returns false for a push that is not Mentiora's.

Handle taps with expo-notifications

With expo-notifications:

TS
import * as Notifications from "expo-notifications";
import { Mentiora } from "@mentiora-ai/react-native-sdk";

// On iOS, a push sent straight through APNs has its keys in `trigger.payload`.
const dataOf = (n: Notifications.Notification): unknown => {
  const { content, trigger } = n.request;
  if (Mentiora.isMentioraPush(content.data)) return content.data;
  return trigger && "payload" in trigger ? trigger.payload : undefined;
};

const onTap = (response: Notifications.NotificationResponse) => {
  Notifications.clearLastNotificationResponse();
  Mentiora.handleNotificationTap(dataOf(response.notification));
};

// At the app root: a tap that launched the app, then later taps.
const launch = Notifications.getLastNotificationResponse();
if (launch) onTap(launch);
Notifications.addNotificationResponseReceivedListener(onTap);

A tap that cold-starts the app can arrive before configure() runs or <MentioraHost /> mounts. The SDK holds it until both exist.

Badge and background

Your app owns the badge. While the chat page is loaded, keep it current from unreadCountChanged. Otherwise, set it from unreadCount.total in the webhook payload when you send the push.

When the app goes to the background, or the chat is hidden, the chat page is told it is hidden and stays loaded. It is told again when it is shown.