How to create an instance of the FormMessage class:
Copy
// Create instance of ButtonElement for card actionslet cardAction = new ButtonElement( "1", new APIAction("https://example.com/api", "POST"), "Click Me");// Create a new instance of CardMessagelet cardMessage = new CardMessage( "receiverId", CometChat.RECEIVER_TYPE.USER, "This is a card", [cardAction]);
The setImageUrl() method allows to set the image URL for the card.
Copy
let cardMessage = new CardMessage( "receiverId", CometChat.RECEIVER_TYPE.USER, "This is a card", [cardAction]);cardMessage.setImageUrl("https://example.com/image.png");
Below is an example that showcases the creation and manipulation of an instance of CardMessage:
Copy
// Create an instance of APIActionlet apiAction = new APIAction("https://example.com/api", "POST");// Create instance of ButtonElement for card actionslet cardAction = new ButtonElement("1", apiAction, "Click Me");// Create a new instance of CardMessagelet cardMessage = new CardMessage( "receiverId", CometChat.RECEIVER_TYPE.USER, "customType", "This is a card", [cardAction]);cardMessage.setImageUrl("https://example.com/image.png");
In this example, a new instance of CardMessage is created. The text, card actions and image URL are retrieved, updated, and retrieved again. Then a new CardMessage instance is made from a JSON object, and the text is retrieved and logged.