Group updates
For more details, see XMTP's Groups documentation.
Added to a group
When a user is added to a group it will emit a new_group
event.
const {
message: { typeId, sender },
group,
} = context;
if (typeId == "new_group") {
// handle being added to a group
return;
}
Group updated object
The group_updated
type contains the following
{
initiatedByInboxId: address, // Address of the user who initiated the update
metadataFieldChanges: Record<string, string>[], // Record of metadata fields that changed
removedInboxes: string[], // Array of addresses of users removed from the group
addedInboxes: string[], // Array of addresses of users added to the group
}
Membership update
Receive a group_updated
event when a group membership changes.
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}`);
}
}
}
Removed member
When a member is removed from a group it will emit a group_updated
event with a removedInboxes
array containing the addresses of the users removed.
if (typeId === "group_updated") {
const { removedInboxes } = context.message.content;
if (removedInboxes?.length > 0) {
for (const inbox of removedInboxes) {
console.log(`User removed: ${inbox.inboxId}`);
}
}
}
Metadata update
When a group name is changed it will emit a group_updated
event with a metadataFieldChanges
array containing the new group name.
Metadata events:
group_name
: The name of the groupgroup_description
: The description of the groupgroup_image_url_square
: The square image of the group
if (typeId === "group_updated") {
const { metadataFieldChanges } = context.message.content;
if (metadataFieldChanges?.length > 0) {
for (const change of metadataFieldChanges) {
const { fieldName, oldValue, newValue } = change;
console.log(`Value ${fieldName} changed from ${oldValue} to ${newValue}`);
}
}
}