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.
AI Integration Quick Reference
Field Value Key Classes TextMessage , MediaMessage , CustomMessageKey Methods sendTextMessage(), sendMediaMessage(), sendCustomMessage()Receiver Types .user, .groupMessage Types .text, .image, .video, .audio, .file, customPrerequisites SDK initialized, user logged in
CometChat supports three types of messages:
Type Method Use Case Text sendTextMessage()Plain text messages Media sendMediaMessage()Images, videos, audio, files Custom sendCustomMessage()Location, polls, or any JSON data
You can also send metadata along with a text, media or custom message. Think, for example, if you’d want to share the user’s location with every message, you can use the metadata field.
Text Message
Send a text message using CometChat.sendTextMessage() with a TextMessage object.
Swift (User)
Objective-C (User)
Swift (Group)
Objective-C (Group)
let receiverID = "cometchat-uid-2"
let text = "Hello"
let textMessage = TextMessage ( receiverUid : receiverID, text : text, receiverType : . user )
CometChat. sendTextMessage ( message : textMessage, onSuccess : { (message) in
print ( "TextMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "TextMessage sending failed with error: " + error ! . errorDescription );
}
NSString * receiverID = @"cometchat-uid-1" ;
NSString * text = @"Hello" ;
TextMessage * textMessage = [[TextMessage alloc ]initWithReceiverUid:receiverID text: text receiverType: ReceiverTypeUser];
[CometChat sendTextMessageWithMessage: textMessage onSuccess: ^ (TextMessage * message) {
NSLog ( @"TextMessage sent successfully. %@ " ,[message stringValue ]);
} onError: ^ (CometChatException * error) {
NSLog ( @"TextMessage sending failed with error: %@ " ,[error errorDescription ]);
}];
let receiverID = "cometchat-guid-102"
let text = "Hello"
let textMessage = TextMessage ( receiverUid : receiverID, text : text, receiverType : . group )
CometChat. sendTextMessage ( message : textMessage, onSuccess : { (message) in
print ( "TextMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "TextMessage sending failed with error: " + error ! . errorDescription );
}
NSString * receiverID = @"cometchat-guid-101" ;
NSString * text = @"Hello" ;
TextMessage * textMessage = [[TextMessage alloc ]initWithReceiverUid:receiverID text: text receiverType: ReceiverTypeGroup];
[CometChat sendTextMessageWithMessage: textMessage onSuccess: ^ (TextMessage * message) {
NSLog ( @"TextMessage sent successfully. %@ " ,[message stringValue ]);
} onError: ^ (CometChatException * error) {
NSLog ( @"TextMessage sending failed with error: %@ " ,[error errorDescription ]);
}];
The TextMessage class constructor takes the following parameters:
Parameter Description Required receiverIDUID of the user or GUID of the group receiving the message Yes textThe text message content Yes receiverType.user or .groupYes
On success, sendTextMessage() returns a TextMessage object containing all information about the sent message.
Send custom data along with a text message using the metaData property:
let metadata = [ "latitude" : "50.6192171633316" , "longitude" : "-72.68182268750002" ];
textMessage. metaData = metadata;
NSDictionary * metadata = @{ @"latitude" : @"50.6192171633316" , @"longitude" : @"-72.68182268750002" };
[textMessage setMetaData: metadata];
let tags = [ "pinned" ]
textMessage. tags = tags
Quote a Message
textMessage. quotedMessageId = 140
textMessage. quotedMessage = // Pass the BaseMessage object you want to quote
Send images, videos, audio, or files using CometChat.sendMediaMessage().
There are two ways to send media messages:
Upload a file — Pass a file path and CometChat uploads it automatically
Send a URL — Provide a URL to media hosted on your server or cloud storage
Upload a File
let receiverid = "cometchat-uid-2"
let mediaUrl = "file:///Library/Developer/CoreSimulator/.../image.jpg"
let mediaMessage = MediaMessage ( receiverUid : receiverid, fileurl : mediaUrl, messageType : . image , receiverType : . user )
CometChat. sendMediaMessage ( message : mediaMessage, onSuccess : { (message) in
print ( "MediaMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "MediaMessage sending failed with error: " + error. errorDescription );
}
NSString * receiverID = @"cometchat-uid-1" ;
NSString * filePath = @"Library/Developer/CoreSimulator/.../image.jpg" ;
MediaMessage * mediaMessage = [[MediaMessage alloc ]initWithReceiverUid:receiverID fileurl: filePath messageType: messageTypeImage receiverType: ReceiverTypeUser];
[CometChat sendMediaMessageWithMessage: mediaMessage onSuccess: ^ (MediaMessage * message) {
NSLog ( @"MediaMessage sent successfully. %@ " ,[message stringValue ]);
} onError: ^ (CometChatException * error) {
NSLog ( @"MediaMessage sending failed with error: %@ " ,[error errorDescription ]);
}];
Send a URL
Use the Attachment class to send media hosted on your server or cloud storage:
let receiverid = "cometchat-uid-2"
let mediaUrl = "https://pngimg.com/uploads/mario/mario_PNG125.png"
let mediaMessage = MediaMessage ( receiverUid : receiverid, fileurl : "" , messageType : . image , receiverType : . user )
mediaMessage. attachment = Attachment ( fileName : "FileName" , fileExtension : "png" , fileMimeType : "image/png" , fileUrl : mediaUrl)
CometChat. sendMediaMessage ( message : mediaMessage, onSuccess : { (message) in
print ( "MediaMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "MediaMessage sending failed with error: " + error. errorDescription );
}
The MediaMessage class constructor takes the following parameters:
Parameter Description Required receiverIDUID of the user or GUID of the group Yes fileurlFile path or empty string if using URL Yes messageType.image, .video, .audio, or .fileYes receiverType.user or .groupYes
On success, sendMediaMessage() returns a MediaMessage object.
Add Caption
mediaMessage. caption = "Message Caption"
Same as text messages:
mediaMessage. metaData = [ "location" : "Paris" ]
mediaMessage. tags = [ "vacation" ]
Starting version 3.0.906 & above, the SDK supports sending multiple attachments in a single media message.
let receiverId = "cometchat-uid-1"
let data = try ? Data ( contentsOf : URL ( string : "file:///path/to/image1.jpeg" ) ! )
let data1 = try ? Data ( contentsOf : URL ( string : "file:///path/to/image2.jpeg" ) ! )
var files = [File]()
files. append ( File ( name : "FileName 1" , data : data))
files. append ( File ( name : "FileName 2" , data : data1))
let mediaMessage = MediaMessage ( receiverUid : receiverId, files : files, messageType : . file , receiverType : . user )
CometChat. sendMediaMessage ( message : mediaMessage, onSuccess : { (message) in
print ( "Message sent successfully" )
}, onError : { (error) in
print ( "Message sending failed: " , error ? . errorDescription )
})
Custom Message
Send structured data that doesn’t fit text or media categories — like location coordinates, polls, or game moves.
Swift (User)
Swift (Group)
let receiverid = "cometchat-uid-2"
let customData: [ String : Any ] = [ "customKey" : "customData" ]
let customMessage = CustomMessage ( receiverUid : receiverid, receiverType : . user , customData : customData, type : "Custom Type" )
CometChat. sendCustomMessage ( message : customMessage, onSuccess : { (message) in
print ( "CustomMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "CustomMessage sending failed with error: " + error ! . errorDescription );
}
let receiverid = "cometchat-guid-1"
let customData: [ String : Any ] = [ "customKey" : "customData" ]
let customMessage = CustomMessage ( receiverUid : receiverid, receiverType : . group , customData : customData, type : "Custom Type" )
CometChat. sendCustomMessage ( message : customMessage, onSuccess : { (message) in
print ( "CustomMessage sent successfully. " + message. stringValue ())
}) { (error) in
print ( "CustomMessage sending failed with error: " + error ! . errorDescription );
}
The CustomMessage class constructor takes the following parameters:
Parameter Description Required receiverIDUID of the user or GUID of the group Yes receiverType.user or .groupYes customDataDictionary with your custom data Yes typeYour custom type string (e.g., "location", "poll") Yes
On success, sendCustomMessage() returns a CustomMessage object.
customMessage. tags = [ "starredMessage" ]
Control Conversation Update
By default, custom messages update the conversation’s last message. To prevent this:
customMessage. updateConversation = false
Custom Notification Text
Set custom text for push, email, and SMS notifications:
customMessage. conversationText = "Shared a location"
It is also possible to send interactive messages from CometChat. To learn more, see Interactive Messages .
Next Steps
Receive Messages Listen for incoming messages in real-time
Edit Message Edit previously sent messages
Delete Message Delete sent messages