Skip to content

Groups

For more details, see XMTP's Groups documentation.

Create a new group

Using the client you can create a new group with an array of addresses.

// get the client
const { client } = context;
// create a new group
const group = await client.conversations.newConversation(addresses);

Group links

You can get the group link by using the converse url and group id

https://converse.xyz/group-invite/${group.id}

Sync a group

Each time you perform an action on a group you must sync it to get the latest state.

// get the group
const { group } = context;
// sync the group
await group.sync();

Group metadata

You need admin privileges to update the metadata.

Groups have the following metadata:

Group name

You can update the name of the group chat.

// get the group
const { group } = context;
// get the name
const groupName = group.name;
// update the name
await group.updateName(name);

Group description

You can update the description of the group chat.

// get the group
const { group } = context;
// get the description
const groupDescription = group.description;
// update the description
await group.updateDescription(description);

Group image

You can update the image of the group chat.

// get the group
const { group } = context;
// get the image
const groupImage = group.imageUrl;
// update the image
await group.updateImageUrl(imageUrl);

Member management

You need admin privileges to manage members.

You can add or remove members from a group.

Remove members from a group

// get the group
const { group } = context;
//By address
await group.removeMembers(userAddresses);
//By inboxId
await group.removeMembersByInboxId(removedInboxes);

Add members to a group

// get the group
const { group } = context;
//By address
await group.addMembers(userAddresses);
//By inboxId
await group.addMembersByInboxId(addedInboxes);

Messages

To get the message history in a group you can use the messages property.

// get the group
const { group } = context;
// sync group first
await group.sync();
// get messages
const messages = group.messages();