# Origamy playbook spec v1. Reference: /playbooks/spec-format/
spec_version: 1
id: church.giving-thank-you
title: Giving thank-you
sector: church
source:
  kind: synthesized
  notes: >-
    No church has sent us giving data yet, so there is no engagement to copy. Written from the
    base patterns, with an event contract the church's giving platform or finance system has to
    send. Thank-you messages never mention amounts.
derived_from: null
vocabulary:
  person: giver
  people: givers
  group: team
summary: >-
  Thanks every giver the morning after they give, never mentioning the amount, and lets a
  pastor personally thank first-time givers. A monthly report to the finance team counts
  givers, not money.
when_to_use:
  - Your giving platform or finance team can send Origamy an event for each gift (by API, a webhook relay or a CSV import).
  - You want every gift acknowledged warmly and first-time givers welcomed personally.

requires:
  data_in:
    - how: webhook
      what: "Your giving platform posts each gift to a webhook source."
    - how: sheet_sync
      what: "Or finance keeps a giving sheet synced as events (one row per gift), or uploads a CSV each week."
  channels:
    - channel: email
      for: The thank-you
      needs: A verified sending domain for {{ params.email_from }}.
  events:
    - "{{ params.gift_event }}"
  traits:
    - first_gift_at

parameters:
  - key: org_name
    ask: true
    question: What should messages call your church?
    label: Church name
    type: string
    example: Grace Community Church
  - key: gift_event
    ask: true
    question: What is the giving event called in your data? (one per gift)
    help: Its properties should include fund and method, and first_gift true on someone's first gift. The amount is never shown in messages.
    label: Gift event
    type: event_name
    default: Gift Received
  - key: pastoral_team
    ask: true
    question: Who should personally thank first-time givers?
    label: Pastoral team
    type: team_name
    default: Pastors
  - key: finance_team
    ask: true
    question: Who gets the monthly giving summary?
    label: Finance team
    type: team_name
    default: Finance
  - key: email_from
    ask: true
    question: Which address should thank-you emails come from?
    label: Sender address
    type: email
    example: thanks@yourchurch.example
  - key: thanks_delay
    label: Thank-you after the gift
    type: duration
    default: 12h
  - key: timezone
    label: Time zone for the report
    type: timezone
    default: "{{ workspace.timezone }}"
  - key: greeting_fallback
    label: Greeting when a first name is missing
    type: string
    default: friend

timings:
  - Thank-you email {{ params.thanks_delay }} after each gift, at most once a week per giver however often they give.
  - First-time givers also create a task for {{ params.pastoral_team }} to thank them personally, due in 3 days.
  - "Monthly summary on the 2nd at 09:00 ({{ params.timezone }}): the number of givers and first-time givers, no amounts."

customer_must:
  - "Send {{ params.gift_event }} for each gift with properties fund, method and first_gift (true on a first gift), identified by the giver's email or phone. Don't put amounts in traits."
  - Add people to the {{ params.pastoral_team }} and {{ params.finance_team }} teams.
  - Verify the sending domain, switch the follow-ups and report on, and test with your own gift record.

objects:
  - ref: team_pastoral
    kind: team
    about: Thanks first-time givers personally.
    body: { name: "{{ params.pastoral_team }}" }
  - ref: team_finance
    kind: team
    about: Gets the monthly giving summary.
    body: { name: "{{ params.finance_team }}" }
  - ref: tmpl_thanks
    kind: template
    about: The thank-you email (no amounts).
    body:
      name: Thank you for giving (email)
      channel: email
      category: Giving
      style: html
      status: active
      subject: "Thank you, {{ traits.first_name | default: \"{{ params.greeting_fallback }}\" }}"
      metadata: { email: { from: "{{ params.email_from }}", preview_text: "" } }
      variables: {}
      body: >-
        <p>Dear {{ traits.first_name | default: "{{ params.greeting_fallback }}" }},</p>
        <p>Thank you for your generous gift to {{ params.org_name }}. Your giving makes our
        ministry possible and blesses many lives in our church and community.</p>
        <p>With gratitude,<br>{{ params.org_name }}</p>
        <p style="font-size:12px;color:#6b6b80"><a href="{{ unsubscribe_url }}">Unsubscribe</a></p>
  - ref: q_givers
    kind: saved_question
    about: How many people gave in the period.
    body:
      name: "Report: givers"
      data_plane_id: default
      viz_type: number
      viz_settings: {}
      visibility: workspace
      query_ast:
        table: events
        filters: { operator: and, conditions: [{ field: event_name, op: eq, value: "{{ params.gift_event }}" }] }
        aggregations: [{ fn: distinct, field: canonical_user_id, alias: people }]
  - ref: q_first_givers
    kind: saved_question
    about: How many gave for the first time.
    body:
      name: "Report: first-time givers"
      data_plane_id: default
      viz_type: number
      viz_settings: {}
      visibility: workspace
      query_ast:
        table: events
        filters:
          operator: and
          conditions:
            - { field: event_name, op: eq, value: "{{ params.gift_event }}" }
            - { field: properties.first_gift, op: eq, value: true }
        aggregations: [{ fn: distinct, field: canonical_user_id, alias: people }]
  - ref: report_monthly
    kind: report
    about: Givers and first-time givers last month, compared with the month before. No amounts.
    body:
      name: "Monthly: giving summary"
      description: Number of givers and first-time givers last month. No amounts.
      schedule_cron: "0 9 2 * *"
      timezone: "{{ params.timezone }}"
      enabled: false
      spec:
        period: previous_month
        compare: previous_period
        week_start: sunday
        sections:
          - { id: givers, kind: saved_question, title: Givers, viz: number, params: { question_id: "{{ ref.q_givers.id }}" } }
          - { id: first, kind: saved_question, title: First-time givers, viz: number, params: { question_id: "{{ ref.q_first_givers.id }}" } }
          - { id: tasks, kind: tasks_summary, title: Personal thank-yous, params: {} }
      recipients: [{ type: team, id: "{{ ref.team_finance.id }}" }]
      channel_policy: { mode: email_only }
  - ref: wf_thanks
    kind: workflow
    about: The thank-you email the morning after; at most once a week per giver.
    body:
      name: "Giving: thank you"
      description: A thank-you after each gift, at most once a week per giver.
      enabled: false
      trigger_type: event
      trigger_config: { event_name: "{{ params.gift_event }}" }
      steps:
        - { id: s1, type: delay, config: { duration: "{{ params.thanks_delay }}" } }
        - { id: s2, type: action, config: { action_type: send_message, channel_config: { mode: single, single: { channel: email, template_id: "{{ ref.tmpl_thanks.id }}" } } } }
      re_entry_policy: cooldown
      re_entry_cooldown_hours: 168
      goal: {}
      exit_conditions: []
  - ref: wf_first_gift
    kind: workflow
    about: A first gift gives the pastoral team a task to thank the giver personally.
    body:
      name: "Giving: first-time giver"
      description: On someone's first gift, a pastor thanks them personally.
      enabled: false
      trigger_type: event
      trigger_config:
        event_name: "{{ params.gift_event }}"
        property_filters: [{ property: first_gift, cond_operator: eq, value: true }]
        properties: { $origamy_property_filters: true }
      steps:
        - { id: s1, type: action, config: { action_type: set_trait, traits: { first_gift_at: "{{ now }}" } } }
        - id: s2
          type: human_task
          config:
            human_task:
              title: "First-time giver: {{ traits.first_name }} {{ traits.last_name }}"
              instructions: |-
                {{ traits.first_name }} {{ traits.last_name }} gave for the first time. Please thank them personally (a call, a note or a word on Sunday).
                Don't mention the amount.
              assignee_refs: [{ type: team, id: "{{ ref.team_pastoral.id }}" }]
              strategy: round_robin
              completion_policy: first_response_wins
              outcome_options:
                - { id: thanked, label: Thanked, intent: positive }
                - { id: not_reached, label: Could not reach, intent: negative }
              due_hours: 72
              wait: false
              notify: immediate
      re_entry_policy: once
      re_entry_cooldown_hours: 24
      goal: {}
      exit_conditions: []

eval:
  name: 68_church_giving_thank_you
  mode: task
  vertical: church
  prompt: >-
    When someone gives, send them a warm thank-you the next morning, without mentioning the
    amount. If it's their first gift, ask one of the pastors to thank them personally. Send
    the finance team a monthly count of givers.
  expect_artifacts: [workflow, message_template]
  forbid_terms: [discount, cart, checkout, purchase, revenue, customers, upsell]
