n8n recipe · ai

Gmail → AI Agent

An AI Agent reads each new Gmail message and decides by itself: log it as a Google Sheets row, or post it to Slack.

지메일에 새 메일이 오면 AI 에이전트가 읽고, 구글 시트에 적을지 슬랙에 올릴지 스스로 정해요.

Steps

  1. When when a new email arrives in gmail — Gmail node
  2. Then decide whether to add a row to google sheets or post in slack — AI Agent node · may use: Google Sheets, Slack

Fields to fill (10)

The file has every node wired up. These are the blanks only you can fill (your form, your sheet, your words).

NodeWhat to do
OpenAI Chat Modelcheck model: OpenAI Chat Model chosen by default (most used) — swap for Gemini, Anthropic, Ollama … if you like
OpenAI Chat Modelfill model (The model)
Google Sheets toolfill documentId (Document)
Google Sheets toolfill sheetName (Sheet)
Google Sheets toolfill columns (Columns)
Google Sheets tooldecide per field: a fixed value, or let the agent fill it with {{ $fromAI('field') }}
Slack toolcheck select = 'channel' (first option; pick yours)
Slack toolfill channelId (The Slack channel to send to) — only if select = channel
Slack toolfill text (The message text to post)
Slack tooldecide per field: a fixed value, or let the agent fill it with {{ $fromAI('field') }}

Accounts to connect (4)

In n8n, pick or add a credential on each node — one of the types below.

Get the n8n file

Download gmail-agent-sheets-or-slack.json

  1. Open a new, empty workflow in n8n.
  2. Open the workflow menu (⋯) and choose Import from File — or copy the JSON below and paste it onto the canvas (Ctrl/Cmd+V).
  3. Connect the accounts, fill the fields above, run one test, then turn the workflow on.
Or copy the JSON
{
  "name": "An AI Agent reads each new Gmail message and decides by itself: log it as a Google Sheets row",
  "nodes": [
    {
      "id": "n1",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.4,
      "parameters": {
        "event": "messageReceived"
      },
      "position": [
        240,
        300
      ],
      "notes": "step: when a new email arrives in gmail"
    },
    {
      "id": "n2",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "parameters": {
        "promptType": "define",
        "text": "=Decide whether to add a row to google sheets or post in slack:\n\n{{ JSON.stringify($json) }}"
      },
      "position": [
        460,
        300
      ],
      "notes": "step: decide whether to add a row to google sheets or post in slack"
    },
    {
      "id": "n3",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "position": [
        460,
        500
      ]
    },
    {
      "id": "n4",
      "name": "Google Sheets tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "parameters": {
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        }
      },
      "position": [
        640,
        500
      ]
    },
    {
      "id": "n5",
      "name": "Slack tool",
      "type": "n8n-nodes-base.slackTool",
      "typeVersion": 2.7,
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "text": ""
      },
      "position": [
        820,
        500
      ]
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Slack tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}