| name | openclaw-dify-workflow-skill |
| description | Dify + n8n 铻嶅悎宸ヤ綔娴佸钩鍙般€侱ify 鐨?LLM 鑳藉姏 + n8n 鐨勮嚜鍔ㄥ寲缂栨帓锛屾敮鎸佸瑙﹀彂鍣ㄣ€佽妭鐐规帶鍒舵祦銆佸嚟璇佺鐞嗐€?homepage: https://dify.ai |
Dify + n8n 铻嶅悎宸ヤ綔娴佸钩鍙?
Dify 鐨?LLM 鑳藉姏 + n8n 鐨勮嚜鍔ㄥ寲缂栨帓 = 寮哄ぇ鐨勫伐浣滄祦骞冲彴
鏍稿績鐗规€?
| 鐗规€? | Dify | n8n | 鏈瀺鍚堝钩鍙? |
|---|
| LLM 宸ヤ綔娴? | 鉁? | 猬? | 鉁? |
| 澶氳Е鍙戝櫒 | 猬? | 鉁? | 鉁? |
| 鑺傜偣缂栨帓 | 猬? | 鉁? | 鉁? |
| 鏉′欢鍒嗘敮 | 猬? | 鉁? | 鉁? |
| 寰幆澶勭悊 | 猬? | 鉁? | 鉁? |
| 鍑瘉绠$悊 | 猬? | 鉁? | 鉁? |
| 閿欒澶勭悊 | 猬? | 鉁? | 鉁? |
鏋舵瀯姒傝
鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹?鈹? 瑙﹀彂鍣ㄥ眰 (Triggers) 鈹?鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹?鈹? 鈹?Webhook 鈹? 鈹?Schedule鈹? 鈹? Event 鈹? 鈹? Manual 鈹? 鈹?鈹? 鈹?澶栭儴HTTP 鈹? 鈹?Cron瀹氭椂 鈹? 鈹?浜嬩欢鐩戝惉 鈹? 鈹?鎵嬪姩瑙﹀彂 鈹? 鈹?鈹? 鈹斺攢鈹€鈹€鈹€鈹攢鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹攢鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹攢鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹攢鈹€鈹€鈹€鈹? 鈹?鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹尖攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹尖攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹尖攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹尖攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹粹攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹粹攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹? 鈻?鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹?鈹? 宸ヤ綔娴佸紩鎿?(Workflow Engine) 鈹?鈹? 鈹?鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹?鈹? 鈹? Condition 鈹傗攢鈹€鈹€鈻垛攤 Loop 鈹傗攢鈹€鈹€鈻垛攤 Dify Node 鈹? 鈹?鈹? 鈹? 鏉′欢鍒嗘敮 鈹? 鈹? 寰幆 鈹? 鈹? LLM璋冪敤 鈹? 鈹?鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹?鈹? 鈹? 鈹?鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹? 鈹?鈹? 鈹? HTTP Node 鈹傗梹鈹€鈹€鈹€鈹?Error Handler鈹傗梹鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹?鈹? 鈹? HTTP璇锋眰 鈹? 鈹? 閿欒澶勭悊 鈹? 鈹?鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹?鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹? 鈹? 鈻?鈹屸攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹?鈹? 鍑瘉绠$悊 (Credentials) 鈹?鈹? Dify API / SMTP / HTTP Auth / OAuth2 / Database ... 鈹?鈹斺攢鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹€鈹?```
## 蹇€熷紑濮?
### 1. 鐜閰嶇疆
```bash
# Dify 閰嶇疆
export DIFY_BASE_URL="https://api.dify.ai/v1"
export DIFY_API_KEY="your-dify-api-key"
# Webhook 瀹夊叏锛堝彲閫夛級
export N8N_WEBHOOK_SECRET="your-webhook-secret"
2. 鍚姩鏈嶅姟
from openclaw_dify_workflow_skill import WorkflowPlatform
3. 鎵ц宸ヤ綔娴?
workflow_id="hello_world",
trigger_data={"name": "OpenClaw"}
)
print(result)
瑙﹀彂鍣ㄧ被鍨?
1. Webhook 瑙﹀彂鍣?
鎺ユ敹 HTTP 璇锋眰瑙﹀彂宸ヤ綔娴侊細
workflows:
my_webhook_flow:
name: "Webhook 绀轰緥"
trigger:
type: "webhook"
path: "/my-webhook"
method: "POST"
nodes:
- id: "process"
type: "dify_workflow"
config:
app_id: "my_app"
inputs:
data: "{{$trigger.body}}"
**瑙﹀彂 URL**锛?```bash
curl -X POST http://localhost:5678/webhook/my-webhook \
-H "Content-Type: application/json" \
-d '{"name": "test"}'
2. 瀹氭椂瑙﹀彂鍣?(Cron)
workflows:
daily_report:
name: "姣忔棩鎶ュ憡"
trigger:
type: "schedule"
cron: "0 9 * * *"
nodes:
- id: "generate"
type: "dify_workflow"
config:
app_id: "report_generator"
3. 鎵嬪姩瑙﹀彂鍣?
workflows:
adhoc_task:
name: "涓存椂浠诲姟"
trigger:
type: "manual"
nodes: [...]
鑺傜偣绫诲瀷
Dify 鑺傜偣
**宸ヤ綔娴佽妭鐐?*锛?```yaml
- id: "dify_workflow_1"
type: "dify_workflow"
name: "鐢熸垚鍐呭"
config:
app_id: "my_workflow"
inputs:
query: "{{$trigger.body.query}}"
style: "professional"
**瀵硅瘽鑺傜偣**锛?```yaml
- id: "dify_chat_1"
type: "dify_chat"
name: "鏅鸿兘瀵硅瘽"
config:
app_id: "my_chatbot"
query: "{{$trigger.body.question}}"
conversation_id: "{{$vars.conv_id}}"
鏉′欢鑺傜偣 (IF/ELSE)
- id: "check_condition"
type: "condition"
name: "妫€鏌ユ潯浠?
conditions:
- id: "is_vip"
rules:
- left: "{{$trigger.body.user_type}}"
operator: "eq"
right: "vip"
- id: "has_high_score"
rules:
- left: "{{$trigger.body.score}}"
operator: "gt"
right: "80"
logic: "and"
branches:
- condition: "is_vip"
nodes:
- id: "vip_service"
type: "dify_chat"
config:
query: "鎻愪緵VIP鏈嶅姟"
- condition: "has_high_score"
nodes:
- id: "reward"
type: "http_request"
config:
url: "https://api.example.com/reward"
- condition: "else"
nodes:
- id: "normal_service"
type: "dify_chat"
config:
query: "鏅€氭湇鍔?
鏀寔鐨勮繍绠楃锛?- eq - 绛変簬
ne - 涓嶇瓑浜?- gt - 澶т簬
lt - 灏忎簬
gte - 澶т簬绛変簬
lte - 灏忎簬绛変簬
contains - 鍖呭惈
starts_with - 寮€澶存槸
ends_with - 缁撳熬鏄?- regex - 姝e垯鍖归厤
exists - 瀛樺湪
empty - 涓虹┖
寰幆鑺傜偣
- id: "process_items"
type: "loop"
name: "澶勭悊鍒楄〃"
config:
type: "for_each"
items: "{{$trigger.body.items}}"
max_iterations: 100
loop_body:
- id: "process_single"
type: "dify_workflow"
config:
inputs:
item: "{{process_items.current}}"
- id: "save_result"
type: "http_request"
config:
method: "POST"
url: "https://api.example.com/save"
body: "{{process_single.outputs}}"
HTTP 璇锋眰鑺傜偣
- id: "call_api"
type: "http_request"
name: "璋冪敤澶栭儴API"
config:
method: "POST"
url: "https://api.example.com/data"
headers:
Authorization: "Bearer {{$env.API_TOKEN}}"
Content-Type: "application/json"
body:
data: "{{$trigger.body}}"
source: "dify_workflow"
timeout: 30
绛夊緟鑺傜偣
- id: "wait_a_moment"
type: "wait"
name: "绛夊緟"
config:
seconds: 5
閿欒澶勭悊
鑺傜偣绾ч敊璇鐞?
- id: "risky_operation"
type: "dify_workflow"
name: "椋庨櫓鎿嶄綔"
config:
app_id: "unstable_api"
on_error:
strategy: "retry"
max_retries: 3
retry_interval: 5
fallback:
type: "dify_workflow"
config:
app_id: "stable_backup"
- id: "notify_admin"
type: "http_request"
config:
method: "POST"
url: "{{$env.WEBHOOK_URL}}"
body:
text: "涓绘湇鍔″け璐ワ紝宸插垏鎹㈠鐢ㄦ柟妗?
鍑瘉绠$悊
閰嶇疆鍑瘉
workflow_platform:
credentials:
dify_production:
type: "dify_api"
data:
api_key: "app-xxxxxx"
base_url: "https://api.dify.ai/v1"
smtp_gmail:
type: "smtp"
data:
host: "smtp.gmail.com"
port: 587
user: "{{$env.GMAIL_USER}}"
password: "{{$env.GMAIL_PASS}}"
internal_api:
type: "http_header"
data:
headers:
X-API-Key: "{{$env.INTERNAL_API_KEY}}"
test_url: "https://internal.api/health"
鏀寔鐨勫嚟璇佺被鍨?
| 绫诲瀷 | 璇存槑 | 瀛楁 |
|---|
dify_api | Dify API Key | api_key, base_url |
http_basic | HTTP Basic Auth | username, password |
http_header | HTTP Header Auth | headers |
oauth2 | OAuth2 | client_id, client_secret, access_token |
smtp | SMTP 閭欢 | host, port, user, password |
postgres | PostgreSQL | host, port, database, user, password |
鍦ㄨ妭鐐逛腑浣跨敤鍑瘉
- id: "send_email"
type: "smtp"
credential: "smtp_gmail"
config:
to: "user@example.com"
subject: "宸ヤ綔娴佺粨鏋?
body: "{{previous_node.outputs}}"
鍙橀噺寮曠敤璇硶
瑙﹀彂鍣ㄦ暟鎹?
"{{$trigger.body.name}}"
"{{$trigger.query.id}}"
"{{$trigger.headers.authorization}}"
鐜鍙橀噺
"{{$env.DIFY_API_KEY}}"
"{{$env.HOSTNAME}}"
鑺傜偣杈撳嚭
"{{node_id.outputs.result}}"
"{{node_id.outputs.tokens}}"
"{{node_id.answer}}"
```yaml
"{{loop_id.current}}"
"{{loop_id.total}}"
"{{loop_id.count}}"
```yaml
workflows:
smart_customer_service:
name: "鏅鸿兘瀹㈡湇"
description: "鑷姩澶勭悊瀹㈡埛鍜ㄨ"
trigger:
type: "webhook"
path: "/customer-service"
nodes:
- id: "classify"
type: "dify_workflow"
name: "闂鍒嗙被"
config:
app_id: "classifier"
inputs:
query: "{{$trigger.body.message}}"
- id: "route"
type: "condition"
name: "璺敱"
conditions:
- id: "is_technical"
rules:
- left: "{{classify.outputs.category}}"
operator: "eq"
right: "technical"
- id: "is_sales"
rules:
- left: "{{classify.outputs.category}}"
operator: "eq"
right: "sales"
branches:
- condition: "is_technical"
nodes:
- id: "tech_support"
type: "dify_chat"
config:
app_id: "tech_bot"
query: "{{$trigger.body.message}}"
- condition: "is_sales"
nodes:
- id: "sales_support"
type: "dify_chat"
config:
app_id: "sales_bot"
query: "{{$trigger.body.message}}"
- condition: "else"
nodes:
- id: "general_support"
type: "dify_chat"
config:
app_id: "general_bot"
query: "{{$trigger.body.message}}"
- id: "log_crm"
type: "http_request"
name: "璁板綍CRM"
config:
method: "POST"
url: "https://crm.example.com/logs"
headers:
Authorization: "Bearer {{$env.CRM_TOKEN}}"
body:
customer: "{{$trigger.body.customer_id}}"
message: "{{$trigger.body.message}}"
response: "{{route.outputs.answer}}"
category: "{{classify.outputs.category}}"
on_error:
strategy: "continue"
output:
answer: "{{route.outputs.answer}}"
category: "{{classify.outputs.category}}"
handled_at: "{{$env.CURRENT_TIME}}"
鎵归噺澶勭悊宸ヤ綔娴?
workflows:
batch_processor:
name: "鎵归噺鏂囨。澶勭悊"
trigger:
type: "webhook"
nodes:
- id: "validate_input"
type: "condition"
conditions:
- id: "has_documents"
rules:
- left: "{{$trigger.body.documents}}"
operator: "exists"
branches:
- condition: "has_documents"
nodes:
- id: "process_docs"
type: "loop"
config:
type: "for_each"
items: "{{$trigger.body.documents}}"
loop_body:
- id: "analyze"
type: "dify_workflow"
config:
app_id: "doc_analyzer"
inputs:
doc_url: "{{process_docs.current.url}}"
- id: "store_result"
type: "http_request"
config:
method: "POST"
url: "https://db.example.com/results"
body:
doc_id: "{{process_docs.current.id}}"
analysis: "{{analyze.outputs}}"
- condition: "else"
nodes:
- id: "error_response"
type: "dify_chat"
config:
query: "璇锋彁渚涙枃妗e垪琛?
output:
processed: "{{process_docs.count}}"
results: "{{process_docs.results}}"
API 鍙傝€?
鎵ц宸ヤ綔娴?
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
result = p.execute_workflow('my_workflow', {'name': 'test'})
print(result)
"
绠$悊鍑瘉
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
print(p.list_credentials())
"
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
print(p.test_credential('dify_production'))
"
Webhook 绠$悊
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
print(p.get_webhook_url('my_webhook_flow'))
"
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
result = p.trigger_webhook('my_webhook_flow', {'test': 'data'})
print(result)
"
鐩綍缁撴瀯
openclaw-dify-workflow-skill/
鈹溾攢鈹€ config/
鈹? 鈹斺攢鈹€ config.yaml # 閰嶇疆鏂囦欢
鈹溾攢鈹€ adapters/
鈹? 鈹斺攢鈹€ dify.py # Dify 閫傞厤鍣?鈹溾攢鈹€ engine/
鈹? 鈹溾攢鈹€ node_engine.py # 鑺傜偣鎵ц寮曟搸
鈹? 鈹溾攢鈹€ webhook_server.py # Webhook 鏈嶅姟
鈹? 鈹斺攢鈹€ credentials.py # 鍑瘉绠$悊
鈹溾攢鈹€ scripts/
鈹? 鈹斺攢鈹€ agent.py # CLI 宸ュ叿
鈹溾攢鈹€ SKILL.md # 鏈枃妗?鈹斺攢鈹€ __init__.py # 鏍稿績骞冲彴绫?```
## 鏁呴殰鎺掓煡
### 妫€鏌ュ钩鍙扮姸鎬?
```bash
python -c "
from openclaw_dify_workflow_skill import WorkflowPlatform
p = WorkflowPlatform()
print(p.health_check())
"
甯歌闂
| 闂 | 鍘熷洜 | 瑙e喅 |
|---|
| Webhook 鏃犳硶璁块棶 | 绔彛琚崰鐢? | 淇敼 triggers.webhook.port |
| 鍑瘉娴嬭瘯澶辫触 | 鐜鍙橀噺鏈缃? | 妫€鏌?$env.XXX 寮曠敤 |
| 鍙橀噺瑙f瀽澶辫触 | 璇硶閿欒 | 纭繚浣跨敤 {{$trigger.xxx}} 鏍煎紡 |
| 寰幆涓嶆墽琛? | items 涓嶆槸鏁扮粍 | 妫€鏌ヤ紶鍏ユ暟鎹牸寮? |
| 鏉′欢鍒ゆ柇閿欒 | 杩愮畻绗︿笉鏀寔 | 浣跨敤鏀寔鐨勮繍绠楃鍒楄〃 |
涓庡師鐗?n8n 鐨勫尯鍒?
| 鐗规€? | n8n | 鏈瀺鍚堝钩鍙? |
|---|
| 鍙鍖栫紪杈戝櫒 | 鉁?鏈? | 猬?閰嶇疆鏂囦欢 |
| 鑷墭绠? | 鉁? | 鉁? |
| LLM 鑺傜偣 | 鈿狅笍 闇€閰嶇疆 | 鉁?鍐呯疆 Dify |
| 鑺傜偣绫诲瀷 | 400+ | 鏍稿績鑺傜偣 + Dify |
| 绀惧尯鐢熸€? | 涓板瘜 | 涓撴敞 LLM 宸ヤ綔娴? |
閫傚悎鍦烘櫙锛?- 闇€瑕?LLM 鑳藉姏鐨勮嚜鍔ㄥ寲宸ヤ綔娴?- 宸叉湁 Dify 搴旂敤闇€瑕佺紪鎺?- 鍋忓ソ浠g爜/閰嶇疆绠$悊