Skip to main content

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.

// Send transient message to user
let data: [String: Any] = ["LIVE_REACTION": "heart"]
let msg = TransientMessage(receiverID: "UID", receiverType: .user, data: data)
CometChat.sendTransientMessage(message: msg)

// Listen for transient messages (CometChatMessageDelegate)
func onTransisentMessageReceived(_ message: TransientMessage) {
    print("Transient:", message.data)
}

Key Characteristics

CharacteristicDescription
Fire-and-forgetNo success/failure callbacks
NOT persistedCannot be retrieved from history
Real-time onlyReceiver must be online
No receiptsNo delivery/read receipts

Use Cases

Use CaseDescription
Live reactionsHeart, thumbs up, emoji animations
Live locationReal-time location sharing
Ephemeral indicatorsTemporary status updates
Custom real-time dataAny data that doesn’t need persistence

Send Transient Message (User)

let data: [String: Any] = ["LIVE_REACTION": "heart", "timestamp": Date().timeIntervalSince1970]
let transientMessage = TransientMessage(receiverID: "cometchat-uid-2", receiverType: .user, data: data)
CometChat.sendTransientMessage(message: transientMessage)

// Note: Fire-and-forget - no success/failure callback
// Message is NOT persisted - receiver must be online

Send Transient Message (Group)

let data: [String: Any] = ["LIVE_REACTION": "thumbsup", "timestamp": Date().timeIntervalSince1970]
let transientMessage = TransientMessage(receiverID: "cometchat-guid-1", receiverType: .group, data: data)
CometChat.sendTransientMessage(message: transientMessage)

Send Live Reaction

let data = ["LIVE_REACTION": "heart", "type": "live_reaction"]
let transientMessage = TransientMessage(receiverID: "cometchat-uid-2", receiverType: .user, data: data)
CometChat.sendTransientMessage(message: transientMessage)

Common Live Reactions

ReactionValue
Heart"heart"
Thumbs Up"thumbsup"
Thumbs Down"thumbsdown"
Laugh"laugh"
Wow"wow"
Sad"sad"
Angry"angry"

Send Live Location

let data: [String: Any] = [
    "type": "live_location",
    "latitude": 37.7749,
    "longitude": -122.4194,
    "accuracy": 10.0,
    "timestamp": Date().timeIntervalSince1970
]
let transientMessage = TransientMessage(receiverID: "cometchat-uid-2", receiverType: .user, data: data)
CometChat.sendTransientMessage(message: transientMessage)

Live Location Data Properties

PropertyTypeDescription
typeString"live_location"
latitudeDoubleLatitude coordinate
longitudeDoubleLongitude coordinate
accuracyDoubleLocation accuracy in meters
timestampDoubleUnix timestamp

Real-time Transient Message Events

To receive transient messages, implement CometChatMessageDelegate:
extension YourViewController: CometChatMessageDelegate {
    
    func onTransisentMessageReceived(_ message: TransientMessage) {
        print("Transient message received")
        print("Sender UID: \(message.sender?.uid ?? "")")
        print("Sender Name: \(message.sender?.name ?? "")")
        print("Receiver ID: \(message.receiverID)")
        print("Receiver Type: \(message.receiverType)")
        print("Data: \(message.data)")
        
        // Handle specific data types
        if let reaction = message.data["LIVE_REACTION"] as? String {
            print("Live Reaction: \(reaction)")
            // Show reaction animation
        }
        
        if let type = message.data["type"] as? String, type == "live_location" {
            let lat = message.data["latitude"] as? Double ?? 0
            let lon = message.data["longitude"] as? Double ?? 0
            print("Live Location: \(lat), \(lon)")
            // Update map marker
        }
    }
}

// Register the delegate:
CometChat.messagedelegate = self

The received object is a TransientMessage.

TransientMessage Object Properties

PropertyTypeDescription
senderUser?User who sent the transient message
receiverIDStringUID of user or GUID of group
receiverTypeReceiverType.user or .group
data[String: Any]Custom data dictionary
Transient messages are NOT persisted and cannot be retrieved later. The receiver must be online to receive them. There are no delivery/read receipts for transient messages.

Next Steps

Typing Indicators

Show real-time typing status in conversations

Send Messages

Send text, media, and custom messages