Skip to content

Conversations and group chats

The first step to creating a conversation is to verify that participants’ identities are reachable on XMTP. The canMessage method checks each identity’s compatibility, returning a response indicating whether each identity can receive messages.

Once you have the verified identities, you can create a new conversation, whether it’s a group chat or direct message (DM).

Client.canMessage(identifiers) works without a client. An existing client also has canMessage. Browser and Node return a Map; Kotlin and Swift return a dictionary keyed by identifier.

A group chat holds up to 250 members.

Create byBrowser, NodeKotlin, Swift
Inbox IDconversations.createGroup(inboxIds, options?)conversations.newGroup(inboxIds, …)
IdentitycreateGroupWithIdentifiers(identifiers, options?)newGroupWithIdentities(identities, …)

Set the group name, description, image URL, app data, permissions, and disappearing-message settings at creation. See Groups.

Optimistic group creation enables you to prepare a group and messages before you know its members. The group stays only in the local database until you add a member. It is not visible to anyone else before that step.

PlatformMethod
Browser, Nodeconversations.createGroupOptimistic(options?)
Kotlin, Swiftconversations.newGroupOptimistic(…)

Add members, then call publishMessages() to publish prepared messages. The Node creation call is synchronous. The other calls are asynchronous.

const
const group: Group<BuiltInContentTypes>
group
= await
client: Client<BuiltInContentTypes>
client
.
Client<BuiltInContentTypes>.conversations: Conversations<BuiltInContentTypes>

Gets the conversations manager for this client

conversations
.
Conversations<BuiltInContentTypes>.createGroupOptimistic(options?: CreateGroupOptions): Promise<Group<BuiltInContentTypes>>

Creates a new group conversation without publishing to the network

@paramoptions - Optional group creation options

@returnsPromise that resolves with the new group

createGroupOptimistic
();
await
const group: Group<BuiltInContentTypes>
group
.
Group<BuiltInContentTypes>.addMembers(inboxIds: string[]): Promise<void>

Adds members to the group using inbox IDs

@paraminboxIds Array of inbox IDs to add

addMembers
([
memberInboxId: string
memberInboxId
]);

Creating a DM returns the existing conversation if you already have one with that peer. You cannot create a DM with yourself.

Create byBrowser, NodeKotlin, Swift
Inbox IDconversations.createDm(inboxId, options?)conversations.findOrCreateDm(peerInboxId, …)
IdentitycreateDmWithIdentifier(identifier, options?)findOrCreateDmWithIdentity(peerIdentity, …)

Different installations can create separate DMs for the same pair. XMTP stitches these records into one visible DM. A lookup can therefore return a different conversation ID. Do not key app state on a DM conversation ID. See DM stitching.

The Agent SDK adds createDmWithAddress, createGroupWithAddresses, and addMembersWithAddresses. getSenderAddress() resolves the first identifier for the sender and returns undefined when none exists.