创建带线程和思考界面的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 聊天模型",
"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 Agent",
"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": "无操作",
"type": "n8n-nodes-base.noOp",
"position": [
-60,
440
],
"parameters": {},
"typeVersion": 1
},
{
"id": "0442b3d9-2149-49b6-9cc8-af92d1ed036c",
"name": "收到消息时",
"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": "检查是否为用户",
"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": "设置思考状态",
"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": "发送回复",
"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": "## 监听私信"
},
"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": "## 过滤噪音"
},
"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": "## 激活加载 UI"
},
"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": "## 在此处自定义您的代理"
},
"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": "Send Reply",
"type": "main",
"index": 0
}
]
]
},
"Check If User": {
"main": [
[
{
"node": "Set Thinking Status",
"type": "main",
"index": 0
},
{
"node": "AI Agent",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"On Message Received": {
"main": [
[
{
"node": "Check If User",
"type": "main",
"index": 0
}
]
]
},
"Postgres Chat Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 客服机器人, AI 聊天机器人
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Telegram支持交接自动化
使用GPT4和邮件提醒自动化Telegram支持从AI到人工的交接
If
Set
Switch
+12
40 节点Meelioo
客服机器人
Explorium MCP - Slack机器人
使用Explorium MCP和Claude AI的Slack商业智能助手
If
Set
Code
+8
13 节点explorium
客服机器人
构建用于Slack候选人评估的AI驱动聊天机器人
AI简历分析与候选人评估:Slack和Google表格集成
If
Code
Slack
+12
29 节点Trung Tran
AI 聊天机器人
🚀 面向Shopify品牌的AI驱动WhatsApp客户支持
面向Shopify品牌的AI驱动WhatsApp客户支持(LLM智能体)
Set
Slack
Switch
+11
30 节点Ruthwik
杂项
商业AI指挥中心:Google Workspace模块化代理、向量搜索与多渠道报告
商业AI指挥中心:Google Workspace模块化代理、向量搜索与多渠道报告
Set
Gmail
Slack
+35
80 节点Paul
文档提取
Dream 100 研究代理
使用 Perplexity AI 研究和 Google Sheets 生成 Dream 100 潜在客户列表
If
Set
Slack
+11
29 节点Brandon True
杂项
工作流信息
难度等级
中级
节点数量12
分类2
节点类型9
作者
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 查看 →
分享此工作流