Skip to content

Groups

Guidelines

Make sure you follow the guidelines for building responsible group bots on XMTP.

Add members to a group

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

Added member

When a member is added to a group it will emit a group_updated event with a addedInboxes array containing the addresses of the users added.

if (typeId === "group_updated") {
  const { addedInboxes } = context.message.content;
 
  if (addedInboxes?.length > 0) {
    for (const inbox of addedInboxes) {
      console.log(`User added: ${inbox.inboxId}`);
    }
  }
}