Groups
MessageKit allows agents to interact inside XMTP groups. Make sure you follow the guidelines for building responsible group agents on XMTP.
Tag an agent
When a message includes a tag like @bot
, it will be received by your agent.
export const agent: Agent = {
name: "Web3 Domain Bot",
tag: "@bot",
/* Your agent definition */
};
Example:
@bot who owns vitalik.eth
Create a group
To create a group from your agent, you can use the following code:
const group = await client?.conversations.newGroup([address1, address2]);
Add members
As an admin you can add members to the group.
// get the group
const { group } = context;
await group.sync();
//By address
await group.addMembers([userAddresses]);
//By inboxId
await group.addMembersByInboxId([addedInboxes]);
Added member event
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}`);
}
}
}
Group templates
Check our templates related to groups.