Slack AI チャットボットの作成(OpenRouterとPostgresを使用し、スレッドと思考インターフェースを備えている)

中級

これはSupport Chatbot, AI Chatbot分野の自動化ワークフローで、12個のノードを含みます。主にIf, Slack, HttpRequest, SlackTrigger, Agentなどのノードを使用。 OpenRouterとPostgresを使用して、スレッドと思考インターフェースを備えたSlack AIチャットボットを作成する

前提条件
  • Slack Bot Token または Webhook URL
  • ターゲットAPIの認証情報が必要な場合あり
  • PostgreSQLデータベース接続情報
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
  "meta": {
    "instanceId": "9192ad8880fb52b25f18408be81eae9d996a6784a1da3c68d52d3b7ef01d482b",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "7436eb20-9360-4219-8c2b-8b56eb3843ec",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -80,
        160
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "muXopBcyQsze8BOD",
          "name": "OpenRouter | Paper Jam"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9601c9d7-41c0-44da-8a9c-97956711bd07",
      "name": "AI エージェント",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -80,
        -20
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a helpful, friendly, assistant. \n\nYou always respond only nicely formatted markdown where appropriate."
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "23df5bee-5095-4c8d-9f78-c62119734332",
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -60,
        440
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "0442b3d9-2149-49b6-9cc8-af92d1ed036c",
      "name": "On Message Received",
      "type": "n8n-nodes-base.slackTrigger",
      "position": [
        -860,
        80
      ],
      "webhookId": "cf67c1e1-f3db-401e-9439-c0f315c05baf",
      "parameters": {
        "options": {
          "resolveIds": false
        },
        "trigger": [
          "message"
        ],
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_APPS_CHANNEL_ID"
        }
      },
      "credentials": {
        "slackApi": {
          "id": "awboaOk6Kh1kQZ7N",
          "name": "Slack | Paper Jam"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d9efc43e-b1c1-48c0-8c68-42304c752645",
      "name": "Check If User",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "ab6c4d27-4daf-4c6f-9ad5-866f6cb62758",
              "operator": {
                "type": "string",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.bot_id }}",
              "rightValue": ""
            },
            {
              "id": "211e32ac-a544-46f4-8ce9-9a41674c4184",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $json.text }}",
              "rightValue": ""
            },
            {
              "id": "6160af99-6beb-4858-95e6-16e808c22581",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.type }}",
              "rightValue": "message"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "99ccfdff-4fd1-4cff-99e0-7a2620735ff8",
      "name": "設定 Thinking Status",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        0,
        -400
      ],
      "parameters": {
        "url": "https://slack.com/api/assistant.threads.setStatus",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "channel_id",
              "value": "={{ $json.channel }}"
            },
            {
              "name": "status",
              "value": "is thinking..."
            },
            {
              "name": "thread_ts",
              "value": "={{ $json.thread_ts }}"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "Pp3oG0nadbpd6DqZ",
          "name": "Jina Bearer Token | Paper Jam"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f1bbe14d-9274-4e7a-804a-dd65b6efca24",
      "name": "Send Reply",
      "type": "n8n-nodes-base.slack",
      "position": [
        560,
        60
      ],
      "webhookId": "f23b3a3c-b618-4d39-a5f0-4d85c65519af",
      "parameters": {
        "text": "={{ $json.output }}",
        "select": "channel",
        "blocksUi": "={\n \"blocks\": [\n   { \n    \"type\": \"markdown\", \n    \"text\": {{ JSON.stringify($json.output) }}\n    }\n ]\n}\n\n",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('On Message Received').item.json.channel }}"
        },
        "messageType": "block",
        "otherOptions": {
          "mrkdwn": true,
          "thread_ts": {
            "replyValues": {
              "thread_ts": "={{ $('On Message Received').item.json.ts }}"
            }
          },
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "id": "awboaOk6Kh1kQZ7N",
          "name": "Slack | Paper Jam"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "484b674d-be92-49a9-9a0d-a4f9747dc5bb",
      "name": "付箋",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -940,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## Listen for a DM\n\n**IMPORTANT**: Enter your Slack app's ID in the \"Channel to Watch\" field."
      },
      "typeVersion": 1
    },
    {
      "id": "fdd9665d-b7c1-4a1d-b84d-6113ffb88a55",
      "name": "付箋1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -40
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 280,
        "content": "## Filter out noise\n\nWe only care about user messages."
      },
      "typeVersion": 1
    },
    {
      "id": "c7cc385d-189f-4fb0-9901-8acbd4696e0c",
      "name": "付箋2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -560
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 360,
        "content": "## Activate loading UI\n\nThis HTTP POST request will trigger the \"three dots\" thinking UI in the message thread. Slack automatically removes this UI when our app responds."
      },
      "typeVersion": 1
    },
    {
      "id": "07c2ebc0-bc20-4584-bf87-31788aa1646d",
      "name": "付箋3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 460,
        "content": "## Customize your agent here\n\nThe agent is the brains of your chatbot. Customize the prompts and tooling however you need."
      },
      "typeVersion": 1
    },
    {
      "id": "242fa108-e421-4428-814d-b4ebf967f12d",
      "name": "Postgres チャットメモリ",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        60,
        160
      ],
      "parameters": {
        "tableName": "chat_histories",
        "sessionKey": "={{ $('On Message Received').item.json.thread_ts }}",
        "sessionIdType": "customKey"
      },
      "credentials": {
        "postgres": {
          "id": "td26YI5S9ozNu8dq",
          "name": "Postgres | Paper Jam n8n"
        }
      },
      "typeVersion": 1.3
    }
  ],
  "pinData": {},
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "f1bbe14d-9274-4e7a-804a-dd65b6efca24",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d9efc43e-b1c1-48c0-8c68-42304c752645": {
      "main": [
        [
          {
            "node": "Set Thinking Status",
            "type": "main",
            "index": 0
          },
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "23df5bee-5095-4c8d-9f78-c62119734332",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "0442b3d9-2149-49b6-9cc8-af92d1ed036c": {
      "main": [
        [
          {
            "node": "d9efc43e-b1c1-48c0-8c68-42304c752645",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "7436eb20-9360-4219-8c2b-8b56eb3843ec": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
よくある質問

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

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

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

中級 - サポートチャットボット, AIチャットボット

有料ですか?

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

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

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

作成者
James Francis

James Francis

@paperjam

👋 Hi, I'm James. I run an AI automation agency focused on building small, focused workflows that have a direct and measurable impact on business growth or optimization.

外部リンク
n8n.ioで表示

このワークフローを共有

カテゴリー

カテゴリー: 34