- 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.
TextMessage
class. The initialize method of the TextMessage class takes the following mandatory parameters:
The TextMessage
class constructor takes the following parameters:
Parameters | Information |
---|---|
receiverID | The UID or GUID of the recipient |
text | The text to be sent |
receiverType | The type of the receiver to whom the message is to be sent i.e user or group |
TextMessage
object which includes all information related to the sent message.
Add Metadata to Text Message
To send custom data along with a text message, you can use the metadata field provided inTextMessage
. A metadata field is a dictionary
of type [String: Any]
which will be received as it was sent without any processing from CometChat. It can be used to send any additional data that needs to be sent along with a message.
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.
MediaMessage
class. The initialize method of the MediaMessage
class takes the following mandatory parameters:
Parameter | Description |
---|---|
receiverId | The UID or GUID of the recipient |
fileurl | The file path object to be sent |
messageType | The type of the message that needs to be sent which in this case can be: - image - video - audio - file |
receiverType | The type of the receiver to whom the message is to be sent - user - group |
MediaMessage
class containing all the information related to the sent media message.
Add Metadata
To send custom data along with a media message, you can use the metadata field provided inMediaMessage
. A metadata field is a dictionary
of type [String: Any]
which will be received as it was sent without any processing from CometChat. It can be used to send any additional data that needs to be sent along with a message.
Custom Message
CometChat SDK allows you to send a completely custom message across. You can use this feature to send messages that do not fit in any default categories provided. 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 two constructor:
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 group
- type - custom message type that you need to set
- customData - The data to be passed as the message in the form of a Dictionary object.
CustomMessage
class to set a specific type for the CustomeMessage.
Once the object of CustomMessage
class is ready you can send the custom message using the sendCustomMessage()
method.
CustomMessage
class.