Skip to content

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).

Node
import { Client, IdentifierKind, type Identifier } from "@xmtp/node-sdk";
 
const identifiers: Identifier[] = [
  { identifier: "0xboAddress", identifierKind: IdentifierKind.Ethereum },
  { identifier: "0xcaroAddress", identifierKind: IdentifierKind.Ethereum }
];
 
// response is a Map of string (identifier) => boolean (is reachable)
const response = await Client.canMessage(identifiers);

Create a new group chat

Once you have the verified identities, create a new group chat. The maximum group chat size is 250 members.

Node
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:

Node
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.

Node
// 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);