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

# Transient Messages

> Send and receive ephemeral real-time messages that are not stored on the server using the CometChat Flutter SDK. Ideal for live reactions and temporary indicators.

<Accordion title="AI Integration Quick Reference">
  | Field           | Value                                                       |
  | --------------- | ----------------------------------------------------------- |
  | Key Classes     | `TransientMessage`                                          |
  | Key Methods     | `CometChat.sendTransientMessage()`                          |
  | Receiver Types  | `CometChatReceiverType.user`, `CometChatReceiverType.group` |
  | Listener Events | `onTransientMessageReceived`                                |
  | Prerequisites   | SDK initialized, user logged in                             |

  ```dart theme={null}
  // Send transient message (not stored on server)
  Map<String, dynamic> data = {"LIVE_REACTION": "heart"};
  TransientMessage transientMessage = TransientMessage(
    receiverId: "UID",
    receiverType: CometChatReceiverType.user,
    data: data,
  );
  CometChat.sendTransientMessage(transientMessage,
    onSuccess: () => debugPrint("Sent"),
    onError: (e) => debugPrint("Error: ${e.message}"),
  );

  // Receive transient messages
  CometChat.addMessageListener("LISTENER_ID", MessageListener(
    onTransientMessageReceived: (TransientMessage message) {
      debugPrint("Received: ${message.data}");
    },
  ));
  ```
</Accordion>

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.

<Note>
  **Available via:** SDK | UI Kits
</Note>

## 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`](/sdk/reference/auxiliary#transientmessage) class.

<Tabs>
  <Tab title="User">
    ```dart theme={null}
    String receiverId = "cometchat-uid-2";
    Map<String, dynamic> data = {};
    data["LIVE_REACTION"] = "heart";

    TransientMessage transientMessage = TransientMessage(
      receiverId: receiverId,
      receiverType: CometChatReceiverType.user,
      data: data,
    );

    CometChat.sendTransientMessage(transientMessage, onSuccess: () {
      debugPrint("Transient Message Sent");
    }, onError: (CometChatException e) {
      debugPrint("Transient message sending failed with exception: ${e.message}");
    });
    ```
  </Tab>

  <Tab title="Group">
    ```dart theme={null}
    String receiverId = "cometchat-guid-1";
    Map<String, dynamic> data = {};
    data["LIVE_REACTION"] = "heart";

    TransientMessage transientMessage = TransientMessage(
      receiverId: receiverId,
      receiverType: CometChatReceiverType.group,
      data: data,
    );

    CometChat.sendTransientMessage(transientMessage, onSuccess: () {
      debugPrint("Transient Message Sent");
    }, onError: (CometChatException e) {
      debugPrint("Transient message sending failed with exception: ${e.message}");
    });
    ```
  </Tab>
</Tabs>

`TransientMessage` Parameters:

| Parameter      | Type                   | Description                                                                              | Required |
| -------------- | ---------------------- | ---------------------------------------------------------------------------------------- | -------- |
| `receiverId`   | `String`               | The `UID` of the user or `GUID` of the group to send the transient message to            | Yes      |
| `receiverType` | `String`               | The type of the receiver — `CometChatReceiverType.user` or `CometChatReceiverType.group` | Yes      |
| `data`         | `Map<String, dynamic>` | A map to provide custom data with the transient message                                  | Yes      |
| `sender`       | `User?`                | The sender of the transient message (set automatically by the SDK)                       | No       |

<Accordion title="Error">
  | Parameter | Type     | Description                  | Sample Value                                                          |
  | --------- | -------- | ---------------------------- | --------------------------------------------------------------------- |
  | `code`    | `String` | Error code identifier        | `"ERR_CHAT_API_FAILURE"`                                              |
  | `message` | `String` | Human-readable error message | `"Failed to send the transient message."`                             |
  | `details` | `String` | Additional technical details | `"An unexpected error occurred while sending the transient message."` |
</Accordion>

## Real-time Transient Messages

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

<Warning>
  Always remove listeners when they're no longer needed (e.g., in the `dispose()` method). Failing to remove listeners can cause memory leaks and duplicate event handling.

  ```dart theme={null}
  CometChat.removeMessageListener("listenerId");
  ```
</Warning>

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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    class Class_Name  with MessageListener {

    //CometChat.addMessageListener("listenerId", this);
    @override
    void onTransientMessageReceived(TransientMessage message) {
      // TODO: implement onTransientMessageReceived
    }


    }
    ```
  </Tab>
</Tabs>

The received object is a `TransientMessage` with the following fields:

| Parameter      | Type                   | Description                                                                                                           |
| -------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `sender`       | `User?`                | An object of the `User` class holding all the information related to the sender of the transient message.             |
| `receiverId`   | `String`               | Unique ID of the receiver. This can be the `UID` of the user or `GUID` of the group the transient message is sent to. |
| `receiverType` | `String`               | The type of the receiver — `CometChatReceiverType.user` or `CometChatReceiverType.group`.                             |
| `data`         | `Map<String, dynamic>` | A map containing the custom data sent with the transient message.                                                     |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Send Messages" icon="paper-plane" href="/sdk/flutter/send-message">
    Learn how to send persistent text and media messages
  </Card>

  <Card title="Typing Indicators" icon="keyboard" href="/sdk/flutter/typing-indicators">
    Show real-time typing status to users
  </Card>
</CardGroup>
