Create conversations
Check if an identity is reachable
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).
import { Client } from "@xmtp/browser-sdk";
// response is a Map of string (identity) => boolean (is reachable)
const response = await Client.canMessage([bo.identity, caro.identity]);
Create a new group chat
Once you have the verified identities, create a new group chat:
const group = await client.conversations.newGroup(
[bo.inboxId, caro.inboxId],
createGroupOptions /* optional */
);
Create a new DM
Once you have the verified identity, get its inbox ID and create a new DM:
const group = await client.conversations.newDm(bo.inboxId);
Conversation helper methods
Use these helper methods to quickly locate and access specific conversations—whether by conversation ID, topic, group ID, or DM identity—returning the appropriate ConversationContainer, group, or DM object.
// get a conversation by its ID
const conversationById = await client.conversations.getConversationById(
conversationId
);
// get a message by its ID
const messageById = await client.conversations.getMessageById(messageId);
// get a 1:1 conversation by a peer's inbox ID
const dmByInboxId = await client.conversations.getDmByInboxId(peerInboxId);
Conversation union type
Serves as a unified structure for managing both group chats and DMs. It provides a consistent set of properties and methods to seamlessly handle various conversation types.
- React Native: Conversation.ts
Group class
Represents a group chat conversation, providing methods to manage group-specific functionalities such as sending messages, synchronizing state, and handling group membership.
- React Native: Group.ts
Dm class
Represents a DM conversation, providing methods to manage one-on-one communications, such as sending messages, synchronizing state, and handling message streams.
- React Native: Dm.ts