{
  "kind": "alaskan.workflow",
  "version": 1,
  "slug": "appointment-recall-reminders",
  "name": "Appointment recall reminders",
  "summary": "Every Monday the recall dog finds patients six months past their cleaning, writes each a short text with no treatment details, and sends them after one yes.",
  "for": "Dental and medical clinics",
  "author": {
    "name": "Alaskan Labs"
  },
  "license": "MIT",
  "dog": "juneau",
  "trigger": {
    "type": "schedule",
    "when": "mon 09:00"
  },
  "nodes": [
    {
      "id": "list",
      "type": "app",
      "title": "Read the recall list",
      "app": "googlesheets",
      "action": "GOOGLESHEETS_BATCH_GET",
      "input": {
        "ranges": [
          "Recalls!A:F"
        ]
      }
    },
    {
      "id": "due",
      "type": "think",
      "title": "Pick who's due",
      "prompt": "From the recall list, pick patients whose last cleaning was six or more months ago and who haven't been texted in the last 14 days. Leave out anyone marked do-not-text. List first name, months since their cleaning and the last four digits of their phone only."
    },
    {
      "id": "check",
      "type": "branch",
      "title": "Anyone due?"
    },
    {
      "id": "texts",
      "type": "think",
      "title": "Write the texts",
      "prompt": "Write one recall text per patient: their first name, the clinic's name ({{company}}), that they're due for a cleaning, and how to book (reply YES, or the booking link). Under 160 characters each. No treatment details."
    },
    {
      "id": "approve",
      "type": "decide",
      "kind": "send",
      "title": "Send this week's recall texts?",
      "prompt": "{{texts}}",
      "options": [
        {
          "key": "send",
          "label": "Send them all"
        },
        {
          "key": "skip",
          "label": "Not this week",
          "effect": "decline"
        }
      ]
    },
    {
      "id": "send",
      "type": "app",
      "title": "Send the texts",
      "app": "twilio",
      "action": "TWILIO_SEND_SMS",
      "write": true,
      "input": {
        "messages": "{{texts}}"
      }
    },
    {
      "id": "mark",
      "type": "app",
      "title": "Mark them texted on the recall list",
      "app": "googlesheets",
      "action": "GOOGLESHEETS_BATCH_UPDATE",
      "write": true,
      "input": {
        "column": "Last texted",
        "value": "{{today}}"
      }
    },
    {
      "id": "skipped",
      "type": "write",
      "title": "Leave the list for next week"
    },
    {
      "id": "none",
      "type": "write",
      "title": "Nobody due this week"
    }
  ],
  "edges": [
    [
      "list",
      "due"
    ],
    [
      "due",
      "check"
    ],
    [
      "check",
      "texts",
      "found"
    ],
    [
      "check",
      "none",
      "empty"
    ],
    [
      "texts",
      "approve"
    ],
    [
      "approve",
      "send",
      "send"
    ],
    [
      "send",
      "mark"
    ],
    [
      "approve",
      "skipped",
      "skip"
    ]
  ]
}
