{
  "kind": "alaskan.workflow",
  "version": 1,
  "slug": "morning-inbox-triage",
  "name": "Morning inbox triage",
  "summary": "Every weekday at 7:30 the inbox dog reads what came in overnight, sorts it into archive, draft and needs-you, and asks once before archiving and sending the drafted replies.",
  "for": "Anyone whose inbox is a second job",
  "author": {
    "name": "Alaskan Labs"
  },
  "license": "MIT",
  "dog": "juneau",
  "trigger": {
    "type": "schedule",
    "when": "weekdays 07:30"
  },
  "nodes": [
    {
      "id": "read",
      "type": "app",
      "title": "Read mail since last night",
      "app": "gmail",
      "action": "GMAIL_FETCH_EMAILS",
      "input": {
        "query": "is:unread newer_than:1d",
        "max_results": 50
      }
    },
    {
      "id": "sort",
      "type": "think",
      "title": "Sort into archive, draft and needs-you",
      "prompt": "Sort these emails into three piles: archive (newsletters, receipts, notifications), draft (you can write the reply) and needs you. Draft a short reply for each email in the draft pile. List each pile with sender and subject."
    },
    {
      "id": "check",
      "type": "branch",
      "title": "Anything to act on?"
    },
    {
      "id": "ask",
      "type": "decide",
      "kind": "send",
      "title": "Archive the newsletters and send the drafted replies?",
      "prompt": "{{sort}}",
      "options": [
        {
          "key": "all",
          "label": "Archive and send the drafts"
        },
        {
          "key": "archive",
          "label": "Archive only; I'll send the replies"
        },
        {
          "key": "skip",
          "label": "Leave my inbox as it is",
          "effect": "decline"
        }
      ]
    },
    {
      "id": "archive",
      "type": "app",
      "title": "Archive the archive pile",
      "app": "gmail",
      "action": "GMAIL_ADD_LABEL_TO_EMAIL",
      "write": true,
      "input": {
        "remove_label_ids": [
          "INBOX"
        ],
        "pile": "archive"
      }
    },
    {
      "id": "send",
      "type": "app",
      "title": "Send the drafted replies",
      "app": "gmail",
      "action": "GMAIL_REPLY_TO_THREAD",
      "write": true,
      "input": {
        "drafts": "{{sort}}"
      }
    },
    {
      "id": "archive-only",
      "type": "app",
      "title": "Archive the archive pile",
      "app": "gmail",
      "action": "GMAIL_ADD_LABEL_TO_EMAIL",
      "write": true,
      "input": {
        "remove_label_ids": [
          "INBOX"
        ],
        "pile": "archive"
      }
    },
    {
      "id": "log",
      "type": "write",
      "title": "Log this morning's triage"
    },
    {
      "id": "clear",
      "type": "write",
      "title": "Inbox already clear"
    }
  ],
  "edges": [
    [
      "read",
      "sort"
    ],
    [
      "sort",
      "check"
    ],
    [
      "check",
      "ask",
      "found"
    ],
    [
      "check",
      "clear",
      "empty"
    ],
    [
      "ask",
      "archive",
      "all"
    ],
    [
      "archive",
      "send"
    ],
    [
      "send",
      "log"
    ],
    [
      "ask",
      "archive-only",
      "archive"
    ],
    [
      "archive-only",
      "log"
    ],
    [
      "ask",
      "log",
      "skip"
    ]
  ]
}
