Skip to content

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

If a message includes a tag like @ens, it will be received by your stream like any other message.

export const skills: SkillGroup[] = [
  {
    name: "Ens Domain Bot",
    tag: "@ens",
    description: "Register ENS domains.",
    skills: [
      /*Your set of skills*/
    ],
  },
];

Example:

@ens who owns vitalik.eth

Be aware that you need to add the agent to the group as a member.

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}`);
    }
  }
}

For more reliable functions visit XMTP Middleware