{
  "name": "Project: HITL via Gmail",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {}
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        0
      ],
      "id": "109f7ca9-9d24-4868-8a10-36e03eb38271",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "id": "ihLzAbGLNsBemV2N",
          "name": "Gmail credentials"
        }
      }
    },
    {
      "parameters": {
        "html": "={{ $json.snippet }}",
        "options": {}
      },
      "type": "n8n-nodes-base.markdown",
      "typeVersion": 1,
      "position": [
        208,
        0
      ],
      "id": "9bf540bc-207e-4f44-9df6-39ce558eeafb",
      "name": "Markdown"
    },
    {
      "parameters": {
        "operationMode": "nodeInputBinary",
        "options": {
          "binaryDataKey": "={{ $json.data }}",
          "summarizationMethodAndPrompts": {
            "values": {
              "combineMapPrompt": "=Write a concise summary of the following in max 100 words:\n\n{{ $json.data }}\n\nDo not enter the total number of words used. ",
              "prompt": "=Write a concise summary of the following in max 100 words:\n\n{{ $json.data }}\n\nDo not enter the total number of words used. "
            }
          }
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "typeVersion": 2.1,
      "position": [
        416,
        0
      ],
      "id": "4c92d9c2-ac82-426c-a5c0-c3f6d921152f",
      "name": "Summarization Chain"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        800,
        240
      ],
      "id": "13a36fbd-74a9-48e5-b098-cd7ba212f8a0",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "xHWDVrLvQFklSodD",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Summarization Chain').item.json.output.text }}",
        "options": {
          "systemMessage": "=You are an expert at answering emails. You need to answer professionally based on the information you have. This is a business email. Be concise and never exceed 100 words. Write only the body of the email, do not create the subject.\n\nThe output must be in HTML format and you can insertonly HTML characters such as <br>, <b>, <i>, <p> where necessary and appropriate.\n\nWrite the text to reply to the email in the prompt."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        976,
        0
      ],
      "id": "f8bc7b0b-1018-42ce-8f94-626184c3b560",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "bottribe.io@gmail.com",
        "subject": "=[Approval Required]  {{ $('Gmail Trigger').item.json.Subject }}",
        "message": "=Original Email\n\n{{ $('Gmail Trigger').item.json.snippet }}\n\nAI Repply\n\n{{ $json.output }}",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        },
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1328,
        0
      ],
      "id": "58269b4a-130f-4ea8-9cd8-af88a997f7b6",
      "name": "Send message and wait for response",
      "webhookId": "2796abf5-3576-4c47-b31e-2753dbdec394",
      "credentials": {
        "gmailOAuth2": {
          "id": "ihLzAbGLNsBemV2N",
          "name": "Gmail credentials"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "0fd79ee4-a315-43e0-a86b-5c4dd18263bf",
              "leftValue": "={{ $json.data.approved }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1536,
        0
      ],
      "id": "5e41206a-030a-4397-9906-00da491be2a4",
      "name": "If"
    },
    {
      "parameters": {
        "sendTo": "={{ $('Gmail Trigger').item.json.From }}",
        "subject": "=Re:  {{ $('Gmail Trigger').item.json.Subject }}",
        "message": "={{ $('AI Agent').item.json.output }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1808,
        -112
      ],
      "id": "fc5d315a-08a8-4584-b338-a2bf7d31f6cd",
      "name": "Send a message",
      "webhookId": "7287720a-973e-4ba4-91e5-58081ca1d9b0",
      "credentials": {
        "gmailOAuth2": {
          "id": "ihLzAbGLNsBemV2N",
          "name": "Gmail credentials"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        768,
        0
      ],
      "id": "44d75653-38ee-4ad8-9946-bc814353801b",
      "name": "Edit Fields"
    }
  ],
  "pinData": {
    "Gmail Trigger": [
      {
        "json": {
          "id": "198dffcebef85293",
          "threadId": "198dffcebef85293",
          "snippet": "AI poem: Beneath the sky so vast and wide, Where dreams and whispers gently glide, A single star begins to gleam, Igniting hopes, inspiring dreams. The morning breeze, so soft and light, Carries",
          "payload": {
            "mimeType": "multipart/alternative"
          },
          "sizeEstimate": 6669,
          "historyId": "11661",
          "internalDate": "1756104513000",
          "labels": [
            {
              "id": "INBOX",
              "name": "INBOX"
            },
            {
              "id": "CATEGORY_PERSONAL",
              "name": "CATEGORY_PERSONAL"
            },
            {
              "id": "UNREAD",
              "name": "UNREAD"
            }
          ],
          "From": "Catalin Stefan <catalin.stefan83@gmail.com>",
          "Subject": "AI Poem",
          "To": "bottribe.io@gmail.com"
        }
      }
    ]
  },
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown": {
      "main": [
        [
          {
            "node": "Summarization Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Summarization Chain",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Summarization Chain": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Send message and wait for response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send message and wait for response": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5eb152de-68b1-4c68-9610-438b6818c27e",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "281c34c03b9c41f054c536eeb966e9e503918cf7f00e3bc32a5ff9cca85ca255"
  },
  "id": "w5s9nc5M8TdGg52J",
  "tags": []
}