- A text message, the most common and standard message type.
- A media message, for sending photos, videos and files.
- A custom message, for sending completely custom data using JSON structures.
Text Message
In other words, as a sender, how do I send a text message? To send a text message to a single user or group, you need to use thesendMessage() method and pass a TextMessage object to it.
- User
- Group
TextMessage class constructor takes the following parameters:
| Parameter | Description | |
|---|---|---|
| receiverID | UID of the user or GUID of the group receiving the message | Required |
| messageText | The text message | Required |
| receiverType | The type of the receiver- CometChatConstants.RECEIVER_TYPE_USER or CometChatConstants.RECEIVER_TYPE_GROUP | Required |
TextMessage object which includes all information related to the sent message.
Add Metadata
To send custom data along with a text message, you can use thesetMetadata method and pass a JSONObject to it.
- User
- Group
Media Message
In other words, as a sender, how do I send a media message like photos, videos & files? To send a media message to any user or group, you need to use thesendMediaMessage() method and pass a MediaMessage object to it.
Getting file Object: You can use different ionic packages for sending media messages. We demonstrate how to send images using CometChat.
- JavaScript
- User
- Group
MediaMessage class constructor takes the following parameters:
| Parameter | Description | |
|---|---|---|
| receiverId | The UID or GUID of the recipient. | Required |
| file | The file object to be sent | Required |
| messageType | The type of the message that needs to be sent which in this case can be: 1. CometChat.MESSAGE_TYPE.IMAGE 2. CometChat.MESSAGE_TYPE.VIDEO 3. CometChat.MESSAGE_TYPE.AUDIO 4. CometChat.MESSAGE_TYPE.FILE | Required |
| receiverType | The type of the receiver to whom the message is to be sent. 1. CometChat.RECEIVER_TYPE.USER 2. CometChat.RECEIVER_TYPE.GROUP | Required |
MediaMessage object which includes all information related to the sent message. If you wish to send a caption or some text along with the Media Message, you can use the caption field provided by the MediaMessage class. While sending the Media Message use the setCaption() method and at the receiver end in the MediaMessage object you can use the getCaption() method to obtain the caption shared.
Add Metadata
To send custom data along with a media message, you can use thesetMetadata method and pass a JSONObject to it.
- Metadata
Add Caption(Text along with Media Message)
To send a caption with a media message, you can usesetCaption method and pass text to it.
- Caption
Custom Message
In other words, as a sender, how do I send a custom message like location co-ordinates? CometChat allows you to send custom messages which are neither text nor media messages. In order to send a custom message, you need to use thesendCustomMessage() method.
The sendCustomMessage() methods takes an object of the CustomMessage which can be obtained using the below constructor.
- Custom Message
custom.
The parameters involved are:
receiverId- Unique id of the user or group to which the message is to be sent.receiverType- Type of the receiver i.e user or groupcustomType- custom message type that you need to setcustomData- The data to be passed as the message in the form of a JSONObject.
CustomMessage class to set a specific type for the custom message. This can be achieved using the setSubtype() method.
Once the object of CustomMessage class is ready you can send the custom message using the sendCustomMessage() method.
- JavaScript (User)
- JavaScript (Group)
CustomMessage class.