{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "f5350dfb-7df6-4f5b-a0a3-c4262477ee8e",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        256,
        480
      ],
      "parameters": {
        "options": {
          "responseMode": "responseNodes"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "77f32376-29e1-4d45-8ef9-6526b3924781",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        480,
        480
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a customer support assistant. When a user shares a customer email or inquiry, draft a professional, helpful response. Be concise, empathetic, and accurate. Never promise features that don't exist or offer discounts unless explicitly authorized. If the inquiry is unclear, ask the user for clarification before drafting a response."
        }
      },
      "typeVersion": 3.1
    },
    {
      "id": "37c546d1-e7ab-4f8b-aa5e-e5e04de1670e",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        560,
        704
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "45dd0c5e-78ce-4538-af77-a56fea41275a",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1056,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "b57dcf1c-6baa-4241-b7e1-6ae5048ef7a9",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.data.approved }}",
              "rightValue": "true"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "04626316-5bac-4924-b65e-e521a9394d83",
      "name": "Gmail - Send Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1280,
        384
      ],
      "parameters": {
        "sendTo": "={{ $json.email || \"customer@example.com\" }}",
        "message": "={{ $(\"AI Agent\").first().json.output }}",
        "options": {},
        "subject": "Re: Your Support Request",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "a46cc0e1-8e67-4a07-ab24-585e81a231b2",
      "name": "Rejected Response",
      "type": "@n8n/n8n-nodes-langchain.chat",
      "position": [
        1280,
        576
      ],
      "parameters": {
        "message": "Response was rejected. Please provide revision feedback and resubmit.",
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "f9d0c2ec-c7bf-4bdf-9479-bb48391575f7",
      "name": "Approved Response",
      "type": "@n8n/n8n-nodes-langchain.chat",
      "position": [
        1504,
        384
      ],
      "parameters": {
        "message": "Response approved and sent to the customer.",
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "9b4ba9ab-feb1-4d09-a574-d75af19fd382",
      "name": "Human Approval",
      "type": "@n8n/n8n-nodes-langchain.chat",
      "position": [
        832,
        480
      ],
      "parameters": {
        "message": "=**Draft Response for Review**\n\n{{ $json.output }}\n\nPlease review the AI-generated response above and approve to send to the customer, or reject to revise.",
        "options": {
          "limitWaitTime": {
            "values": {
              "resumeAmount": 4
            }
          }
        },
        "operation": "sendAndWait",
        "responseType": "approval",
        "approvalOptions": {
          "values": {
            "approvalType": "double",
            "approveLabel": "Send to Customer",
            "disapproveLabel": "Revise"
          }
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5f0cca1b-e43d-44d2-820d-02931dd9f782",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        256
      ],
      "parameters": {
        "width": 560,
        "height": 720,
        "content": "## Customer Support Email Review with Chat Approval\n\n### How it works\n1. **Chat Trigger** receives a customer support scenario via the built-in chat interface.\n2. **AI Agent** drafts a professional email response using the connected LLM.\n3. **Human Approval** node presents the draft in chat with Approve/Reject buttons. The workflow pauses here.\n4. **IF node** routes based on the decision: approved drafts are sent via Gmail, rejected drafts are flagged for manual revision.\n\n### Setup\n- Connect your **LLM credentials** (e.g., OpenRouter, OpenAI) to the Chat Model node\n- Connect your **Gmail credentials** to the Gmail - Send Reply node\n- Set the Chat Trigger's Response Mode to \"Using Response Nodes\"\n- (Optional) Enable \"Limit Wait Time\" on the Human Approval node to prevent indefinite waits\n\n### Customization\n- Swap Gmail for another email provider (Outlook, SMTP)\n- Adjust the AI Agent's system prompt to match your company's tone and policies\n\n\nThis template is a learning companion to the Production AI Playbook, a  series that explores strategies, shares best practices, and provides practical examples for building reliable AI systems in n8n.  \n\n[Link to blog](https://go.n8n.io/PAP-HO-Blog)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cdc3acd8-ae03-4512-8011-4321fbd463c1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 480,
        "content": "## Draft Response"
      },
      "typeVersion": 1
    },
    {
      "id": "bead3a0f-64a5-417b-ba2a-c053ef95ee17",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 208,
        "height": 480,
        "content": "## Human Review"
      },
      "typeVersion": 1
    },
    {
      "id": "8ca1ea87-8cd3-4507-b6fb-d2b6ece0cb9a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        368
      ],
      "parameters": {
        "color": 7,
        "width": 688,
        "height": 480,
        "content": "## Route and Send"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Gmail - Send Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Rejected Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Human Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human Approval": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail - Send Reply": {
      "main": [
        [
          {
            "node": "Approved Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}