Handle user consent in group chat
With XMTP, in addition to permissions that enable members to add and remove members, user consent preferences also apply.
User consent preferences enable you to give a user the option to allow or deny contact from a group ID, inbox ID, or address.
For example, your app can check inboxId
values using the isInboxIdAllowed()
or isInboxIdDenied()
functions. Then, based on your app's design and the user's settings, your app can determine how and whether a group chat and message should be displayed for a user.
To learn more, see Spam Protection.
To learn how to allow and deny contact by address, see Universal allow/block preferences.
To learn how to keep user consent preferences synchronized, see Synchronize user consent preferences.
Allow or deny contact by wallet in group chat
// Allow
await contact.allow([walletAddress]);
// Deny
await contact.deny([walletAddress]);
Allow or deny contact by inbox ID in group chat
// Allow
await contact.allowGroup([groupId]);
// Deny
await contact.denyGroup([groupId]);
Allow or deny contact by group chat ID
// Allow group
await contact.allowGroup([groupId]);
// Deny a group
await contact.denyGroup([groupId]);
Allow or deny contact from inbox ID
Enable a user to explicitly allow or deny contact from an inbox ID.
// Allow
await client.contacts.allowInboxes([client.inboxId])
// Deny
await client.contacts.denyInboxes([client.inboxId])
Check consent for group chat ID
Check if contact from a group chat ID is allowed or denied for a user.
// Check if contact by a group is allowed for a member
const isAllowed = await group.isGroupAllowed(groupId);
// Check if contact by a group is denied for a member
const isDenied = await group.isGroupDenied(groupId);
Check consent for inbox ID
Check if contact from an inbox ID is allowed or denied for a user.
await client.contacts.isInboxAllowed(client.inboxId)