带等待节点的长运行工作流状态管理系统
高级
这是一个Engineering领域的自动化工作流,包含 42 个节点。主要使用 If, Set, Code, Wait, Filter 等节点。 带等待节点的长运行工作流状态管理系统
前置要求
- •可能需要目标 API 的认证凭证
- •HTTP Webhook 端点(n8n 会自动生成)
使用的节点 (42)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"creator": "Lucas Peyrin",
"instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0",
"fingerprint": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdG9yIjoiIiwiaXNzIjoibjhuIiwiaWF0IjoxNzUzMTg1NTA2fQ.dVu-rLvYTXqkxAD6CAZ88wBJP6Esr41Te54DdaImktw"
},
"nodes": [
{
"id": "1ec4313c-df14-4c89-86e7-a51b2462428c",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "D. TELEPORT: Resume Paused Workflow",
"type": "n8n-nodes-base.httpRequest",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"onError": "continueErrorOutput",
"position": [
1632,
896
],
"parameters": {
"url": "={{ $json.resume_url }}",
"method": "POST",
"options": {},
"jsonBody": "={{ $('A. Entry: Receive Session Info').last().json.input_items }}",
"sendBody": true,
"specifyBody": "json"
},
"typeVersion": 4.2
},
{
"id": "ab925a2d-f8b4-4267-8aa6-f6c2eeb1f150",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "E. Stop This Execution",
"type": "n8n-nodes-base.filter",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2256,
688
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "0e6f2a44-0407-4534-9df9-71af678be3e8",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": false,
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "14e9e8a7-b52b-43a7-a24c-133ed203789f",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "B. Check if Session is New or Existing",
"type": "n8n-nodes-base.code",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
944,
1104
],
"parameters": {
"jsCode": "// n8n Code Node\n// Description: Checks if a session_id already exists in the workflow's static data.\n// If it's a new session, it stores the session_id and its resume_url.\n// If the session already exists, it returns the previously stored resume_url.\n\n// --- INPUTS ---\n// This code expects the following inputs from the previous node:\n// $json.session_id: (string) A unique identifier for the session.\n// $json.resume_url: (string) The URL associated with the session.\n\nconst sessionId = $json.session_id;\nconst resumeUrl = $json.resume_url;\nconst workflowId = $json.workflow_id;\nconst executionId = $json.execution_id;\n\n// --- VALIDATION ---\nif (!sessionId) {\n throw new Error(\"Input data is missing 'session_id'. Please ensure it's provided.\");\n}\nif (!workflowId) {\n throw new Error(\"Input data is missing 'workflow_id'. Please ensure it's provided.\");\n}\nif (!executionId) {\n throw new Error(\"Input data is missing 'execution_id'. Please ensure it's provided.\");\n}\n\n// Get the workflow's static data (persists between executions).\nconst staticData = $getWorkflowStaticData('global');\n\n// --- INITIALIZATION ---\nif (!staticData.sessions) {\n staticData.sessions = {};\n}\nif (!staticData.sessions[workflowId]) {\n staticData.sessions[workflowId] = {};\n}\n\n// Prepare output object\nconst output = {\n session_id: sessionId,\n new: false,\n resume_url: '',\n main_execution: ''\n};\n\n// --- CORE LOGIC ---\nif (staticData.sessions[workflowId][sessionId]) {\n // Session already exists\n output.new = false;\n output.resume_url = staticData.sessions[workflowId][sessionId].resume_url;\n output.main_execution = staticData.sessions[workflowId][sessionId].execution_id;\n} else {\n // New session\n if (!resumeUrl) {\n throw new Error(\"Input data is missing 'resume_url' for a new session.\");\n }\n\n output.new = true;\n output.resume_url = resumeUrl;\n output.main_execution = executionId;\n\n // Store session data\n staticData.sessions[workflowId][sessionId] = {\n resume_url: resumeUrl,\n execution_id: executionId,\n first_seen: new Date().toISOString()\n };\n}\n\n// --- OUTPUT ---\nreturn output;"
},
"typeVersion": 2
},
{
"id": "529a1e67-9e2c-4c59-b402-790bb62a34ea",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "F. Prepare Initial Data",
"type": "n8n-nodes-base.set",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1632,
1280
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "72bd8c68-d201-4376-ab1f-2cbd8a62b3e2",
"name": "input_items",
"type": "array",
"value": "={{ $('A. Entry: Receive Session Info').last().json.input_items }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "9d8cc3b8-f4ae-4d2a-9e27-c41b3eb0a708",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "G. Return Data to Main Workflow",
"type": "n8n-nodes-base.splitOut",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1856,
1280
],
"parameters": {
"options": {},
"fieldToSplitOut": "input_items"
},
"typeVersion": 1
},
{
"id": "116121f5-8fa4-4d23-80f4-3000511f901a",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "C. Route Based on Session State",
"type": "n8n-nodes-base.if",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1296,
1104
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "40784acd-1fd8-4370-9219-7053267ac426",
"operator": {
"type": "boolean",
"operation": "notEquals"
},
"leftValue": "={{ $json.new }}",
"rightValue": true
}
]
}
},
"typeVersion": 2.2
},
{
"id": "54bdfb27-85ca-44c5-9cdb-3dc92d44000e",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Stop Session On Error ?",
"type": "n8n-nodes-base.if",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1952,
1056
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "e3920d1a-8312-4142-81ac-3708e1cfceed",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ $('A. Entry: Receive Session Info').last().json.stop_session_on_error }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "d8bf9a2d-045d-4bbe-8c85-ca1183a4b86e",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Reset Session",
"type": "n8n-nodes-base.code",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2192,
1056
],
"parameters": {
"jsCode": "// n8n Code Node\n// Description: Checks if a session_id already exists in the workflow's static data.\n// If it's a new session, it stores the session_id and its resume_url.\n// If the session already exists, it returns the previously stored resume_url.\n\n// --- INPUTS ---\n// This code expects the following inputs from the previous node:\n// $json.session_id: (string) A unique identifier for the session.\n// $json.resume_url: (string) The URL associated with the session.\n\nconst sessionId = $('A. Entry: Receive Session Info').last().json.session_id;\nconst resumeUrl = $('A. Entry: Receive Session Info').last().json.resume_url;\nconst workflowId = $('A. Entry: Receive Session Info').last().json.workflow_id;\nconst executionId = $('A. Entry: Receive Session Info').last().json.execution_id;\n\n// --- VALIDATION ---\nif (!sessionId) {\n throw new Error(\"Input data is missing 'session_id'. Please ensure it's provided.\");\n}\nif (!workflowId) {\n throw new Error(\"Input data is missing 'workflow_id'. Please ensure it's provided.\");\n}\nif (!executionId) {\n throw new Error(\"Input data is missing 'execution_id'. Please ensure it's provided.\");\n}\n\n// Get the workflow's static data (persists between executions).\nconst staticData = $getWorkflowStaticData('global');\n\n// --- INITIALIZATION ---\nif (!staticData.sessions) {\n staticData.sessions = {};\n}\nif (!staticData.sessions[workflowId]) {\n staticData.sessions[workflowId] = {};\n}\n\n// Prepare output object\nconst output = {\n session_id: sessionId,\n new: false,\n resume_url: '',\n main_execution: ''\n};\n\n// --- CORE LOGIC ---\n\n// Reset session\nif (!resumeUrl) {\n throw new Error(\"Input data is missing 'resume_url' for a new session.\");\n}\n\noutput.new = true;\noutput.resume_url = resumeUrl;\noutput.main_execution = executionId;\n\n// Store session data\nstaticData.sessions[workflowId][sessionId] = {\n resume_url: resumeUrl,\n execution_id: executionId,\n first_seen: new Date().toISOString()\n};\n\n// --- OUTPUT ---\nreturn output;"
},
"typeVersion": 2
},
{
"id": "cf9710a0-8f0b-4370-a35e-39b5878f1cc2",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Respond with Input Items",
"type": "n8n-nodes-base.noOp",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2416,
1056
],
"parameters": {},
"typeVersion": 1
},
{
"id": "b23f9aa6-e9c8-441f-8d65-9474b2f9cba6",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Wait Node Sent Response Items ?",
"type": "n8n-nodes-base.if",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2016,
608
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "or",
"conditions": [
{
"id": "27670327-4717-4b1c-9edb-c1ece0f43bdc",
"operator": {
"type": "string",
"operation": "notEquals"
},
"leftValue": "={{ $json.message }}",
"rightValue": "Workflow was started"
},
{
"id": "191d97bf-71dc-4a8c-8715-7171a1dfae9a",
"operator": {
"type": "string",
"operation": "notExists",
"singleValue": true
},
"leftValue": "={{ $json.message }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "dab41bea-d997-4a48-a1b8-9f90f2267743",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Send Items From Checkpoint",
"type": "n8n-nodes-base.noOp",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2256,
512
],
"parameters": {},
"typeVersion": 1
},
{
"id": "e29f9889-86f7-41c2-969a-459f5450bfe9",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note13",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
880,
-48
],
"parameters": {
"color": 4,
"width": 256,
"height": 272,
"content": ""
},
"typeVersion": 1
},
{
"id": "7f899a48-c96a-417e-957a-a2fa720f6d73",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "A. Entry: Receive Session Info",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
640,
1104
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "session_id"
},
{
"name": "resume_url"
},
{
"name": "input_items",
"type": "any"
},
{
"name": "workflow_id"
},
{
"name": "execution_id"
},
{
"name": "stop_session_on_error",
"type": "boolean"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "d66ecc05-1b86-4f16-9534-d5c47c76f1bc",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "1. Start Main Workflow (Manual)",
"type": "n8n-nodes-base.manualTrigger",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
640,
48
],
"parameters": {},
"typeVersion": 1
},
{
"id": "d72f27c3-2724-4126-b0c2-93fd82ecbb21",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
-288,
-656
],
"parameters": {
"width": 624,
"height": 416,
"content": "# The \"Teleport\" Workflow Pattern\n\nThis workflow demonstrates a powerful stateful pattern for managing long-running, multi-step processes that need to be paused and resumed by external events.\n\n**Use Cases:**\n- Multi-day user onboarding sequences.\n- Processes waiting for human approval (e.g., via email link).\n- Chatbots that need to maintain conversation state across multiple messages.\n\n\nIt consists of two parts:\n1. **The Main Process (Top):** Your primary business logic. It can be paused at any 'Checkpoint' (`Wait` node).\n2. **The Async Portal (Bottom):** A state-management engine that remembers running processes and can 'teleport' new data to them."
},
"typeVersion": 1
},
{
"id": "b8c415e6-3d16-432d-844d-97bb9634d066",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
368,
-656
],
"parameters": {
"color": 7,
"width": 3344,
"height": 944,
"content": "## MAIN PROCESS\n### This is your primary business logic. It calls the Portal to register itself, processes some data, and then pauses at a Checkpoint, waiting for another event to resume it."
},
"typeVersion": 1
},
{
"id": "9368010f-f32c-43fc-bac1-e90d193ffca4",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "2. Call Async Portal",
"type": "n8n-nodes-base.executeWorkflow",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
960,
48
],
"parameters": {
"options": {
"waitForSubWorkflow": true
},
"workflowId": {
"__rl": true,
"mode": "id",
"value": "={{ $workflow.id }}"
},
"workflowInputs": {
"value": {
"resume_url": "={{ $execution.resumeUrl }}",
"session_id": "test123",
"input_items": "={{ $input.all().map(item => item.json) }}",
"workflow_id": "={{ $workflow.id }}",
"execution_id": "={{ $execution.id }}",
"stop_session_on_error": false
},
"schema": [
{
"id": "session_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "session_id",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "resume_url",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "resume_url",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "input_items",
"display": true,
"removed": false,
"required": false,
"displayName": "input_items",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "workflow_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "workflow_id",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "execution_id",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "execution_id",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "stop_session_on_error",
"type": "boolean",
"display": true,
"removed": false,
"required": false,
"displayName": "stop_session_on_error",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"session_id"
],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"executeOnce": true,
"typeVersion": 1.2
},
{
"id": "9c98707e-763a-4022-8996-9ded3f587754",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "3. Process Initial Data (Before Checkpoint 1)",
"type": "n8n-nodes-base.set",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1696,
48
],
"parameters": {
"options": {}
},
"typeVersion": 3.4
},
{
"id": "9814ef51-c934-4b71-af89-4d6a3df671ff",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "4. PAUSE at Checkpoint 1",
"type": "n8n-nodes-base.wait",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2144,
48
],
"webhookId": "d522c442-945b-4350-9d88-76276d6afaf9",
"parameters": {
"resume": "webhook",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 1.1
},
{
"id": "3bc4a204-04e8-4294-8d52-5fb1ae0d8f95",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "5a. Receive Resumed Data",
"type": "n8n-nodes-base.splitOut",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2496,
48
],
"parameters": {
"options": {},
"fieldToSplitOut": "body"
},
"typeVersion": 1
},
{
"id": "b76cafb7-8d42-40e4-b276-62536e360b06",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "6. PAUSE at Checkpoint 2",
"type": "n8n-nodes-base.wait",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
3088,
48
],
"webhookId": "d522c442-945b-4350-9d88-76276d6afaf9",
"parameters": {
"resume": "webhook",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 1.1
},
{
"id": "a9bffc0c-fcdb-49c0-b920-8ed458798e78",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "7. Process Final Data (After Checkpoint 2)",
"type": "n8n-nodes-base.set",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
3440,
48
],
"parameters": {
"options": {}
},
"typeVersion": 3.4
},
{
"id": "6ca47cb1-f7ec-4c4f-87d8-4f780224ce61",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
400,
-112
],
"parameters": {
"color": 7,
"width": 384,
"height": 320,
"content": "### 1. Start Main Process\n\nThis is the entry point for your stateful process. It could be a webhook, a form submission, or a manual trigger like this one."
},
"typeVersion": 1
},
{
"id": "9ff30639-61f4-49a9-89fc-0e071b8faebe",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2032,
-240
],
"parameters": {
"color": 7,
"width": 320,
"height": 464,
"content": "### 4. PAUSE at Checkpoint 1\n\nThis `Wait` node is a **Checkpoint**. The workflow execution physically stops here and is persisted.\n\nIt generates a unique `resume_url` that is stored by the Portal. The only way to wake this execution up is for the Portal to make an HTTP POST request to that specific URL."
},
"typeVersion": 1
},
{
"id": "88e03f8a-efda-4194-b3a4-cda3513e2753",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note8",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2384,
-176
],
"parameters": {
"color": 7,
"width": 560,
"height": 400,
"content": "### 5. Resumption & Response\n\nWhen the Portal 'teleports' data, this sequence is triggered.\n\n- **5a:** Receives the new data from the body of the resume request.\n- **5b:** Immediately sends a response back to the Portal. This is optional and can be used for passing data back to the Portal if needed."
},
"typeVersion": 1
},
{
"id": "0c961fcc-5f67-4301-a8f4-e8bb1434bcc9",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note9",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2976,
-176
],
"parameters": {
"color": 7,
"width": 320,
"height": 400,
"content": "### 6. PAUSE at Checkpoint 2\n\nThis demonstrates that a single Main Process can have multiple, sequential checkpoints. The Portal will always resume the *latest* Checkpoint that was registered for the session."
},
"typeVersion": 1
},
{
"id": "c1bb3790-8b55-48f5-aab9-fa9d28157ddb",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
816,
-304
],
"parameters": {
"color": 4,
"width": 384,
"height": 560,
"content": "### 2. Call Async Portal\n\nThis is the first and only direct interaction with the Portal. The Main Process sends its `session_id` and its current `resume_url` to register itself.\n\n**Key Setting:** `Wait for Sub-Workflow` is **ON**. The Main Process needs the Portal's response to know if it should continue (new session) or stop (existing session that will get teleported to a checkpoint)."
},
"typeVersion": 1
},
{
"id": "54ca2319-a769-4cb7-b459-1e83863460ff",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
368,
320
],
"parameters": {
"color": 7,
"width": 2256,
"height": 1280,
"content": "## ASYNC PORTAL\n### This is the state-management engine. It's a separate, reusable workflow. Its only job is to check if a session is new or existing. If it's existing, it finds the correct paused workflow's resume url and sends the new data to it. If it's new, then it simply returns all the input items."
},
"typeVersion": 1
},
{
"id": "8e86a20e-afd8-4105-9d10-2b8038beb6ae",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note10",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
400,
928
],
"parameters": {
"color": 7,
"width": 384,
"height": 352,
"content": "### Portal Entry\n\nThis is the single entry point for the entire state management system. Any external event (a webhook, a form, another workflow) that needs to interact with a stateful session will call this trigger."
},
"typeVersion": 1
},
{
"id": "b6ca1d7e-b880-4cc0-bbfb-df910c968a6a",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
816,
688
],
"parameters": {
"color": 6,
"width": 352,
"height": 592,
"content": "### Session State Manager (Code)\n\nThis Code node is the brain of the portal. It uses **Workflow Static Data** (`$getWorkflowStaticData`) as a persistent, shared memory (a \"whiteboard\") to track all active sessions.\n\n**Technical Breakdown:**\n1. It receives a `session_id` and a `workflow_id`.\n2. It checks its whiteboard to see if an entry for `[workflow_id][session_id]` already exists.\n3. **If it exists (Existing Session):** It retrieves the stored `resume_url` and outputs `new: false`.\n4. **If it's new (New Session):** It stores the incoming `resume_url` and `execution_id` on the whiteboard and outputs `new: true`."
},
"typeVersion": 1
},
{
"id": "9d825e53-fe5b-4930-a6fa-075786dd161f",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note11",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1184,
800
],
"parameters": {
"color": 7,
"width": 304,
"height": 480,
"content": "### Route: New vs. Existing Session\n\nThis `IF` node directs traffic based on the output of the State Manager.\n\n- **True (Existing Session):** The flow proceeds to the 'Teleport' node to resume the paused process.\n- **False (New Session):** The flow proceeds to the 'Pass-through' nodes, which simply return the initial data back to the Main Process so it can start."
},
"typeVersion": 1
},
{
"id": "99c10763-a6fd-4a62-9046-b4853c50b013",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note12",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1856,
848
],
"parameters": {
"color": 7,
"width": 736,
"height": 368,
"content": "### Handle Teleport Error\n\nThis is a crucial safety feature. If the 'Teleport' action fails (e.g., the main execution was manually stopped and the `resume_url` is invalid), this branch is triggered.\n\nIt allows you to decide whether to stop the session entirely or to reset the state, allowing a new Main Process to begin for that `session_id`."
},
"typeVersion": 1
},
{
"id": "1c496a9e-0f6d-486b-8728-52800fd97f0b",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note14",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1504,
608
],
"parameters": {
"color": 7,
"width": 336,
"height": 464,
"content": "### TELEPORT: Resume Paused Process\n\nThis is the \"Teleport\" action. It's triggered only for existing sessions.\n\n**Technical Breakdown:**\nIt takes the `resume_url` retrieved by the State Manager and makes an HTTP POST request to it. This action wakes up the specific `Wait` node that is paused in the Main Process, effectively delivering the new data directly to the correct checkpoint."
},
"typeVersion": 1
},
{
"id": "1fee913a-2bc9-4295-83d3-33734b0dd9bb",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "5b. Send Back Data to Portal",
"type": "n8n-nodes-base.respondToWebhook",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2752,
48
],
"parameters": {
"options": {
"responseKey": "teleport_data"
},
"respondWith": "allIncomingItems"
},
"typeVersion": 1.4
},
{
"id": "d98a1678-d297-4cfe-9b3c-9f34b42279a5",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Response From Checkpoint",
"type": "n8n-nodes-base.if",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1296,
48
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "4e2a2496-c47a-4909-9a63-f92156484e9d",
"operator": {
"type": "array",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.teleport_data }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "78a48514-f755-482b-a138-904838d54108",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Split Out Teleported Items",
"type": "n8n-nodes-base.splitOut",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1584,
-304
],
"parameters": {
"options": {},
"fieldToSplitOut": "teleport_data"
},
"typeVersion": 1
},
{
"id": "b2e5b9f4-2111-40af-aced-19b7c84c0878",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "How to Test",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
-288,
-208
],
"parameters": {
"color": 5,
"width": 624,
"height": 704,
"content": "## How to Test This Workflow\n\nThis pattern requires a special testing method to see it in action.\n\n1. **Open Two Tabs:** Open this workflow in two separate browser tabs (let's call them **Tab A** and **Tab B**).\n\n2. **Start the First Session (Tab A):**\n - In **Tab A**, click **\"Execute Workflow\"** on the `1. Start Main Workflow` node.\n - Observe the execution. It will run until `4. PAUSE at Checkpoint 1` and the status will change to **\"Waiting\"**. This is your paused process.\n\n3. **Trigger the Teleport (Tab B):**\n - Now, go to **Tab B** and click **\"Execute Workflow\"** on the *same* `1. Start Main Workflow` node.\n\n4. **Observe the Magic:**\n - The execution in **Tab B** will be very short. The Portal will detect an existing session and \"teleport\" its data.\n - Instantly, the execution in **Tab A** will resume! It will pass Checkpoint 1, run through the `5a` and `5b` nodes, and then pause again at `6. PAUSE at Checkpoint 2`.\n\n5. **Resume the Final Checkpoint (Tab B again):**\n - In **Tab B**, click **\"Execute Workflow\"** one more time.\n\n6. **Observe the Completion:**\n - The execution in **Tab A** will now resume from Checkpoint 2 and run to completion.\n\n\nThis test proves how external events (from Tab B) can control and pass data to a long-running, paused process (in Tab A)."
},
"typeVersion": 1
},
{
"id": "c717aae2-6acd-4ab7-9be0-035ce1ec6f4d",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note15",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1232,
-544
],
"parameters": {
"color": 7,
"width": 736,
"height": 800,
"content": "### 2a. Handle Portal's Response\n\nThis `IF` node routes the initial execution.\n\n- **False Path (First Run):** When the Portal is first called, it confirms the session is new but sends no special data back. The workflow proceeds down the `false` path to begin its work.\n\n- **True Path (Data from Checkpoint):** If a checkpoint sends data back to the Portal (like Checkpoint 1 does), the Portal returns that data here. This path is for handling data that has been \"teleported\" from a checkpoint in another execution."
},
"typeVersion": 1
},
{
"id": "7947fc09-8c55-4c78-aecf-9f008ff357a7",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note16",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
1552,
-144
],
"parameters": {
"color": 7,
"width": 384,
"height": 368,
"content": "### 3. Process Initial Data\n\nThis is a placeholder for your own business logic. This is where you would perform the first set of actions in your process, like creating a user account, sending a welcome email, etc., before reaching the first checkpoint."
},
"typeVersion": 1
},
{
"id": "f9be8200-420d-4d4a-b964-f4abe544d68c",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note17",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
3328,
-176
],
"parameters": {
"color": 7,
"width": 320,
"height": 400,
"content": "### 7. Process Final Data\n\nThis represents the final steps of your process after all checkpoints have been passed. For example, this is where you would mark an order as 'complete' or send a final notification."
},
"typeVersion": 1
},
{
"id": "8909e76d-b953-44d0-a126-e422645862ec",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note18",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2000,
-464
],
"parameters": {
"color": 6,
"width": 1680,
"height": 720,
"content": "### Two Types of Checkpoints\n\nThis workflow demonstrates two different ways to use `Wait` nodes as checkpoints.\n\n- **Checkpoint 1 (Two-Way):** This `Wait` node has **`Response Mode`** set to `On Resume`. This means it can not only be resumed, but it can also **send data back** to the Portal that resumed it. This is useful for two-way communication.\n\n- **Checkpoint 2 (One-Way):** This `Wait` node has **`Response Mode`** set to `Never`. It can only be resumed; it **cannot send data back**. This is useful for simple, one-way continuation."
},
"typeVersion": 1
},
{
"id": "73a60499-87ad-4a91-9e9d-0c13bdb9d06e",
"cid": "Ikx1Y2FzIFBleXJpbiI",
"name": "Sticky Note20",
"type": "n8n-nodes-base.stickyNote",
"notes": "© 2025 Lucas Peyrin",
"creator": "Lucas Peyrin",
"position": [
2656,
320
],
"parameters": {
"color": 3,
"width": 540,
"height": 1280,
"content": "## Was this helpful? Let me know!\n[](https://n8n.ac)\n\nI really hope this utility helped you implement asynchronous workflows in n8n easily. Your feedback is incredibly valuable and helps me create better resources for the n8n community.\n\n### **Share Your Thoughts & Ideas**\n\nWhether you have a suggestion, found a typo, or just want to say thanks, I'd love to hear from you!\nHere's a simple n8n form built for this purpose:\n\n#### ➡️ **[Click here to give feedback](https://api.ia2s.app/form/templates/feedback?template=Async%20Portal)**\n\n### **Ready to Build Something Great?**\n\nIf you're looking to take your n8n skills or business automation to the next level, I can help.\n\n**🎓 n8n Coaching:** Want to become an n8n pro? I offer one-on-one coaching sessions to help you master workflows, tackle specific problems, and build with confidence.\n#### ➡️ **[Book a Coaching Session](https://api.ia2s.app/form/templates/coaching?template=Async%20Portal)**\n\n**💼 n8n Consulting:** Have a complex project, an integration challenge, or need a custom workflow built for your business? Let's work together to create a powerful automation solution.\n#### ➡️ **[Inquire About Consulting Services](https://api.ia2s.app/form/templates/consulting?template=Async%20Portal)**\n\n---\n\nHappy Automating!\nLucas Peyrin | [n8n Academy](https://n8n.ac)"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Reset Session": {
"main": [
[
{
"node": "Respond with Input Items",
"type": "main",
"index": 0
}
]
]
},
"2. Call Async Portal": {
"main": [
[
{
"node": "Response From Checkpoint",
"type": "main",
"index": 0
}
]
]
},
"F. Prepare Initial Data": {
"main": [
[
{
"node": "G. Return Data to Main Workflow",
"type": "main",
"index": 0
}
]
]
},
"Stop Session On Error ?": {
"main": [
[
{
"node": "E. Stop This Execution",
"type": "main",
"index": 0
}
],
[
{
"node": "Reset Session",
"type": "main",
"index": 0
}
]
]
},
"4. PAUSE at Checkpoint 1": {
"main": [
[
{
"node": "5a. Receive Resumed Data",
"type": "main",
"index": 0
}
]
]
},
"5a. Receive Resumed Data": {
"main": [
[
{
"node": "5b. Send Back Data to Portal",
"type": "main",
"index": 0
}
]
]
},
"6. PAUSE at Checkpoint 2": {
"main": [
[
{
"node": "7. Process Final Data (After Checkpoint 2)",
"type": "main",
"index": 0
}
]
]
},
"Respond with Input Items": {
"main": [
[
{
"node": "F. Prepare Initial Data",
"type": "main",
"index": 0
}
]
]
},
"Response From Checkpoint": {
"main": [
[
{
"node": "Split Out Teleported Items",
"type": "main",
"index": 0
}
],
[
{
"node": "3. Process Initial Data (Before Checkpoint 1)",
"type": "main",
"index": 0
}
]
]
},
"Send Items From Checkpoint": {
"main": [
[]
]
},
"5b. Send Back Data to Portal": {
"main": [
[
{
"node": "6. PAUSE at Checkpoint 2",
"type": "main",
"index": 0
}
]
]
},
"A. Entry: Receive Session Info": {
"main": [
[
{
"node": "B. Check if Session is New or Existing",
"type": "main",
"index": 0
}
]
]
},
"1. Start Main Workflow (Manual)": {
"main": [
[
{
"node": "2. Call Async Portal",
"type": "main",
"index": 0
}
]
]
},
"C. Route Based on Session State": {
"main": [
[
{
"node": "D. TELEPORT: Resume Paused Workflow",
"type": "main",
"index": 0
}
],
[
{
"node": "F. Prepare Initial Data",
"type": "main",
"index": 0
}
]
]
},
"Wait Node Sent Response Items ?": {
"main": [
[
{
"node": "Send Items From Checkpoint",
"type": "main",
"index": 0
}
],
[
{
"node": "E. Stop This Execution",
"type": "main",
"index": 0
}
]
]
},
"D. TELEPORT: Resume Paused Workflow": {
"main": [
[
{
"node": "Wait Node Sent Response Items ?",
"type": "main",
"index": 0
}
],
[
{
"node": "Stop Session On Error ?",
"type": "main",
"index": 0
}
]
]
},
"B. Check if Session is New or Existing": {
"main": [
[
{
"node": "C. Route Based on Session State",
"type": "main",
"index": 0
}
]
]
},
"3. Process Initial Data (Before Checkpoint 1)": {
"main": [
[
{
"node": "4. PAUSE at Checkpoint 1",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 工程
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
🎓 使用并行处理优化速度关键工作流(扇出-扇入)
🎓 使用并行处理(扇出/扇入)优化速度关键工作流
If
Set
Code
+10
34 节点Lucas Peyrin
工程
实时Notion Todoist双向同步模板
使用Redis的Notion Todoist实时双向同步
If
Set
Code
+26
246 节点Mario
销售
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
API架构提取器
API架构提取器
If
Set
Code
+22
88 节点Polina Medvedieva
工程
Overpass 潜在客户生成系统
使用 OpenStreetMap 数据生成商业线索并保存到 Google Sheets
If
Set
Code
+12
27 节点Akram Kadri
销售
基于Voyage-Context-3嵌入和MongoDB Atlas的文档问答系统
基于Voyage-Context-3嵌入和MongoDB Atlas的文档问答系统
Set
Code
Wait
+18
53 节点Jimleuk
工程
工作流信息
难度等级
高级
节点数量42
分类1
节点类型13
作者
Lucas Peyrin
@lucaspeyrinInnovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.
外部链接
在 n8n.io 查看 →
分享此工作流