{
  "kind": "alaskan.workflow",
  "version": 1,
  "slug": "invoice-chase",
  "name": "Invoice chase",
  "summary": "Twice a week the finance dog finds overdue invoices, drafts a friendly reminder for each (firmer past 30 days) and sends them once you say so.",
  "for": "Any business that sends invoices",
  "author": {
    "name": "Alaskan Labs"
  },
  "license": "MIT",
  "dog": "denali",
  "trigger": {
    "type": "schedule",
    "when": "mon,thu 09:00"
  },
  "nodes": [
    {
      "id": "overdue",
      "type": "app",
      "title": "Find overdue invoices",
      "app": "quickbooks",
      "action": "QUICKBOOKS_QUERY_INVOICES",
      "input": {
        "status": "overdue"
      }
    },
    {
      "id": "check",
      "type": "branch",
      "title": "Anything overdue?"
    },
    {
      "id": "draft",
      "type": "think",
      "title": "Draft the reminders",
      "prompt": "For each overdue invoice, write a short, friendly reminder: invoice number, amount, due date, the pay link if there is one, and an offer to help if something's wrong. Firmer for anything more than 30 days late. List them, one per customer."
    },
    {
      "id": "approve",
      "type": "decide",
      "kind": "send",
      "title": "Send these payment reminders?",
      "prompt": "{{draft}}",
      "options": [
        {
          "key": "send",
          "label": "Send all of them"
        },
        {
          "key": "under30",
          "label": "Only the ones under 30 days late"
        },
        {
          "key": "skip",
          "label": "Not now",
          "effect": "decline"
        }
      ]
    },
    {
      "id": "send",
      "type": "app",
      "title": "Send the reminders",
      "app": "gmail",
      "action": "GMAIL_SEND_EMAIL",
      "write": true,
      "input": {
        "reminders": "{{draft}}"
      }
    },
    {
      "id": "send-some",
      "type": "app",
      "title": "Send the reminders under 30 days late",
      "app": "gmail",
      "action": "GMAIL_SEND_EMAIL",
      "write": true,
      "input": {
        "reminders": "{{draft}}",
        "only": "under 30 days late"
      }
    },
    {
      "id": "log",
      "type": "write",
      "title": "Note who was chased"
    },
    {
      "id": "none",
      "type": "write",
      "title": "Nothing overdue"
    }
  ],
  "edges": [
    [
      "overdue",
      "check"
    ],
    [
      "check",
      "draft",
      "found"
    ],
    [
      "check",
      "none",
      "empty"
    ],
    [
      "draft",
      "approve"
    ],
    [
      "approve",
      "send",
      "send"
    ],
    [
      "approve",
      "send-some",
      "under30"
    ],
    [
      "approve",
      "log",
      "skip"
    ],
    [
      "send",
      "log"
    ],
    [
      "send-some",
      "log"
    ]
  ]
}
