AIによる自動Gmail請求書検出とSlack通知

中級

これは自動化ワークフローで、12個のノードを含みます。主にIf, Gmail, Slack, Agent, ScheduleTriggerなどのノードを使用。 Gmail から請求書データを抽出し、GPT-4o を使用して Slack 通知を送信します

前提条件
  • Googleアカウント + Gmail API認証情報
  • Slack Bot Token または Webhook URL
  • OpenAI API Key

カテゴリー

-
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "name": "AI Auto-Detect Invoices from Gmail and Notify on Slack",
  "nodes": [
    {
      "id": "df47f544-18a9-4eea-a02f-6e8618bdc903",
      "name": "スケジュールトリガー",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1488,
        -16
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fb69e703-7747-4862-8208-0d0803f5ce8f",
      "name": "AIエージェント",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueRegularOutput",
      "position": [
        -1040,
        -16
      ],
      "parameters": {
        "text": "=You are an intelligent assistant that reads emails and determines whether the message is related to an invoice or a payment notification.\n\nYour tasks:\n1. Determine if the email is invoice-related.\n2. If yes, extract:\n   - Due date (in YYYY-MM-DD format, or null)\n   - Amount due (as a number, no currency symbols)\n\nAlways include these metadata values:\nId: {{ $json.id }}\nthreadId: {{ $json.threadId }}\nbody: {{ $json.text }}\nsubject: {{ $json.subject }}\nsender: {{ $json.from.value[0].name }}\n\nReturn only a valid JSON object in the format below:\n\n```json\n{\n  \"is_invoice\": true or false,\n  \"due_date\": \"YYYY-MM-DD\" or null,\n  \"amount_due\": number or null,\n  \"email_id\": \"string\",\n  \"thread_id\": \"string\",\n  \"sender\": \"string\",\n  \"subject\": \"string\"\n}\n\n\n",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "ff1adb6a-43d6-4b36-9c91-0046b0146565",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1024,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "acc58349-b51f-4623-9a23-f740791483fb",
      "name": "構造化出力パーサー",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -896,
        208
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"is_invoice\": {\n      \"type\": \"boolean\"\n    },\n    \"due_date\": {\n      \"type\": [\"string\", \"null\"],\n      \"format\": \"date\"\n    },\n    \"amount_due\": {\n      \"type\": [\"number\", \"null\"]\n    },\n    \"email_id\": {\n      \"type\": \"string\"\n    },\n    \"thread_id\": {\n      \"type\": \"string\"\n    },\n    \"sender\": {\n      \"type\": \"string\"\n    },\n    \"subject\": {\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"is_invoice\",\n    \"due_date\",\n    \"amount_due\",\n    \"email_id\",\n    \"thread_id\",\n    \"sender\",\n    \"subject\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "436dccba-2b62-4ee9-b2c3-0581bc836ed7",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -464,
        80
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4c1eb726-1666-4f5c-b4e0-8f938f3ef791",
      "name": "付箋2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1552,
        208
      ],
      "parameters": {
        "width": 304,
        "height": 224,
        "content": "### ⚠️ Setup Required  \n- Connect your Gmail account using OAuth2  \n- Connect your Slack account using OAuth 2\n- Add your OpenAI API Key under **API Credentials**  "
      },
      "typeVersion": 1
    },
    {
      "id": "17c6acfe-6074-43f9-af78-8a2f7104df5b",
      "name": "未読メール取得",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1264,
        -16
      ],
      "webhookId": "4259da3e-a2e2-41ea-aaac-50d8bf8a4bb7",
      "parameters": {
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {},
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "51725993-99b5-4d9e-a562-4e762ca6a0a2",
      "name": "メールが請求書か確認",
      "type": "n8n-nodes-base.if",
      "position": [
        -688,
        -16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "dc8158a0-29aa-4c7f-9de3-994a5d827331",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.output.is_invoice }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "ec14d8de-cfab-4b53-a3b5-9aae1c3b808d",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 272,
        "content": "### 💡 Schedule Trigger  \nThis runs every hour.  \nYou can change the interval here depending on how often you want Gmail to be checked."
      },
      "typeVersion": 1
    },
    {
      "id": "3f7e75ec-5a03-4664-b1ff-91f57bee2d9d",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -336
      ],
      "parameters": {
        "color": 5,
        "width": 272,
        "height": 400,
        "content": "### 💡 Customize Notification Format  \nYou can change the title in this node.  For example: `Pay invoice from {{sender}} by {{due_date}}`  \nInclude more invoice details in the notes field if needed.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "db70ae0c-794b-452e-b8cd-26574ff006a2",
      "name": "Notify Slack User",
      "type": "n8n-nodes-base.slack",
      "position": [
        -464,
        -112
      ],
      "webhookId": "a155a0c9-d84e-4937-b215-9d2920c45616",
      "parameters": {
        "text": "=Invoice from {{ $json.output.sender }} – ${{ $json.output.amount_due }} due {{ $json.output.due_date }}",
        "user": {
          "__rl": true,
          "mode": "username",
          "value": ""
        },
        "select": "user",
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.3
    },
    {
      "id": "d9bc11f7-edb5-4521-9702-725c8fa736fc",
      "name": "付箋3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        -256
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 640,
        "content": "### 🤖 AI Agent\n\n• This node uses an AI prompt to detect whether an email is invoice-related.\n• You can customize the prompt to detect other types of emails (e.g., receipts, contracts).\n"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "fb69e703-7747-4862-8208-0d0803f5ce8f": {
      "main": [
        [
          {
            "node": "51725993-99b5-4d9e-a562-4e762ca6a0a2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "df47f544-18a9-4eea-a02f-6e8618bdc903": {
      "main": [
        [
          {
            "node": "17c6acfe-6074-43f9-af78-8a2f7104df5b",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "17c6acfe-6074-43f9-af78-8a2f7104df5b": {
      "main": [
        [
          {
            "node": "fb69e703-7747-4862-8208-0d0803f5ce8f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ff1adb6a-43d6-4b36-9c91-0046b0146565": {
      "ai_languageModel": [
        [
          {
            "node": "fb69e703-7747-4862-8208-0d0803f5ce8f",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "acc58349-b51f-4623-9a23-f740791483fb": {
      "ai_outputParser": [
        [
          {
            "node": "fb69e703-7747-4862-8208-0d0803f5ce8f",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "51725993-99b5-4d9e-a562-4e762ca6a0a2": {
      "main": [
        [
          {
            "node": "db70ae0c-794b-452e-b8cd-26574ff006a2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "436dccba-2b62-4ee9-b2c3-0581bc836ed7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

このワークフローの使い方は?

上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。

このワークフローはどんな場面に適していますか?

中級

有料ですか?

このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。

ワークフロー情報
難易度
中級
ノード数12
カテゴリー-
ノードタイプ9
難易度説明

経験者向け、6-15ノードの中程度の複雑さのワークフロー

作成者
Matt Chong | n8n Creator

Matt Chong | n8n Creator

@mattxchong

Automation nerd fueled by good coffee, deep curiosity, and clean flows.

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34