> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-v6-beta2-flutter-uikit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Transient Messages

> Send and receive real-time transient messages that are not stored or tracked using the CometChat React Native SDK.

<Info>
  **Quick Reference** — Send a transient message:

  ```javascript theme={null}
  let data = { "LIVE_REACTION": "heart" };
  let transientMessage = new CometChat.TransientMessage("RECEIVER_ID", CometChat.RECEIVER_TYPE.USER, data);
  CometChat.sendTransientMessage(transientMessage);
  ```
</Info>

<Note>
  **Available via:** [SDK](/sdk/react-native/transient-messages)
</Note>

Transient messages are messages that are sent in real-time only and are not saved or tracked anywhere. The receiver of the message will only receive the message if he is online and these messages cannot be retrieved later.

## Send a Transient Message

You can use the `sendTransientMessage()` method to send a transient message to a user or in a group. The receiver will receive this information in the `onTransientMessageReceived()` method of the `MessageListener` class. In order to send the transient message, you need to use the `TransientMessage` class.

<Tabs>
  <Tab title="To User">
    ```javascript theme={null}
    let receiverId = "UID";
    let receiverType = CometChat.RECEIVER_TYPE.USER;
    let data = { "LIVE_REACTION": "heart" };

    let transientMessage = new CometChat.TransientMessage(receiverId, receiverType, data);
    CometChat.sendTransientMessage(transientMessage);
    ```
  </Tab>

  <Tab title="To Group">
    ```javascript theme={null}
    let receiverId = "GUID";
    let receiverType = CometChat.RECEIVER_TYPE.GROUP;
    let data = { "LIVE_REACTION": "heart" };

    let transientMessage = new CometChat.TransientMessage(receiverId, receiverType, data);
    CometChat.sendTransientMessage(transientMessage);
    ```
  </Tab>

  <Tab title="TypeScript (User)">
    ```typescript theme={null}
    let receiverId: string = "UID";
    let receiverType: string = CometChat.RECEIVER_TYPE.USER;
    let data: Object = { "LIVE_REACTION": "heart" };

    let transientMessage: CometChat.TransientMessage = new CometChat.TransientMessage(receiverId, receiverType, data);
    CometChat.sendTransientMessage(transientMessage);
    ```
  </Tab>

  <Tab title="TypeScript (Group)">
    ```typescript theme={null}
    let receiverId: string = "GUID";
    let receiverType: string = CometChat.RECEIVER_TYPE.GROUP;
    let data: Object = { "LIVE_REACTION": "heart" };

    let transientMessage: CometChat.TransientMessage = new CometChat.TransientMessage(receiverId, receiverType, data);
    CometChat.sendTransientMessage(transientMessage);
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — `sendTransientMessage()` does not return a value, but the transient message object sent looks like:

  <span id="send-transient-object" style={{scrollMarginTop: '100px'}} />

  **TransientMessage Object:**

  | Parameter      | Type   | Description                  | Sample Value                               |
  | -------------- | ------ | ---------------------------- | ------------------------------------------ |
  | `receiverId`   | string | Receiver's unique identifier | `"cometchat-uid-7"`                        |
  | `receiverType` | string | Type of receiver             | `"user"`                                   |
  | `data`         | object | Custom data payload          | [See below ↓](#send-transient-data-object) |

  ***

  <span id="send-transient-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter       | Type   | Description        | Sample Value |
  | --------------- | ------ | ------------------ | ------------ |
  | `LIVE_REACTION` | string | Live reaction type | `"heart"`    |
</Accordion>

## Real-time Transient Messages

*In other words, as a recipient, how do I know when someone sends a transient message?*

You will receive the transient message in the `onTransientMessageReceived()` method of the registered `MessageListener` class.

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    let listenerId = "UNIQUE_LITENER_ID";

    CometChat.addMessageListener(
    listenerId,
    new CometChat.MessageListener({
      onTransientMessageReceived: transientMessage => {
        console.log('transient message received', transientMessage);
      },
    })
    );
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
    let listenerId: string = "UNIQUE_LITENER_ID";

    CometChat.addMessageListener(
      listenerId,
      new CometChat.MessageListener({
          onTransientMessageReceived: (transientMessage: CometChat.TransientMessage) => {
              console.log('transient message received', transientMessage);
          },
      })
    );
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Event** — `onTransientMessageReceived` returns the transient message object with sender info:

  <span id="receive-transient-object" style={{scrollMarginTop: '100px'}} />

  **TransientMessage Object:**

  | Parameter      | Type   | Description                         | Sample Value                                    |
  | -------------- | ------ | ----------------------------------- | ----------------------------------------------- |
  | `receiverId`   | string | Receiver's unique identifier        | `"cometchat-uid-7"`                             |
  | `receiverType` | string | Type of receiver                    | `"user"`                                        |
  | `data`         | object | Custom data payload                 | [See below ↓](#receive-transient-data-object)   |
  | `sender`       | object | User who sent the transient message | [See below ↓](#receive-transient-sender-object) |

  ***

  <span id="receive-transient-data-object" style={{scrollMarginTop: '100px'}} />

  **`data` Object:**

  | Parameter       | Type   | Description        | Sample Value |
  | --------------- | ------ | ------------------ | ------------ |
  | `LIVE_REACTION` | string | Live reaction type | `"heart"`    |

  ***

  <span id="receive-transient-sender-object" style={{scrollMarginTop: '100px'}} />

  **`sender` Object:**

  | Parameter       | Type    | Description                            | Sample Value                                                            |
  | --------------- | ------- | -------------------------------------- | ----------------------------------------------------------------------- |
  | `uid`           | string  | User's unique identifier               | `"cometchat-uid-6"`                                                     |
  | `name`          | string  | User's display name                    | `"Ronald Jerry"`                                                        |
  | `avatar`        | string  | URL to user's avatar                   | `"https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp"` |
  | `status`        | string  | User's online status                   | `"online"`                                                              |
  | `role`          | string  | User's role                            | `"default"`                                                             |
  | `hasBlockedMe`  | boolean | Whether user has blocked current user  | `false`                                                                 |
  | `blockedByMe`   | boolean | Whether current user blocked this user | `false`                                                                 |
  | `deactivatedAt` | number  | Deactivation timestamp (0 if active)   | `0`                                                                     |
  | `tags`          | array   | User tags                              | `[]`                                                                    |
</Accordion>

<Warning>
  **Listener Cleanup** — Always remove your message listeners when the component unmounts to prevent memory leaks and unexpected behavior. Use `CometChat.removeMessageListener("UNIQUE_LITENER_ID")` in your cleanup logic (e.g., inside a `useEffect` return function or `componentWillUnmount`).
</Warning>

The `TransientMessage` class consists of the below parameters:

| Parameter        | Information                                                                                              |
| ---------------- | -------------------------------------------------------------------------------------------------------- |
| **sender**       | An object of the User class holding all the information. related to the sender of the transient message. |
| **receiverId**   | Unique Id of the receiver. This can be the Id of the group or the user the transient message is sent to. |
| **receiverType** | The type of the receiver - `CometChat.RECEIVER_TYPE.USER` or `CometChat.RECEIVER_TYPE.GROUP`             |
| **data**         | A JSONObject to provide data.                                                                            |

<AccordionGroup>
  <Accordion title="Best Practices">
    * **Use transient messages for ephemeral interactions only** — Since transient messages are not stored, they are ideal for features like live reactions, presence pings, or real-time indicators that don't need to persist.
    * **Keep the data payload small** — Transient messages are designed for lightweight, real-time signals. Avoid sending large JSON objects in the `data` field.
    * **Use unique listener IDs** — Each screen or component that registers a `MessageListener` should use a distinct `listenerId` to avoid conflicts with other listeners.
    * **Confirm the receiver is online** — Transient messages are only delivered to online users. If guaranteed delivery is required, use a regular [message](/sdk/react-native/send-message) instead.
    * **Pair with typing indicators for richer UX** — Combine transient messages with [typing indicators](/sdk/react-native/typing-indicators) to build expressive, real-time chat experiences.
  </Accordion>

  <Accordion title="Troubleshooting">
    * **Recipient not receiving transient messages** — Verify that the recipient is online and has registered a `MessageListener` with the `onTransientMessageReceived` callback before the sender dispatches the message.
    * **Listener not firing** — Confirm that the `listenerId` used in `addMessageListener` is unique and that the listener has not been removed prematurely.
    * **Messages not arriving in groups** — Make sure you are using `CometChat.RECEIVER_TYPE.GROUP` with the correct group ID (`GUID`), not a user ID.
    * **Cannot retrieve transient messages later** — This is expected behavior. Transient messages are never stored. If you need message persistence, use [send a message](/sdk/react-native/send-message) instead.
    * **Data field appears empty on the receiver side** — Ensure you are passing a valid JSON object to the `data` parameter when constructing the `TransientMessage` instance.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Typing Indicators" icon="keyboard" href="/sdk/react-native/typing-indicators">
    Send and receive real-time typing indicators in conversations.
  </Card>

  <Card title="Send a Message" icon="paper-plane" href="/sdk/react-native/send-message">
    Send text, media, and custom messages to users and groups.
  </Card>

  <Card title="Receive Messages" icon="inbox" href="/sdk/react-native/receive-messages">
    Set up real-time and fetch-based message receiving.
  </Card>

  <Card title="Messaging Overview" icon="comments" href="/sdk/react-native/messaging-overview">
    Explore the full messaging feature set available in the SDK.
  </Card>
</CardGroup>
