PhoenixKit.Notifications.Types (phoenix_kit v1.7.102)

Copy Markdown View Source

Registry of notification types for the per-user preferences UI.

A type is a named group of related activity actions that a user can toggle as one unit. Core types ("account", "posts", "comments") ship with PhoenixKit; external modules contribute additional types via the optional notification_types/0 callback on PhoenixKit.Module (same pattern the integrations system uses for integration_providers/0).

Shape of a type:

%{
  key: "posts",
  label: "Posts",
  description: "Likes, comments, mentions on your posts",
  actions: ["post.liked", "post.commented", "post.mentioned"],
  default: true
}

The maybe_create_from_activity/1 pipeline resolves the activity's action back to a type via type_for_action/1 and asks Prefs.user_wants?/2 whether the recipient has that type enabled.

Actions not matched by any registered type are treated as fail-open — the notification still fires. New action types can ship without a UI update while remaining visible to users.

Summary

Functions

Returns the default-enabled flag for a type key. Missing types default to true.

Look up a type by its key. Returns nil when not registered.

Full list of types — core plus module-contributed, stable order.

Resolves an action string to the key of its owning type.

Types

t()

@type t() :: %{
  key: String.t(),
  label: String.t(),
  description: String.t(),
  actions: [String.t()],
  default: boolean()
}

Functions

default_for(key)

@spec default_for(String.t()) :: boolean()

Returns the default-enabled flag for a type key. Missing types default to true.

find(key)

@spec find(String.t()) :: t() | nil

Look up a type by its key. Returns nil when not registered.

list()

@spec list() :: [t()]

Full list of types — core plus module-contributed, stable order.

type_for_action(action)

@spec type_for_action(String.t()) :: String.t() | nil

Resolves an action string to the key of its owning type.

Returns nil when no type claims the action — the caller treats that as fail-open and still delivers the notification.