> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Card Message

> Card Message — CometChat documentation.

The `CardMessage` class is used to create a card message for CometChat. It extends the `InteractiveMessage` class from CometChat.

### Constructor

| Name         | Type          | Description                                                  |
| ------------ | ------------- | ------------------------------------------------------------ |
| receiverId   | string        | The ID of the receiver                                       |
| receiverType | string        | The type of the receiver                                     |
| text         | string        | The text to be displayed on the card                         |
| cardActions  | ButtonElement | The actions to be performed when the card is interacted with |

### Class Usage

How to create an instance of the `CardMessage` class:

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    List<BaseInteractiveElement> elementEntities = new ArrayList<>();

    URLNavigationAction urlNavigationAction = new URLNavigationAction("https://www.cometchat.com/");

    ButtonElement buttonElement = new ButtonElement("idbtn", "submit", urlNavigationAction);
    buttonElement.setDisableAfterInteracted(true); // button will be disable after interacted
    buttonElement.setText("Learn more");

    elementEntities.add(buttonElement);
    // Create a new instance of CardMessage
    CardMessage cardMessage = new CardMessage(receiverId, receivertype, "Decorative Text to show on Card", elementEntities);

    cardMessage.setImageUrl("https://anyImageUrl.com"); // here you can set the Image url to the Card Message
    ```
  </Tab>
</Tabs>

### Send Card Message

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    cardMessage.setSender(CometChatUIKit.getLoggedInUser());
    cardMessage.setSentAt(System.currentTimeMillis() / 1000);
    cardMessage.setReceiver(user); //here receiver user or group object need to be set
    CometChatUIKit.sendCardMessage(cardMessage, false, new CometChat.CallbackListener<CardMessage>() {
     @Override
       public void onSuccess(CardMessage cardMessage) {

       }

      @Override
        public void onError(CometChatException e) {
               e.printStackTrace();
         }
     });
    ```
  </Tab>
</Tabs>
