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
PreferenceSetfor their tenant. - Enable your users to override that tenant default
PreferenceSetwith their own preferences. - Trigger your workflows with a
tenantparameter to apply tenant-specific preferences.
Create a per-tenant default PreferenceSet
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.
Set a per-tenant user PreferenceSet
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
PreferenceSetfor all users. - At the tenant-level when you set the default
PreferenceSetfor all users in a tenant. - At the user-level when you set a user's
PreferenceSetwithout 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
tenantwill automatically load that tenant's defaultPreferencesSet(if one exists) for all recipients of the workflow. These tenant-level defaults will override a recipient's owndefaultpreferences. - 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
PreferenceSeton the tenant AND the recipient has no per-tenant preferences set, the recipient’sdefaultidPreferenceSetwill be used. As always, the recipient'sdefaultpreferences are merged with the environment-level preference defaults.