{
  "schema_version": "1.0.0",
  "id": "support-email-to-clickup",
  "title": "Route a support email to ClickUp",
  "category": "support",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Turn each support email into a ClickUp task with a queue, a priority, and an agent picked by a stable rotation, then DM that agent in Slack.",
  "tags": [
    "support",
    "clickup",
    "gmail",
    "routing",
    "slack"
  ],
  "apps": [
    "Gmail",
    "Code by Zapier",
    "ClickUp",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 3 steps after the trigger"
    ]
  },
  "tasks": {
    "typical": 3,
    "max": 3
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Labeled Email",
    "kind": "polling",
    "title": "New email under the Support label",
    "why": "Fires for each email under the Support label. A Gmail filter on the support@ address can apply it automatically.",
    "config": {
      "Label": "Support"
    },
    "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": "route",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Pick a queue, priority, and agent",
      "why": "Keyword rules choose billing, account, bug, sales, or general; urgent words and VIP domains raise the priority; the agent comes from a hash of the Gmail message id, so a re-run lands on the same person without Storage.",
      "code": {
        "language": "javascript",
        "module": "assign-ticket",
        "file": "code/assign-ticket.js"
      },
      "input_data": {
        "subject": "{{trigger.subject}}",
        "body": "{{trigger.body_plain}}",
        "from_email": "{{trigger.from_email}}",
        "vip_domains": "globex.example, initech.example",
        "agents": "ayesha.k, bilal.r, chen.w",
        "ticket_id": "{{trigger.message_id}}"
      },
      "outputs": [
        "queue",
        "priority",
        "assignee",
        "matched_keyword",
        "is_vip"
      ]
    },
    {
      "key": "task",
      "kind": "action",
      "app": "ClickUp",
      "event": "Create Task",
      "title": "Create the support task",
      "why": "One task per email in the Support list, tagged with the queue and the agent's handle so the board can be filtered either way.",
      "fields": {
        "Workspace": "YOUR_CLICKUP_WORKSPACE",
        "Space": "Customer Support",
        "Folder": "(none)",
        "List": "Inbox",
        "Task Name": "[{{route.queue}}] {{trigger.subject}}",
        "Content": "From: {{trigger.from_name}} <{{trigger.from_email}}>\nPriority: {{route.priority}} (matched \"{{route.matched_keyword}}\")\nOwner: {{route.assignee}}\n\n{{trigger.body_plain}}\n\nGmail: https://mail.google.com/mail/u/0/#all/{{trigger.message_id}}",
        "Priority": "{{route.priority}}",
        "Tags": "{{route.queue}}, {{route.assignee}}"
      },
      "outputs": [
        "id",
        "url"
      ]
    },
    {
      "key": "dm",
      "kind": "action",
      "app": "Slack",
      "event": "Send Direct Message",
      "title": "DM the agent",
      "why": "The person who owns it hears about it directly, with the link, instead of everyone watching the inbox.",
      "fields": {
        "To Username": "{{route.assignee}}",
        "Message Text": "New {{route.priority}} {{route.queue}} ticket for you: \"{{trigger.subject}}\" from {{trigger.from_email}}. {{task.url}}",
        "Send as a bot?": "Yes",
        "Bot Name": "Zap alerts"
      },
      "outputs": [
        "ts"
      ]
    }
  ]
}
