{
    "name": "Beeznez starter: inbound email triage with human approval",
    "nodes": [
        {
            "parameters": {
                "content": "## Inbound email triage\n**Untested starter** from Beeznez Tech. Not run in production.\n\n1. Open the IMAP node and add your mailbox credentials.\n2. In both AI nodes set the API key and the model name. Any OpenAI-compatible endpoint works, including a local Ollama at http://localhost:11434/v1/chat/completions.\n3. In the email nodes add SMTP credentials and your addresses.\n4. Paste your own knowledge snippets into the draft-reply node.\n5. Test with a few real emails before you activate it.\n\nKeep a person in the loop before anything reaches a customer.",
                "height": 320,
                "width": 380
            },
            "id": "eec02b1e-6bd3-4b90-8e59-dcd5164c9be7",
            "name": "READ ME",
            "type": "n8n-nodes-base.stickyNote",
            "typeVersion": 1,
            "position": [
                -420,
                -40
            ]
        },
        {
            "parameters": {
                "mailbox": "INBOX",
                "postProcessAction": "nothing",
                "options": []
            },
            "id": "da22645f-692e-42e2-b435-2ff43176c579",
            "name": "Email Trigger (IMAP)",
            "type": "n8n-nodes-base.emailReadImap",
            "typeVersion": 2,
            "position": [
                -20,
                200
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "https://api.openai.com/v1/chat/completions",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Authorization",
                            "value": "Bearer YOUR_API_KEY"
                        },
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={{ JSON.stringify({ model: \"YOUR_MODEL\", temperature: 0, messages: [ { role: \"system\", content: \"You are a support triage assistant for YOUR COMPANY. Read the email and return JSON only, with these keys: category (billing, bug, how-to, sales, spam or other), urgency (low, normal or high), summary (at most 25 words), needs_human (true or false). Set needs_human to true if the email mentions legal action, a refund above 100, account deletion, a safety issue, or anything you are unsure about. Do not invent facts about our product.\" }, { role: \"user\", content: \"Email:\\n\" + $json.textPlain } ] }) }}",
                "options": {
                    "timeout": 60000
                }
            },
            "id": "5c29a913-3fbd-4aa8-9d0a-afd2f8c8ded1",
            "name": "AI: triage",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 4.2,
            "position": [
                200,
                200
            ]
        },
        {
            "parameters": {
                "jsCode": "const raw = ($json.choices && $json.choices[0] && $json.choices[0].message && $json.choices[0].message.content) || '';\nconst mail = $('Email Trigger (IMAP)').item.json;\nlet parsed;\ntry {\n  parsed = JSON.parse(raw.replace(/```json|```/g, '').trim());\n} catch (e) {\n  parsed = { category: 'other', urgency: 'normal', summary: 'The model reply could not be read, so a person should check this email.', needs_human: true };\n}\nreturn { json: {\n  category: parsed.category || 'other',\n  urgency: parsed.urgency || 'normal',\n  summary: parsed.summary || '',\n  needs_human: parsed.needs_human !== false,\n  from: mail.from,\n  subject: mail.subject,\n  body: mail.textPlain || ''\n} };",
                "mode": "runOnceForEachItem"
            },
            "id": "a8b8b8d8-a048-442e-aeed-737f4b79c1d6",
            "name": "Parse triage JSON",
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                420,
                200
            ]
        },
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": true,
                        "leftValue": "",
                        "typeValidation": "strict",
                        "version": 2
                    },
                    "conditions": [
                        {
                            "id": "6148a865-bdcc-4400-a7fc-6bb0459d8fc9",
                            "leftValue": "={{ $json.needs_human }}",
                            "rightValue": "",
                            "operator": {
                                "type": "boolean",
                                "operation": "true",
                                "singleValue": true
                            }
                        }
                    ],
                    "combinator": "and"
                },
                "options": []
            },
            "id": "783298e4-b1ca-43bf-9a06-a1ada3c4c550",
            "name": "Needs a human?",
            "type": "n8n-nodes-base.if",
            "typeVersion": 2,
            "position": [
                640,
                200
            ]
        },
        {
            "parameters": {
                "fromEmail": "you@example.com",
                "toEmail": "team@example.com",
                "subject": "=[NEEDS A PERSON] {{ $json.subject }}",
                "emailFormat": "text",
                "text": "=From: {{ $json.from }}\nCategory: {{ $json.category }}\nUrgency: {{ $json.urgency }}\nSummary: {{ $json.summary }}\n\nOriginal message:\n{{ $json.body }}",
                "options": []
            },
            "id": "55ea4b97-bfd8-4530-9bd3-5bfb670d1d20",
            "name": "Notify team: needs a person",
            "type": "n8n-nodes-base.emailSend",
            "typeVersion": 2.1,
            "position": [
                880,
                100
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "https://api.openai.com/v1/chat/completions",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Authorization",
                            "value": "Bearer YOUR_API_KEY"
                        },
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={{ JSON.stringify({ model: \"YOUR_MODEL\", temperature: 0, messages: [ { role: \"system\", content: \"Draft a reply to the customer message below. A person will review it before it is sent. Tone: friendly and direct. Use only facts from the knowledge snippets. If the answer is not in them, write NEEDS ANSWER: followed by the question for the team instead of guessing. Keep it under 120 words.\" }, { role: \"user\", content: \"Customer message:\\n\" + $(\"Parse triage JSON\").item.json.body + \"\\n\\nKnowledge snippets:\\nPASTE YOUR KNOWLEDGE SNIPPETS HERE\" } ] }) }}",
                "options": {
                    "timeout": 60000
                }
            },
            "id": "ba5b2f75-75f1-4f4a-af06-e6d76895ef42",
            "name": "AI: draft reply",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 4.2,
            "position": [
                880,
                320
            ]
        },
        {
            "parameters": {
                "fromEmail": "you@example.com",
                "toEmail": "team@example.com",
                "subject": "=[DRAFT, NOT SENT] Re: {{ $(\"Parse triage JSON\").item.json.subject }}",
                "emailFormat": "text",
                "text": "=Draft reply for a person to approve or edit. Nothing has been sent to the customer.\n\n{{ $json.choices[0].message.content }}\n\n---\nOriginal message from {{ $(\"Parse triage JSON\").item.json.from }}:\n{{ $(\"Parse triage JSON\").item.json.body }}",
                "options": []
            },
            "id": "5dde7a8c-0a5b-4f29-a6c1-5ebb758e49bf",
            "name": "Send draft to team for approval",
            "type": "n8n-nodes-base.emailSend",
            "typeVersion": 2.1,
            "position": [
                1100,
                320
            ]
        }
    ],
    "connections": {
        "Email Trigger (IMAP)": {
            "main": [
                [
                    {
                        "node": "AI: triage",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "AI: triage": {
            "main": [
                [
                    {
                        "node": "Parse triage JSON",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Parse triage JSON": {
            "main": [
                [
                    {
                        "node": "Needs a human?",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Needs a human?": {
            "main": [
                [
                    {
                        "node": "Notify team: needs a person",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "AI: draft reply",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "AI: draft reply": {
            "main": [
                [
                    {
                        "node": "Send draft to team for approval",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "active": false,
    "settings": {
        "executionOrder": "v1"
    },
    "tags": []
}