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.
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.
Platform
Method
Browser, Node
conversations.createGroupOptimistic(options?)
Kotlin, Swift
conversations.newGroupOptimistic(…)
Add members, then call publishMessages() to publish prepared messages. The Node creation call is synchronous. The other calls are asynchronous.
Creating a DM returns the existing conversation if you already have one with that peer. You cannot create a DM with yourself.
Create by
Browser, Node
Kotlin, Swift
Inbox ID
conversations.createDm(inboxId, options?)
conversations.findOrCreateDm(peerInboxId, …)
Identity
createDmWithIdentifier(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.