# Automation recipes

These recipes use the steps that exist today: `trigger`, `delay`, `send_email`, `wait_for_event`, `condition`, `contact_update`, `add_to_segment`, `contact_delete`, plus goals and exits. They are starting points, not a substitute for your own consent and clinical review.

## Before you build

- Every automation needs one trigger.
- Every step must be reachable from the trigger.
- The graph has no loops.
- Marketing steps use a template with the right message kind.
- A contact without the required consent makes the email step fail, and the run shows why.
- A goal ends the run. An exit is terminal and has no outgoing edge.

## 1. Appointment reminder

**Goal:** the patient confirms or attends. **Exit:** the patient unsubscribes or the appointment is cancelled.

1. Trigger: `appointment.booked`.
2. Delay: `2 days`.
3. Send: appointment reminder template, kind `termin`.
4. Wait for event: `appointment.confirmed`, timeout `3 days`.
5. If confirmed, goal reached. If timeout, send one final reminder.
6. Exit: `appointment.cancelled` or `contact.unsubscribed`.

Keep the reminder on the `outgoing` route. Do not add marketing content to it.

## 2. Recall

**Goal:** the patient books the recall. **Exit:** the patient asks not to be contacted.

1. Trigger: `recall.due`.
2. Delay: `1 day`.
3. Send: recall invitation, kind `recall`.
4. Wait for event: `appointment.booked`, timeout `14 days`.
5. If no booking, send one follow-up after `7 days`.
6. Exit: `contact.unsubscribed` or `recall.declined`.

Use a reentry policy of `once` for the same recall period. A second recall cycle should be a new event, not a silent restart.

## 3. Welcome and double opt-in

**Goal:** the contact confirms. **Exit:** the contact does not confirm within the window.

1. Trigger: `contact.created`.
2. Send: double opt-in email, kind `doi`.
3. Wait for event: `contact.confirmed`, timeout `7 days`.
4. If confirmed, add to the newsletter segment and send a welcome.
5. If timeout, exit without adding to the marketing audience.

Do not send marketing before confirmation. The confirmation is the consent event, not a formality.

## 4. Onboarding a new practice

**Goal:** the first domain is verified and the first test message is sent.

1. Trigger: `workspace.created`.
2. Delay: `1 hour`.
3. Send: getting started email.
4. Wait for event: `domain.verified`, timeout `3 days`.
5. If not verified, send a DNS help email.
6. Goal: `message.sent` with a test kind.
7. Exit: `workspace.closed`.

This is a good place for a `condition` on `contact.role` so the clinical lead and the IT contact get different help.

## 5. Win-back

**Goal:** the customer sends again or books a call. **Exit:** the customer unsubscribes or is marked as churned.

1. Trigger: `customer.inactive` with `days: 60`.
2. Condition: `contact.consent.newsletter == true`.
3. Send: a short “what changed” email.
4. Delay: `7 days`.
5. Send: one case study or a direct booking link.
6. Wait for event: `message.sent` or `meeting.booked`, timeout `14 days`.
7. Exit: `contact.unsubscribed` or `customer.churned`.

Set reentry to `after_days: 90`. A win-back that restarts every week is a complaint generator.

## 6. Re-engagement after a quiet period

**Goal:** the contact opens or clicks once. **Exit:** the contact stays quiet after the final step.

1. Trigger: `contact.inactive` with `days: 120`.
2. Condition: `contact.consent.newsletter == true`.
3. Send: “Do you still want to hear from us?”
4. Wait for event: `email.opened` or `email.clicked`, timeout `10 days`.
5. If no response, send one final confirmation request.
6. Exit: no response, or `contact.unsubscribed`.

Do not treat an open as consent. It is an engagement signal. Consent remains a separate record.

## Testing a recipe

1. Use a test contact and a test domain.
2. Trigger the event manually.
3. Inspect the run at each step.
4. Confirm the goal ends the run and the exit is terminal.
5. Confirm a second event respects the reentry policy.
6. Confirm a contact without consent fails at the email step with a visible reason.

## Related

- [Automations](/automations)
- [Broadcasts](/broadcasts)
- [Consent and preference center](https://werkmail.eu/features/consent-and-preference-center)
- [Automation goals](https://werkmail.eu/features/automation-goals)
- [Recipient diagnostics](https://werkmail.eu/features/recipient-diagnostics)
