{
  "schema_version": "1.0.0",
  "id": "gmail-triage-draft-reply",
  "title": "Triage Gmail and draft the reply",
  "category": "email",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Classify each new email by category and urgency, leave a draft reply in the thread, and ping Slack only when something is urgent.",
  "tags": [
    "email",
    "gmail",
    "ai-triage",
    "drafts",
    "slack"
  ],
  "apps": [
    "Gmail",
    "AI by Zapier",
    "Filter by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 4 steps after the trigger",
      "Filter by Zapier",
      "AI by Zapier"
    ]
  },
  "tasks": {
    "typical": 2,
    "max": 3
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Email",
    "kind": "polling",
    "title": "New email in the inbox",
    "why": "Fires for each new email in the inbox. Drafts are never sent, so a wrong classification costs nothing but a deleted draft.",
    "config": {
      "Label": "INBOX"
    },
    "outputs": [
      "message_id",
      "thread_id",
      "from_email",
      "from_name",
      "to",
      "subject",
      "date",
      "body_plain",
      "snippet",
      "labels",
      "attachment_count",
      "attachment_names"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "triage",
      "kind": "ai",
      "app": "AI by Zapier",
      "event": "Analyze and Return Data",
      "title": "Classify and draft",
      "why": "One AI call returns the category, the urgency, a one-line summary, and a reply draft in your voice.",
      "fields": {
        "Model": "Default (fast)",
        "Instructions": "You triage email for a small-business owner. Return: category (one of customer_question, sales_lead, invoice_or_billing, partnership, newsletter, personal, other), urgency (urgent if a customer is blocked, money is at risk, or a deadline is today; otherwise normal), summary (one sentence, under 20 words), and draft_reply (a short, friendly reply that answers what you can from the email and asks for what is missing; never promise refunds, dates, or prices that are not in the email; sign off as YOUR_NAME). For newsletters, leave draft_reply empty.",
        "Input data": "From: {{trigger.from_name}} <{{trigger.from_email}}>\nSubject: {{trigger.subject}}\n\n{{trigger.body_plain}}",
        "Output fields": "category, urgency, summary, draft_reply"
      },
      "outputs": [
        "category",
        "urgency",
        "summary",
        "draft_reply"
      ]
    },
    {
      "key": "draft",
      "kind": "action",
      "app": "Gmail",
      "event": "Create Draft Reply",
      "title": "Leave a draft in the thread",
      "why": "The draft sits in the original thread, ready to edit and send. Nothing is sent automatically.",
      "fields": {
        "Thread": "{{trigger.thread_id}}",
        "To": "{{trigger.from_email}}",
        "Body Type": "plain",
        "Body": "{{triage.draft_reply}}"
      },
      "outputs": [
        "id"
      ]
    },
    {
      "key": "urgent",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only urgent mail",
      "why": "Most email is not urgent, so most runs stop here.",
      "conditions": [
        [
          {
            "field": "{{triage.urgency}}",
            "operator": "(Text) Exactly matches",
            "value": "urgent"
          }
        ]
      ],
      "usually": false
    },
    {
      "key": "ping",
      "kind": "action",
      "app": "Slack",
      "event": "Send Channel Message",
      "title": "Ping Slack about it",
      "why": "A direct, short alert with the summary and a link to the thread.",
      "fields": {
        "Channel": "#inbox-urgent",
        "Message Text": ":rotating_light: Urgent {{triage.category}} from {{trigger.from_name}}: {{triage.summary}} A draft reply is waiting. https://mail.google.com/mail/u/0/#inbox/{{trigger.thread_id}}",
        "Send as a bot?": "Yes",
        "Bot Name": "Zap alerts",
        "Include a link to this Zap?": "No"
      },
      "outputs": [
        "ts",
        "permalink"
      ]
    }
  ]
}
