Manage group chats with XMTP
Secure group chats are an important part of every messaging app. Learn how to create and manage them with XMTP. Discover how XMTP can enhance your group communication experience.
Create a group chat
Initiate a new group chat with a list of specified addresses. To create a group, the recipient must have already started their client at least once on the XMTP network.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
val group = client.conversations.newGroup(listOf(walletAddress1,walletAddress2))
let group = try await client.conversations.newGroup(with: [walletAddress1, walletAddress2])
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
The maximum amount of addresses allowed is X.
List group chat conversations
Retrieve all existing group chat conversations associated with the current XMTP client. Refer to the Conversations section for more details.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
// List all group chats for the current user
val groups = client.conversations.listGroups()
List all you conversation for both group and individual conversations using includeGroups
// Use existing list() method
val conversations = client.conversations.list(includeGroups = true)
// List all group chats for the current user
let groups = try await client.conversations.groups()
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Send a message in a group chat
Send a message to an existing group chat. Refer to the Messages section for more details.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
val group = client.conversations.newGroup(listOf(walletAddress1,walletAddress2))
//Send a message
group.send("Hello, group!")
let group = try await client.conversations.newGroup(with: [walletAddress1, walletAddress2])
//Send a message
try await group.send(content: "Hello, group!")
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Manage group chat members
Here are the ways that you manage group chat members with XMTP.
List group members
Retrieve a list of wallet addresses for all members in the group chat
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
group.sync()
val members = group.memberAddresses()
try await group.sync()
let members = group.members()
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Add group members
Add new members to an existing group chat using its wallet address.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
group.addMembers(listOf(walletAddress))
try await group.addMembers(addresses: [walletAddress])
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Remove group members
Remove a member from an existing group chat using its wallet address
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
group.removeMembers(listOf(walletAddress))
try await group.removeMembers(addresses: [walletAddress])
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Listen for new messages in a group chat
Streams allow real-time monitoring of new messages in a group chat. Here's how you can set up a stream for message updates. Refer to the Streams section for more details.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
// Stream new messages in a group chat
val group = client.conversations.newGroup(listOf(walletAddress1, walletAddress2))
val messageStream = group.streamMessages()
// Collect from the Flow to receive messages
messageStream.collect { message ->
print("New message from ${message.senderAddress}: ${message.body}")
}
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Listen for group chat updates
Monitor updates in group chats, including member management activities like adding and removing members as well as the creation of new group chats.
- Kotlin
- Swift
- React Native
- Dart
- JavaScript
- React
// Stream updates for all group conversations
val groupsStream = client.conversations.streamGroups()
groupsStream.collect { group ->
println("New or updated group: ${group.id}")
}
Keep your conversation list current by streaming updates for both group and individual conversations using includeGroups
.
// Stream updates for all conversations, including individual and groups
val conversationStream = client.conversations.stream(includeGroups = true)
conversationStream.collect { conversation ->
println("New or updated conversation: ${conversation.id}")
}
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon
Code sample coming soon