Skip to content

Manage group chats

Group chats can have metadata like names, descriptions, and images to help users identify them. You can set metadata when creating a group chat or update it later.

Available metadata fields

  • group_name: The name of the group chat
  • description: A description of the group chat
  • image_url: A URL pointing to an image for the group chat

Get and update metadata

Node
// Get metadata
const groupName = group.name;
const groupDescription = group.description;
const groupImageUrl = group.imageUrl;
 
// Update metadata
await group.updateName('New Group Name');
await group.updateDescription('New Group Description');
await group.updateImageUrl('newurl.com');

Manage group chat membership

The maximum group chat size is 250 members.

Node
// Get inbox IDs for identities
const inboxId = await client.getInboxIdByIdentities([
  bo.identity,
  caro.identity,
]);
 
// Add/remove members
await group.addMembers([inboxId]);
await group.removeMembers([inboxId]);
 
// Get member information
await group.sync();
const members = group.members;
const addedByInboxId = group.addedByInboxId;
 
// Map inbox ID to account identity
const inboxIdIdentityMap = new Map(
  members.map((member) => [member.inboxId, member.accountIdentity])
);

Manage group chat admins

Node
// Check admin status
const isAdmin = group.isAdmin(inboxId);
const isSuperAdmin = group.isSuperAdmin(inboxId);
 
// List admins
const admins = group.admins;
const superAdmins = group.superAdmins;
 
// Add/remove admin status
await group.addAdmin(inboxId);
await group.addSuperAdmin(inboxId);
await group.removeAdmin(inboxId);
await group.removeSuperAdmin(inboxId);

Member information

Get detailed information about group members:

agent.on('text', async (ctx) => {
  const members = await group.members();
 
  for (const member of members) {
    console.log('Member inbox ID:', member.inboxId);
    console.log('Permission level:', member.permissionLevel);
    console.log('Consent state:', member.consentState);
 
    // Get Ethereum address
    const ethIdentifier = member.accountIdentifiers.find(
      (id) => id.identifierKind === IdentifierKind.Ethereum
    );
 
    if (ethIdentifier) {
      console.log('Ethereum address:', ethIdentifier.identifier);
    }
  }
});