AI 智能体 - 短链接生成器
高级
这是一个Miscellaneous, AI Chatbot领域的自动化工作流,包含 18 个节点。主要使用 Set, Code, Html, Webhook, DataTable 等节点。 使用 GPT-4.1 和数据存储生成并管理短链接
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
- •OpenAI API Key
使用的节点 (18)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "WmHtnpnkARE1wVqs",
"meta": {
"instanceId": "a0e41110bf9f611e96e18e0663d80d746aeedc58368940bfe471a8d577a5069b",
"templateCredsSetupCompleted": true
},
"name": "AI Agent - 短链接生成器",
"tags": [],
"nodes": [
{
"id": "6c7043d8-e091-4e50-a661-f1047576c565",
"name": "插入行",
"type": "n8n-nodes-base.dataTable",
"position": [
-16,
-144
],
"parameters": {
"columns": {
"value": {
"orginalLink": "={{ $('GenerateShortLink').item.json.originalLink }}",
"shortlinkId": "={{ $json.shortLinkId }}"
},
"schema": [
{
"id": "orginalLink",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "orginalLink",
"defaultMatch": false
},
{
"id": "shortlinkId",
"type": "string",
"display": true,
"removed": false,
"readOnly": false,
"required": false,
"displayName": "shortlinkId",
"defaultMatch": false
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "MzE4aKh7Wsv4N0Cv",
"cachedResultUrl": "/projects/pjq2PmuJxpMOPZST/datatables/MzE4aKh7Wsv4N0Cv",
"cachedResultName": "ShortLink"
}
},
"typeVersion": 1
},
{
"id": "310ecc62-f469-42d8-bb15-8795e0aef955",
"name": "生成短链接ID",
"type": "n8n-nodes-base.code",
"position": [
-240,
-144
],
"parameters": {
"jsCode": "\nvar length = 4;\n const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n const randomIndex = Math.floor(Math.random() * chars.length);\n result += chars[randomIndex];\n }\n\n return [{ shortLinkId: result }];\n"
},
"typeVersion": 2
},
{
"id": "1a615458-ea3c-4336-b9fd-602844b36f5d",
"name": "获取行数据",
"type": "n8n-nodes-base.dataTable",
"position": [
-464,
80
],
"parameters": {
"filters": {
"conditions": [
{
"keyName": "shortlinkId",
"keyValue": "={{ $json.query.a }}"
}
]
},
"operation": "get",
"dataTableId": {
"__rl": true,
"mode": "list",
"value": "MzE4aKh7Wsv4N0Cv",
"cachedResultUrl": "/projects/pjq2PmuJxpMOPZST/datatables/MzE4aKh7Wsv4N0Cv",
"cachedResultName": "ShortLink"
}
},
"typeVersion": 1
},
{
"id": "2c2ace57-bb37-43b5-a606-122e38928bb2",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-688,
-576
],
"webhookId": "a282c57a-a0b2-43d9-9fe5-fdd3b61ad585",
"parameters": {
"public": true,
"options": {}
},
"typeVersion": 1.3
},
{
"id": "af6bae57-7f02-4b14-b5a0-f4d852321a62",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-352,
-576
],
"parameters": {
"options": {
"systemMessage": "You are a helpful assistant.\n"
}
},
"typeVersion": 2.2
},
{
"id": "c10cdd53-ddaa-4701-922c-5788c3f41759",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-480,
-368
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "2TBvwobWbbHlIjKT",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "8d9e3709-0fb7-4fbc-9c1d-f3f74878e6bc",
"name": "简单记忆",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
-256,
-368
],
"parameters": {},
"typeVersion": 1.3
},
{
"id": "1e495a59-c48b-4887-a9c1-19c53072a591",
"name": "生成短链接",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-688,
-144
],
"parameters": {
"inputSource": "jsonExample",
"jsonExample": "\n{\n\"originalLink\": \n\"https://www.nghiaai.dev/\"\n}"
},
"typeVersion": 1.1
},
{
"id": "4e019563-fc6f-4ec7-b79e-1817cd35e411",
"name": "配置",
"type": "n8n-nodes-base.set",
"position": [
-464,
-144
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "5c7030c4-c308-4e95-a78d-c32d8a252df4",
"name": "your_webhook_url",
"type": "string",
"value": "http://localhost:5678"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "290c7c96-1cc9-432a-806e-6f2b04fe92a5",
"name": "生成短链接",
"type": "n8n-nodes-base.code",
"position": [
208,
-144
],
"parameters": {
"jsCode": "var your_webhook_url = $('Config').first().json.your_webhook_url;\nvar shortLinkId = $('Generate shorlinkId').first().json.shortLinkId\nvar shortLink = your_webhook_url + \"/webhook/shortLink?a=\" + shortLinkId;\nreturn [{ shortLink: shortLink }];"
},
"typeVersion": 2
},
{
"id": "1a2213c2-c423-49a0-a2b1-939109d30391",
"name": "调用\"创建短链接\"",
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [
-48,
-368
],
"parameters": {
"workflowId": {
"__rl": true,
"mode": "list",
"value": "WmHtnpnkARE1wVqs",
"cachedResultUrl": "/workflow/WmHtnpnkARE1wVqs",
"cachedResultName": "Create Short Link"
},
"description": "调用此工具获取短链接",
"workflowInputs": {
"value": {
"originalLink": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('originalLink', ``, 'string') }}"
},
"schema": [
{
"id": "originalLink",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "originalLink",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "host",
"type": "string",
"display": true,
"removed": true,
"required": false,
"displayName": "host",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
}
},
"typeVersion": 2.2
},
{
"id": "49807a5c-8c1a-4a6d-9e1b-b6d0ea72ff92",
"name": "页面重定向",
"type": "n8n-nodes-base.html",
"position": [
-240,
80
],
"parameters": {
"html": "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <title>Redirecting…</title>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <!-- Optional: meta refresh as a no-JS fallback -->\n <meta http-equiv=\"refresh\" content=\"0; url={{ $json.orginalLink }}\" />\n <script>\n // Use replace() so it doesn't create an extra history entry\n location.replace({{ $json.orginalLink }});\n </script>\n <style>\n body {font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; display:grid; place-content:center; min-height:100vh;}\n a {text-decoration: none;}\n </style>\n</head>\n<body>\n <p>Redirecting… If nothing happens, <a href=\"{{ $json.orginalLink }}\">click here</a>.</p>\n</body>\n</html>\n"
},
"typeVersion": 1.2
},
{
"id": "d6732527-8565-4d7d-8bf5-77f02eba0462",
"name": "响应",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
-16,
80
],
"parameters": {
"options": {},
"respondWith": "text",
"responseBody": "={{ $json.html }}"
},
"typeVersion": 1.4
},
{
"id": "866a4e41-ff4f-4eda-8be8-0e584285318b",
"name": "短链接API",
"type": "n8n-nodes-base.webhook",
"position": [
-688,
80
],
"webhookId": "b280e565-5037-4752-ba2c-547e4b52531c",
"parameters": {
"path": "shortLink",
"options": {},
"responseMode": "responseNode"
},
"typeVersion": 2.1
},
{
"id": "ad474ea3-02bb-4770-88b0-8bba2c5ad859",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
-656
],
"parameters": {
"width": 336,
"height": 896,
"content": "## 设置指南"
},
"typeVersion": 1
},
{
"id": "4903952a-5da7-4bee-b945-550c0a636b7e",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-784,
-656
],
"parameters": {
"color": 4,
"width": 1168,
"height": 448,
"content": "## 智能体"
},
"typeVersion": 1
},
{
"id": "05b8c558-4503-45a9-8c5d-52809d60f0d6",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-784,
-208
],
"parameters": {
"color": 5,
"width": 1168,
"height": 224,
"content": "## 创建短链接"
},
"typeVersion": 1
},
{
"id": "5ba8e271-d542-42e9-8cab-fac08171c120",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-784,
16
],
"parameters": {
"color": 3,
"width": 1168,
"height": 224,
"content": "## 处理短链接请求"
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "be460863-5692-4397-a9d3-c94e69d2c6b3",
"connections": {
"Config": {
"main": [
[
{
"node": "Generate shorlinkId",
"type": "main",
"index": 0
}
]
]
},
"Get row(s)": {
"main": [
[
{
"node": "Page Redirect",
"type": "main",
"index": 0
}
]
]
},
"Insert row": {
"main": [
[
{
"node": "Generate ShortLink",
"type": "main",
"index": 0
}
]
]
},
"Page Redirect": {
"main": [
[
{
"node": "Response",
"type": "main",
"index": 0
}
]
]
},
"ShortLink API": {
"main": [
[
{
"node": "Get row(s)",
"type": "main",
"index": 0
}
]
]
},
"Simple Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"GenerateShortLink": {
"main": [
[
{
"node": "Config",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Generate shorlinkId": {
"main": [
[
{
"node": "Insert row",
"type": "main",
"index": 0
}
]
]
},
"Call 'Create Short Link'": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 杂项, AI 聊天机器人
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
创建具有GPT-4o聊天界面和可视化报告的交互式Snowflake数据浏览器
创建具有GPT-4o聊天界面和可视化报告的交互式Snowflake数据浏览器
If
Set
Webhook
+11
28 节点Mark Shcherbakov
内部知识库
使用 VAPI 构建 AI 语音助手
WooCommerce AI语音客服,使用VAPI、GPT-4o、Gemini和RAG
Set
Webhook
Http Request
+13
25 节点Davide
杂项
使用GPT-4创建播放列表和控制Spotify播放器
通过GPT-4创建播放列表并控制Spotify播放器
Set
Code
Spotify
+11
29 节点Guillaume Duvernay
个人效率
[模板] - 仪表板聊天
AI模型使用仪表板:追踪LLM工作流的令牌指标和成本
N8n
Set
Code
+12
30 节点Hugo
创建品牌化AI驱动的网站聊天机器人
创建品牌化AI驱动的网站聊天机器人
If
Set
Code
+12
24 节点Wayne Simpson
产品
工作流信息
难度等级
高级
节点数量18
分类2
节点类型13
作者
Nghia Nguyen
@nghiaaidevI am Nguyen Trung Nghia, a Software Engineer passionate about AI Automation. I build intelligent automation systems that help businesses reduce costs, increase productivity, and scale faster with the power of AI technology.
外部链接
在 n8n.io 查看 →
分享此工作流