Gmail Inbox Triage
Module 06 · business · intermediate
learner.json
In n8n, copy this file and paste it onto the canvas, or use Import from File.
{
"name": "06 - Gmail Inbox Triage",
"nodes": [
{
"parameters": {
"pollTimes": { "item": [{ "mode": "everyMinute" }] },
"filters": { "readStatus": "unread" }
},
"id": "m06-gmail-trigger",
"name": "New Email",
"type": "n8n-nodes-base.gmailTrigger",
"typeVersion": 1.3,
"position": [0, 0]
},
{
"parameters": {
"httpMethod": "POST",
"path": "triage",
"responseMode": "responseNode",
"options": {}
},
"id": "m06-webhook",
"name": "Triage API",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [0, 300],
"webhookId": "course-06-triage"
},
{
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
"conditions": [
{
"id": "t1",
"leftValue": "={{ ($json.body.subject ?? '') + ($json.body.text ?? '') }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"id": "m06-valid",
"name": "Has Content?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [220, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ { error: 'send at least a subject or text' } }}",
"options": { "responseCode": 400 }
},
"id": "m06-400",
"name": "Respond Bad Input",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [440, 450]
},
{
"parameters": {
"assignments": {
"assignments": [
{ "id": "p1", "name": "message_id", "value": "={{ $json.id ?? '' }}", "type": "string" },
{ "id": "p2", "name": "from", "value": "={{ $json.From ?? $json.body?.from ?? '' }}", "type": "string" },
{ "id": "p3", "name": "subject", "value": "={{ $json.Subject ?? $json.body?.subject ?? '' }}", "type": "string" },
{ "id": "p4", "name": "text", "value": "={{ ($json.snippet ?? $json.body?.text ?? '').slice(0, 3000) }}", "type": "string" }
]
},
"options": {}
},
"id": "m06-prepare",
"name": "Prepare Email",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [440, 100]
},
{
"parameters": {
"text": "=From: {{ $json.from }}\nSubject: {{ $json.subject }}\n\n{{ $json.text }}",
"attributes": {
"attributes": [
{
"name": "category",
"description": "Exactly one of: sales (potential client, partnership, quote request), support (existing customer needs help), billing (invoices, receipts, payments), newsletter (marketing, promotions, newsletters, notifications), personal (friends, family, non-business), other",
"required": true
},
{
"name": "urgent",
"type": "boolean",
"description": "true only if the sender needs a response within 24 hours or something is broken/at risk",
"required": true
},
{
"name": "summary",
"description": "One sentence, max 20 words, saying what the sender wants",
"required": true
}
]
},
"options": {
"systemPromptTemplate": "You triage a freelancer's inbox. Extract the requested fields. Use only the allowed category values, in lowercase."
}
},
"id": "m06-classify",
"name": "Classify Email",
"type": "@n8n/n8n-nodes-langchain.informationExtractor",
"typeVersion": 1.2,
"position": [660, 100]
},
{
"parameters": {
"model": { "__rl": true, "mode": "list", "value": "gpt-5-mini", "cachedResultName": "gpt-5-mini" },
"options": {}
},
"id": "m06-model",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.3,
"position": [660, 320]
},
{
"parameters": {
"assignments": {
"assignments": [
{ "id": "r1", "name": "message_id", "value": "={{ $('Prepare Email').item.json.message_id }}", "type": "string" },
{ "id": "r2", "name": "from", "value": "={{ $('Prepare Email').item.json.from }}", "type": "string" },
{ "id": "r3", "name": "subject", "value": "={{ $('Prepare Email').item.json.subject }}", "type": "string" },
{ "id": "r4", "name": "category", "value": "={{ ['sales','support','billing','newsletter','personal'].includes($json.output.category) ? $json.output.category : 'other' }}", "type": "string" },
{ "id": "r5", "name": "urgent", "value": "={{ $json.output.urgent === true || $json.output.urgent === 'true' }}", "type": "boolean" },
{ "id": "r6", "name": "summary", "value": "={{ $json.output.summary }}", "type": "string" }
]
},
"options": {}
},
"id": "m06-result",
"name": "Triage Result",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [880, 100]
},
{
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
"conditions": [
{
"id": "a1",
"leftValue": "={{ $('Triage API').isExecuted }}",
"rightValue": "",
"operator": { "type": "boolean", "operation": "true", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"id": "m06-api",
"name": "Called via API?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [1100, 100]
},
{
"parameters": { "respondWith": "json", "responseBody": "={{ $json }}", "options": {} },
"id": "m06-respond",
"name": "Respond",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [1320, 0]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "l1",
"name": "label_ids",
"value": "={{ { sales: 'Label_SALES', support: 'Label_SUPPORT', billing: 'Label_BILLING', newsletter: 'Label_NEWSLETTER', personal: 'Label_PERSONAL', other: 'Label_OTHER' } }}",
"type": "object"
}
]
},
"includeOtherFields": true,
"options": {}
},
"id": "m06-labels",
"name": "Label Map (edit me)",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [1320, 200]
},
{
"parameters": {
"operation": "addLabels",
"messageId": "={{ $json.message_id }}",
"labelIds": "={{ [$json.label_ids[$json.category]] }}"
},
"id": "m06-apply",
"name": "Apply Label",
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [1540, 200]
},
{
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
"conditions": [
{
"id": "u1",
"leftValue": "={{ $('Label Map (edit me)').item.json.urgent }}",
"rightValue": "",
"operator": { "type": "boolean", "operation": "true", "singleValue": true }
}
],
"combinator": "and"
},
"options": {}
},
"id": "m06-urgent",
"name": "Urgent?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [1760, 200]
},
{
"parameters": {},
"id": "m06-notify",
"name": "Notify Me (Exercise 2)",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1980, 120]
}
],
"connections": {
"New Email": { "main": [[{ "node": "Prepare Email", "type": "main", "index": 0 }]] },
"Triage API": { "main": [[{ "node": "Has Content?", "type": "main", "index": 0 }]] },
"Has Content?": {
"main": [
[{ "node": "Prepare Email", "type": "main", "index": 0 }],
[{ "node": "Respond Bad Input", "type": "main", "index": 0 }]
]
},
"Prepare Email": { "main": [[{ "node": "Classify Email", "type": "main", "index": 0 }]] },
"OpenAI Chat Model": { "ai_languageModel": [[{ "node": "Classify Email", "type": "ai_languageModel", "index": 0 }]] },
"Classify Email": { "main": [[{ "node": "Triage Result", "type": "main", "index": 0 }]] },
"Triage Result": { "main": [[{ "node": "Called via API?", "type": "main", "index": 0 }]] },
"Called via API?": {
"main": [
[{ "node": "Respond", "type": "main", "index": 0 }],
[{ "node": "Label Map (edit me)", "type": "main", "index": 0 }]
]
},
"Label Map (edit me)": { "main": [[{ "node": "Apply Label", "type": "main", "index": 0 }]] },
"Apply Label": { "main": [[{ "node": "Urgent?", "type": "main", "index": 0 }]] },
"Urgent?": { "main": [[{ "node": "Notify Me (Exercise 2)", "type": "main", "index": 0 }]] }
},
"pinData": {},
"settings": { "executionOrder": "v1" }
}