---
url: /saas-starter/latest/guide/reference/messages.md
---

# Messages

::: tip What this page covers
Every choice of `--Persistence`, `--Auth`, `--IncludeTests` and `--Aspire`: a label says
which options a part is for. The copy in your app's `docs/` folder has only the parts for yours.
`ApiHost` stands for your app's name.
:::

The messages ApiHost handles in the background, and the handlers that handle them. A message
is sent by returning it from an endpoint or a handler (or with `IMessageBus`), stored with the
data in the same transaction, and handled from a durable queue: see
[how messages are delivered](../architecture.md#how-messages-are-delivered). One message can
have several handlers, one per feature that reacts to it.

## Handlers

| Message | Handler | Notes |
|---|---|---|
|  `AccountDeleted` | DeleteFilesOfDeletedAccountHandler | A deleted account's files (its picture, and anything else kept under users/{id}/) go with it, through DeleteStoredFiles: see there for why it's a message of its own. Published rather than returned: see DeleteStoredFiles. ([PictureCleanup.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Pictures/PictureCleanup.cs)) |
|  `AccountDeleted` | DeletePreferencesOfDeletedAccountHandler | A deleted account's preferences go with it. ([UserPreferences.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/UserPreferences.cs)) |
|  `AccountDeleted` | DeleteTodosOfDeletedAccountHandler | Deletes a user's Todos when they delete their account (AccountDeleted is published by Features/Account/DeleteAccountEndpoint.cs). Runs in the background through Wolverine's durable outbox; the changes are saved automatically (AutoApplyTransactions). Wolverine finds handlers by name: the class name must end in "Handler" (or "Consumer"). ([DeleteTodosOfDeletedAccountHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/DeleteTodosOfDeletedAccountHandler.Marten.cs)) |
|  `AccountDeleted` | LeaveOrganisationsOfDeletedAccountHandler | When a user deletes their account, they leave each of their organisations. One they were the only member of is deleted, with its data (the store publishes OrganisationDeleted for its tenant, in the same transaction). The store saves after each change, so it gets a scope (and with Marten, a session) of its own: the session Wolverine gives a handler records the message as handled when it saves, which can only happen once. Running it again after a failure is safe: memberships already removed aren't found again. ([LeaveOrganisationsOfDeletedAccountHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Organisations/LeaveOrganisationsOfDeletedAccountHandler.cs)) |
|  `AccountDeleted` | NotificationHandler | A deleted account's notifications go with it. ([NotificationHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Notifications/NotificationHandler.cs)) |
|  `DeleteAttachmentIfUnused` | DeleteAttachmentIfUnusedHandler | With organisations, the message keeps the organisation it was sent in, and Wolverine opens the session for it. ([TodoAttachmentEndpoints.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/TodoAttachmentEndpoints.Marten.cs)) |
|  `DeleteAttachmentIfUnused` | DeleteAttachmentIfUnusedHandler | With organisations, the message keeps the organisation it was sent in, and Wolverine opens the DbContext for it. ([TodoAttachmentEndpoints.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/TodoAttachmentEndpoints.Marten.cs)) |
|  `DeletePictureIfUnused` | DeletePictureIfUnusedHandler |  ([PictureCleanup.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Pictures/PictureCleanup.cs)) |
| `DeleteStoredFiles` | DeleteStoredFilesHandler |  ([DeleteStoredFiles.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Storage/DeleteStoredFiles.cs)) |
|  `DeliverWebhook` | WebhookHandler |  ([WebhookHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Integrations/Webhooks/WebhookHandler.cs)) |
|  `EmailNotification` | NotificationHandler | With a one-click unsubscribe link (the List-Unsubscribe headers mail apps show as a button) and one in the text. Only to a confirmed address. ([NotificationHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Notifications/NotificationHandler.cs)) |
|  `IncomingWebhookReceived` | IncomingWebhookHandler | Where received events are handled: replace the logging with the app's own work, switching on the source (and the event's "type" in the body). ([IncomingWebhooks.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Integrations/Webhooks/IncomingWebhooks.cs)) |
|  `OrganisationDeleted` | DeleteBillingOfDeletedOrganisationHandler | A deleted organisation's subscription is cancelled (it isn't charged again), and its billing account, usage and invoices go with it. The payment provider keeps its own records. ([BillingSetup.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Billing/BillingSetup.cs)) |
|  `OrganisationDeleted` | DeleteFilesOfDeletedOrganisationHandler | A deleted organisation's files (its logo, and anything else kept under organisations/{id}/) go with it, through DeleteStoredFiles: see there for why it's a message of its own. Published rather than returned: see DeleteStoredFiles. ([OrganisationLogoEndpoints.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Organisations/OrganisationLogoEndpoints.cs)) |
|  `OrganisationDeleted` | DeleteIntegrationsOfDeletedOrganisationHandler | An organisation's keys, webhooks and secrets go with it. ([IntegrationsSetup.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Integrations/IntegrationsSetup.cs)) |
|  `OrganisationDeleted` | DeleteTodosOfDeletedOrganisationHandler | Deletes a deleted organisation's Todos. The message is sent for that organisation's tenant, so Wolverine opens the session for it and the query only finds its Todos. ([DeleteTodosOfDeletedOrganisationHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/DeleteTodosOfDeletedOrganisationHandler.Marten.cs)) |
|  `OrganisationDeleted` | DeleteTodosOfDeletedOrganisationHandler | Deletes a deleted organisation's Todos. The message is sent for that organisation's tenant, so Wolverine pins the DbContext to it; the explicit filter on TenantId is a second guard. ([DeleteTodosOfDeletedOrganisationHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/DeleteTodosOfDeletedOrganisationHandler.Marten.cs)) |
|  `PaymentEventReceived` | PaymentEventHandler | Keeps the organisation's BillingAccount (the app's copy of its billing state) in step with the provider. It reads the subscription again rather than trusting the event's copy, so events that arrive late or out of order can't leave an old state behind. ([PaymentEventHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Billing/Payments/PaymentEventHandler.cs)) |
|  `SendEmailChangeConfirmation` | AccountEmailHandler | Sent to the new address: the email changes only when its owner opens the link. ([AccountEmails.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/Email/AccountEmails.cs)) |
|  `SendEmailConfirmation` | AccountEmailHandler | Sends the emails. Each handler creates the one-time token itself, when it runs, so no token is ever stored in the message tables. Tokens are checked by the endpoints the links lead to (ConfirmEmailEndpoint, ResetPasswordEndpoint, ConfirmEmailChangeEndpoint, AcceptInvitationEndpoint). Wolverine finds handlers by name: the class name must end in "Handler". ([AccountEmails.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/Email/AccountEmails.cs)) |
|  `SendInvitation` | AccountEmailHandler | An account an admin created, with no password yet: the link lets the person choose one. ([AccountEmails.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/Email/AccountEmails.cs)) |
|  `SendNotification` | NotificationHandler | Stores the notification and refreshes the user's open tabs; then emails it, unless they turned that category's emails off. ([NotificationHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Notifications/NotificationHandler.cs)) |
|  `SendOrganisationInvitation` | OrganisationInvitationEmailHandler | Sends an invitation email. Like the account emails (Identity/Email/AccountEmails.cs), the token is created when the email is sent, so it's never in Wolverine's message tables; only its hash is stored, on the invitation. Sending again (a new invitation to the same email) gives a new token, and the old link stops working. ([OrganisationInvitationEmailHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Organisations/OrganisationInvitationEmailHandler.cs)) |
|  `SendPasswordReset` | AccountEmailHandler | Sends the emails. Each handler creates the one-time token itself, when it runs, so no token is ever stored in the message tables. Tokens are checked by the endpoints the links lead to (ConfirmEmailEndpoint, ResetPasswordEndpoint, ConfirmEmailChangeEndpoint, AcceptInvitationEndpoint). Wolverine finds handlers by name: the class name must end in "Handler". ([AccountEmails.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/Email/AccountEmails.cs)) |
|  `SendSecurityNotice` | SecurityNoticeHandler | Wolverine finds handlers by name: the class name must end in "Handler". ([SecurityNotices.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Identity/Email/SecurityNotices.cs)) |
|  `TodoCompleted` | TodoCompletedHandler | tenantId: the organisation the Todo belongs to; Wolverine carries it on every message. ([TodoCompleted.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/TodoCompleted.cs)) |
|  `TodoCompleted` | TodoCompletedHandler | Runs asynchronously, after the endpoint that completed the Todo has returned. Local queues are durable (see Program.cs), so the message is stored by the transactional outbox in the same database transaction as the Todo change: it is never lost if the app stops, and never sent if that transaction rolls back. The returned TodoChanged is cascaded on to the browser over SignalR. Add real follow-up work here too, such as an email, a notification, or an integration call. ([TodoCompleted.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/TodoCompleted.cs)) |
|  `TodoReminderDue` | TodoReminderDueHandler | Runs when the reminder is due. Nothing happens if the Todo was completed or deleted in the meantime, the member who asked for it has left the organisation, or the organisation's plan no longer includes reminders (it was downgraded); otherwise their open tabs show the reminder. tenantId: the organisation the reminder was scheduled in; Wolverine keeps it on the message. ([RemindTodoEndpoint.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/RemindTodoEndpoint.Marten.cs)) |
|  `TodoReminderDue` | TodoReminderDueHandler | Runs when the reminder is due. Nothing happens if the Todo was completed or deleted in the meantime; otherwise the owner's open tabs show the reminder. ([RemindTodoEndpoint.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/RemindTodoEndpoint.Marten.cs)) |
|  `WebhookEventRaised` | WebhookHandler | An event: one delivery for each of the organisation's subscriptions that wants it, each sent on its own (so one slow or failing receiver doesn't hold up the others). ([WebhookHandler.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Integrations/Webhooks/WebhookHandler.cs)) |

## Sent to browsers

Pushed to the open tabs over SignalR (`/api/hub`); the client recognises each by its name.

| Name | Message | Notes |
|---|---|---|
|  `notification-added` | `NotificationAdded` | Pushed to the user's open tabs over SignalR, so the sidebar's list refreshes; the client matches on the stable "notification-added" name. ([Notification.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Notifications/Notification.cs)) |
| `todo-changed` | `TodoChanged` | Pushed to browsers over SignalR (see Realtime/AppHub.cs) whenever a Todo is created or completed, so every open tab refreshes its list. The client matches on the stable "todo-changed" name (the CloudEvents "type"), not on the .NET type name. ([TodoChanged.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/TodoChanged.cs)) |
| `todo-reminder` | `TodoReminder` | Pushed to the browser over SignalR when a reminder is due; the client matches on the stable "todo-reminder" name. ([RemindTodo.cs](https://github.com/LibreSharp/saas-starter/blob/v0.10.1/src/ApiHost/Features/Todos/RemindTodo.cs)) |
