{
  "schema_version": "1.0.0",
  "id": "weekly-kpi-digest-slack",
  "title": "Post a weekly KPI digest to Slack",
  "category": "reporting",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Every Monday, read this week's and last week's numbers from a KPI sheet and post one Slack message with arrows, percentages, and warnings.",
  "tags": [
    "kpi",
    "reporting",
    "google-sheets",
    "slack",
    "weekly"
  ],
  "apps": [
    "Schedule by Zapier",
    "Google Sheets",
    "Code by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 3 steps after the trigger"
    ]
  },
  "tasks": {
    "typical": 3,
    "max": 3
  },
  "trigger": {
    "app": "Schedule by Zapier",
    "event": "Every Week",
    "kind": "schedule",
    "title": "Every Monday at 8am",
    "why": "Runs once a week before the Monday meeting.",
    "config": {
      "Day of the Week": "Monday",
      "Time of Day": "8am",
      "Timezone": "YOUR_TIMEZONE"
    },
    "outputs": [
      "pretty_date",
      "date",
      "day_of_week",
      "week_of_year"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "kpis",
      "kind": "search",
      "app": "Google Sheets",
      "event": "Lookup Spreadsheet Row",
      "title": "Read the summary row",
      "why": "One summary row, keyed `current`, holds the metric names and both weeks as comma-joined text, so a single lookup returns everything.",
      "fields": {
        "Drive": "My Google Drive",
        "Spreadsheet": "KPIs",
        "Worksheet": "Summary",
        "Lookup Column": "key",
        "Lookup Value": "current",
        "Should this step be considered a \"success\" when nothing is found?": "Yes"
      },
      "outputs": [
        "row_number",
        "_zap_search_was_found_status",
        "metric_names",
        "this_week",
        "last_week",
        "lower_is_better",
        "week_label"
      ]
    },
    {
      "key": "digest",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Write the digest",
      "why": "Calculates week-over-week change, picks arrows and warnings (a falling refund rate is good news, so lower-is-better metrics are handled), and finds the biggest mover.",
      "code": {
        "language": "javascript",
        "module": "kpi-digest",
        "file": "code/kpi-digest.js"
      },
      "input_data": {
        "metric_names": "{{kpis.metric_names}}",
        "this_week": "{{kpis.this_week}}",
        "last_week": "{{kpis.last_week}}",
        "lower_is_better": "{{kpis.lower_is_better}}",
        "week_label": "{{kpis.week_label}}"
      },
      "outputs": [
        "slack_text",
        "biggest_mover",
        "improved_count",
        "worse_count"
      ]
    },
    {
      "key": "post",
      "kind": "action",
      "app": "Slack",
      "event": "Send Channel Message",
      "title": "Post it to the team channel",
      "why": "One message with every metric and the biggest mover at the end.",
      "fields": {
        "Channel": "#team",
        "Message Text": "{{digest.slack_text}}\n\nBiggest mover: {{digest.biggest_mover}} · better {{digest.improved_count}}, worse {{digest.worse_count}}",
        "Send as a bot?": "Yes",
        "Bot Name": "Zap alerts",
        "Include a link to this Zap?": "No"
      },
      "outputs": [
        "ts",
        "permalink"
      ]
    }
  ]
}
