# MessageReactions
The `MessageReactions` interface provides methods to send, delete, and subscribe to reactions on specific messages. Unlike room reactions, message reactions are persisted and associated with individual chat messages. Access it via `room.messages.reactions`.
#### Kotlin
```
val reactions = room.messages.reactions
```
Message reactions support three counting strategies:
- **Unique**: One reaction per client per message (like iMessage, WhatsApp)
- **Distinct**: One reaction of each type per client (like Slack)
- **Multiple**: Unlimited reactions including repeats (like Medium claps)
## Send a reaction to a message
`suspend reactions.send(messageSerial: String, name: String, type: MessageReactionType? = null, count: Int? = null): Unit`
Sends a reaction to a specific chat message. The reaction is persisted and contributes to the message's reaction summary.
This method uses the Ably Chat REST API and does not require the room to be attached.
### Kotlin
```
room.messages.reactions.send(
messageSerial = "message-serial-123",
name = "👍"
)
```
An extension function overload is also available that accepts a `Message` object directly:
`suspend MessageReactions.send(message: Message, name: String, type: MessageReactionType? = null, count: Int = 1): Unit`
### Kotlin
```
room.messages.reactions.send(
message = message,
name = "👍"
)
```
### Parameters
The `send()` method takes the following parameters:
### Kotlin
```
room.messages.reactions.delete(
messageSerial = "message-serial-123",
name = "👍"
)
```
An extension function overload is also available that accepts a `Message` object directly:
`suspend MessageReactions.delete(message: Message, name: String? = null, type: MessageReactionType? = null): Unit`
### Kotlin
```
room.messages.reactions.delete(message = message)
```
### Parameters
The `delete()` method takes the following parameters:
### Kotlin
```
val subscription = room.messages.reactions.subscribe { event ->
println("Message: ${event.messageSerial}")
println("Reactions: ${event.reactions}")
}
// To stop receiving reaction summaries
subscription.unsubscribe()
```
### Parameters
The `subscribe()` method takes the following parameters:
### Kotlin
```
val subscription = room.messages.reactions.subscribeRaw { event ->
when (event.type) {
MessageReactionEventType.Create ->
println("${event.reaction.clientId} reacted with ${event.reaction.name}")
MessageReactionEventType.Delete ->
println("${event.reaction.clientId} removed ${event.reaction.name}")
}
}
// To stop receiving raw events
subscription.unsubscribe()
```
### Parameters
The `subscribeRaw()` method takes the following parameters:
### Kotlin
```
// Get current user's reactions on a message
val myReactions = room.messages.reactions.clientReactions("message-serial-123")
// Get another user's reactions
val theirReactions = room.messages.reactions.clientReactions("message-serial-123", "user-456")
```
### Parameters
The `clientReactions()` method takes the following parameters:
### Kotlin
```
import kotlinx.coroutines.launch
launch {
room.messages.reactions.asFlow().collect { event ->
println("Message ${event.messageSerial} reactions updated")
}
}
```
### Returns
`Flow
### Kotlin
```
import com.ably.chat.MessageReactionType
import com.ably.chat.MessageReactionEventType
import com.ably.chat.asFlow
import kotlinx.coroutines.launch
val room = chatClient.rooms.get("my-room") {
messages {
rawMessageReactions = true
}
}
room.attach()
// Subscribe to reaction summaries
val summarySub = room.messages.reactions.subscribe { event ->
val reactions = event.reactions
// Update UI with reaction counts
for ((name, summary) in reactions.distinct) {
println("$name: ${summary.total} reactions from ${summary.clientIds.size} clients")
}
}
// Subscribe to individual reaction events for animations
val rawSub = room.messages.reactions.subscribeRaw { event ->
if (event.type == MessageReactionEventType.Create) {
println("${event.reaction.clientId} reacted with ${event.reaction.name}")
}
}
// Or use Flow for reactive collection
launch {
room.messages.reactions.asFlow().collect { event ->
println("Reactions updated for ${event.messageSerial}")
}
}
// Send a distinct reaction (Slack-style)
room.messages.reactions.send(
messageSerial = "message-serial-123",
name = "👍",
type = MessageReactionType.Distinct
)
// Send multiple reactions (Medium-style claps)
room.messages.reactions.send(
messageSerial = "message-serial-456",
name = "👏",
type = MessageReactionType.Multiple,
count = 5
)
// Remove a reaction
room.messages.reactions.delete(
messageSerial = "message-serial-123",
name = "👍"
)
// Check what reactions I've sent on a message
val myReactions = room.messages.reactions.clientReactions("message-serial-123")
println("My reactions: $myReactions")
// Clean up
summarySub.unsubscribe()
rawSub.unsubscribe()
```
## Related Topics
- [ChatClient](https://ably.com/docs/chat/api/kotlin/chat-client.md): API reference for the ChatClient interface in the Ably Chat Kotlin SDK.
- [Connection](https://ably.com/docs/chat/api/kotlin/connection.md): API reference for the Connection interface in the Ably Chat Kotlin SDK.
- [Rooms](https://ably.com/docs/chat/api/kotlin/rooms.md): API reference for the Rooms interface in the Ably Chat Kotlin SDK.
- [Room](https://ably.com/docs/chat/api/kotlin/room.md): API reference for the Room interface in the Ably Chat Kotlin SDK.
- [Messages](https://ably.com/docs/chat/api/kotlin/messages.md): API reference for the Messages interface in the Ably Chat Kotlin SDK.
- [Message](https://ably.com/docs/chat/api/kotlin/message.md): API reference for the Message interface in the Ably Chat Kotlin SDK.
- [Presence](https://ably.com/docs/chat/api/kotlin/presence.md): API reference for the Presence interface in the Ably Chat Kotlin SDK.
- [Occupancy](https://ably.com/docs/chat/api/kotlin/occupancy.md): API reference for the Occupancy interface in the Ably Chat Kotlin SDK.
- [Typing](https://ably.com/docs/chat/api/kotlin/typing.md): API reference for the Typing interface in the Ably Chat Kotlin SDK.
- [RoomReactions](https://ably.com/docs/chat/api/kotlin/room-reactions.md): API reference for the RoomReactions interface in the Ably Chat Kotlin SDK.
## Documentation Index
To discover additional Ably documentation:
1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages.
2. Identify relevant URLs from that index.
3. Fetch target pages as needed.
Avoid using assumed or outdated documentation paths.