# Origamy playbook spec v1. Reference: /playbooks/spec-format/
spec_version: 1
id: church.house-fellowship-routing
title: House fellowship routing
sector: church
source:
  kind: engagement
  date: 2026-10-31
  ref: eng-2026-10-church-a
  notes: >-
    Built for a church on 2026-10-31. A first try matched the address's City or Area against
    patterns; the church replaced it with a fixed list of areas (one radio question) so nothing
    depends on spelling, and adding a fellowship means adding one option, one team and one
    follow-up. This spec is the second design.
derived_from: null
vocabulary:
  person: member
  people: members
  group: house fellowship
summary: >-
  First-timers and new members choose the area they live in from a short list. Each area
  belongs to a house fellowship, and that fellowship's leaders get a task to invite the person.
  People outside the listed areas go to the follow-up team to place by hand.
when_to_use:
  - You run house fellowships, cell groups or small groups by area, and want every newcomer offered one near them.
  - Each fellowship has a leader or two who can take a task.
  - You already have a first-timer card or membership form (for example from the First-timer to member playbook).

requires:
  data_in:
    - how: public_form
      what: "The area question this playbook adds to your intake forms."
  channels: []
  events:
    - onboarding.submitted
  traits:
    - house_fellowship   # set from the area question

parameters:
  - key: fellowships
    ask: true
    question: What are your house fellowships, and which area does each cover?
    help: One line per fellowship. The area text is what people see on the form.
    label: Fellowships
    type: list
    item_fields:
      key: { type: string, help: "short id, e.g. north" }
      name: { type: string, help: "the fellowship's name" }
      area: { type: string, help: "what people choose on the form" }
    default:
      - { key: north, name: North, area: North of the city }
      - { key: central, name: Central, area: City centre }
      - { key: south, name: South, area: South of the city }
  - key: intake_forms
    ask: true
    question: Which forms should ask for the area? (usually the first-timer card and the membership class form)
    label: Forms that ask
    type: list
    default: [first-timer-card, membership-class]
  - key: placement_team
    ask: true
    question: Who places people who live outside the listed areas?
    label: Placement team
    type: team_name
    default: Follow-up team
  - key: invite_due_hours
    ask: true
    question: How many hours do fellowship leaders have to reach out?
    label: Hours to invite
    type: hours
    default: 72
  - key: other_label
    label: The "somewhere else" option on the form
    type: string
    default: Somewhere else
  - key: team_prefix
    label: Name prefix for fellowship teams
    type: string
    default: "Fellowship: "

timings:
  - The task is created a couple of minutes after the form, so the area is saved on the person first.
  - Fellowship leaders have {{ params.invite_due_hours }} hours; Origamy reminds them halfway and at the due time.
  - Every submission that answers the area question routes again, so someone who comes back as a new member is offered a fellowship again.

customer_must:
  - Add each fellowship's leaders to its team (Settings → Collaborators → Teams), and the placement team's people to {{ params.placement_team }}.
  - Review the area question on each form, then publish the forms. A published question can't change type; to change it later, add a new question with a new key.
  - "To add a fellowship later: add an option to the area question, create its team and group, and copy one of the fellowship follow-ups with the new area. Or run this playbook again with the new line only."
  - Switch on one follow-up per fellowship, plus the catch-all.

objects:
  - ref: team_placement
    kind: team
    about: Places people who live outside the listed areas.
    body: { name: "{{ params.placement_team }}" }
  - ref: team_fellowship
    kind: team
    for_each: params.fellowships
    about: The fellowship's leaders; they get the invitation tasks.
    body: { name: "{{ params.team_prefix }}{{ item.name }}" }
  - ref: group_fellowship
    kind: group
    for_each: params.fellowships
    about: The fellowship itself, so members can be added to it once they join.
    body:
      name: "House fellowship: {{ item.name }}"
      group_type: cell
      status: active
      description: "House fellowship for {{ item.area }}."

  - ref: fields_area
    kind: form_fields
    title: Area question on each intake form
    target: { param: intake_forms }   # a list: the same fields go on each form
    insert_after: home_address
    about: Adds "Which area do you live in?" (one choice) and a free-text area for "somewhere else" to each intake form.
    body:
      fields:
        - id: f_fellowship_area
          key: fellowship_area
          type: multiple_choice
          label: Which area do you live in?
          help: So we can connect you with a house fellowship near you.
          required: true
          maps_to: { mode: custom, key: house_fellowship, trait: true }
          options:
            - $each: params.fellowships
              $value: { value: "{{ item.key }}", label: "{{ item.area }}" }
            - { value: other, label: "{{ params.other_label }}" }
        - id: f_other_area
          key: other_area
          type: short_text
          label: Your area or city
          required: true
          maps_to: { mode: custom, key: other_area, trait: true }
          visible_if: { source: form_answer, key: fellowship_area, op: eq, value: other }

  - ref: wf_route
    kind: workflow
    for_each: params.fellowships
    about: When someone chooses this fellowship's area, its leaders get a task to invite them.
    body:
      name: "Fellowship: {{ item.name }} placement"
      description: "When a form answer picks {{ item.area }}, the {{ item.name }} fellowship gets a task to invite the person."
      enabled: false
      trigger_type: event
      trigger_config: { event_name: onboarding.submitted }
      steps:
        - { id: s1, type: filter, config: { condition: { type: form_answer, trait_key: fellowship_area, cond_operator: eq, value: "{{ item.key }}" } } }
        - { id: s2, type: delay, config: { duration: 2m } }
        - id: s3
          type: human_task
          config:
            human_task:
              title: "New in your area: {{ traits.first_name }} {{ traits.last_name }}"
              instructions: |-
                {{ traits.first_name }} {{ traits.last_name }} chose an area covered by the {{ item.name }} house fellowship.
                Phone: {{ traits.phone }}

                Please reach out, invite them to the fellowship, and add them to the House fellowship: {{ item.name }} group. Mark Contacted or Could not reach, with a short note.
              assignee_refs: [{ type: team, id: "{{ ref.team_fellowship.id }}" }]
              strategy: all
              completion_policy: first_response_wins
              outcome_options:
                - { id: contacted, label: Contacted, intent: positive }
                - { id: not_reached, label: Could not reach, intent: negative }
              due_hours: "{{ params.invite_due_hours }}"
              wait: false
              notify: immediate
      re_entry_policy: every_time
      re_entry_cooldown_hours: 0
      goal: {}
      exit_conditions: []
  - ref: wf_other
    kind: workflow
    about: People who chose "somewhere else" go to the placement team.
    body:
      name: "Fellowship: other areas, place by hand"
      description: People outside the listed areas go to the placement team to place by hand.
      enabled: false
      trigger_type: event
      trigger_config: { event_name: onboarding.submitted }
      steps:
        - { id: s1, type: filter, config: { condition: { type: form_answer, trait_key: fellowship_area, cond_operator: eq, value: other } } }
        - { id: s2, type: delay, config: { duration: 2m } }
        - id: s3
          type: human_task
          config:
            human_task:
              title: "Place in a house fellowship: {{ traits.first_name }} {{ traits.last_name }}"
              instructions: |-
                {{ traits.first_name }} {{ traits.last_name }} ({{ traits.phone }}) lives in "{{ traits.other_area | default: "an area not on our list" }}", which no house fellowship on the list covers.

                Please find the nearest fellowship (or an online one) and pass their details to its leader.
              assignee_refs: [{ type: team, id: "{{ ref.team_placement.id }}" }]
              strategy: all
              completion_policy: first_response_wins
              outcome_options:
                - { id: placed, label: Placed, intent: positive }
                - { id: no_fellowship, label: No fellowship nearby, intent: neutral }
              due_hours: "{{ params.invite_due_hours }}"
              wait: false
              notify: immediate
      re_entry_policy: every_time
      re_entry_cooldown_hours: 0
      goal: {}
      exit_conditions: []

eval:
  name: 61_church_house_fellowship_routing
  mode: task
  vertical: church
  prompt: >-
    Our house fellowships take members by location: North, Central and South. Add an area
    question to the first-timer card and the membership class form, and when someone picks an
    area, give that fellowship's leaders a task to invite them. Anyone outside those areas
    should go to the follow-up team to place by hand. How do we add a fellowship later?
  expect_artifacts: [workflow, team, form]
  forbid_terms: [discount, cart, checkout, purchase, revenue, customers]
