Tenant preferences
You can use tenant preferences to enable your customers' admins to create a tenant-specific default PreferencesSet
for users in their tenant.
If you're a B2B application or a multi-tenant SaaS product, you can use tenant preferences to allow your customers to set default preferences for their users. For example, in Slack, your notification preferences are set per Slack workspace (that is, per-tenant), not as global preferences that apply across all of your Slack workspaces.
Overview
Here is how tenant preferences work and the steps you'll take to implement them:
- Enable your tenant admins to create a default
PreferenceSet
for their tenant. - Enable your users to override that tenant default
PreferenceSet
with their own preferences. - Trigger your workflows with a
tenant
parameter to apply tenant-specific preferences.
PreferenceSet
Create a per-tenant default You set the default PreferenceSet
for a tenant via the API by calling the tenants.set
method. The preferences should follow the format of a recipient PreferenceSet
.
PreferenceSet
Set a per-tenant user A PreferenceSet
has an id
. When you set a given user's preferences in Knock, you'll use the default
ID to apply the preferences universally for the user. When using one of our SDKs, the default
preference set is used if you don't provide an id
.
- At the environment-level when you set your default
PreferenceSet
for all users. - At the tenant-level when you set the default
PreferenceSet
for all users in a tenant. - At the user-level when you set a user's
PreferenceSet
without providing a tenant ID.
You can also get a user's tenant-specific preferences.
Trigger per-tenant workflows
When you trigger a workflow run, you pass a tenant
parameter to tell Knock which tenant in your application the workflow is executing for.
The Knock workflow engine uses that tenant
parameter to evaluate the user's PreferenceSet
. If the user has a tenant-specific preference set, Knock uses that to determine whether to send the notification. If the user does not have a tenant
-specific preference set, Knock uses the tenant's default preference set.
Tenant preference evaluation rules
Here are a few things to keep in mind when using tenant preferences.
- When executing a workflow trigger, passing in a
tenant
will automatically load that tenant's defaultPreferencesSet
(if one exists) for all recipients of the workflow. These tenant-level defaults will override a recipient's owndefault
preferences. - If the recipient has any per-tenant preferences set for that
tenant.id
, they will override the tenant-level default preferences. - If there is no default
PreferenceSet
on the tenant AND the recipient has no per-tenant preferences set, the recipient’sdefault
idPreferenceSet
will be used. As always, the recipient'sdefault
preferences are merged with the environment-level preference defaults.