Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 9, 2025

参考 coze, dify provider 以及 n8n 官方文档接口,增加 n8n provider。


Motivation / 动机

Enable n8n workflow automation integration with AstrBot, allowing users to trigger custom n8n workflows via webhooks and receive responses through the chatbot interface.

Modifications / 改动点

Core Implementation:

  • astrbot/core/utils/n8n_api_client.py: Lightweight HTTP client for webhook communication

    • GET/POST methods, streaming/non-streaming responses, SSE support
    • Lazy ClientSession initialization for proper async handling
    • Custom authentication headers
  • astrbot/core/provider/sources/n8n_source.py: Provider adapter implementing full Provider interface

    • Configurable input/output key mappings for workflow flexibility
    • Session management, multimodal support (text/images)
    • Intelligent response parsing (string/object/array/media objects)

Integration:

  • astrbot/core/provider/manager.py: Provider registration
  • dashboard/src/views/ProviderPage.vue: Type mapping
  • dashboard/src/utils/providerUtils.js: Provider icon
  • tests/test_n8n_provider.py: 13 unit tests covering initialization, methods, parsing

Documentation:

  • Updated README.md, README_en.md with n8n provider listing
  • Added docs/n8n_provider_implementation.md with configuration guide

Configuration example:

{
  "type": "n8n",
  "id": "my_workflow",
  "enable": true,
  "n8n_webhook_url": "https://n8n.example.com/webhook/abc123",
  "n8n_http_method": "POST",
  "n8n_auth_header": "Authorization",
  "n8n_auth_value": "Bearer token",
  "n8n_output_key": "output",
  "n8n_input_key": "input",
  "timeout": 120,
  "variables": {"key": "value"}
}

Verification Steps / 验证步骤

  1. Run tests: uv run pytest tests/test_n8n_provider.py -v
  2. Verify import: uv run python -c "from astrbot.core.provider.sources.n8n_source import ProviderN8n"
  3. Check provider registration: uv run python -c "from astrbot.core.provider.register import provider_cls_map; print('n8n' in provider_cls_map)"
  4. Add n8n provider configuration in WebUI with a test webhook URL
  5. Send message to trigger workflow execution

Screenshots or Test Results / 运行截图或测试结果

================================================= test session starts ==================================================
tests/test_n8n_provider.py::TestN8nProvider::test_provider_registration PASSED                                   [  7%]
tests/test_n8n_provider.py::TestN8nProvider::test_provider_initialization_missing_url PASSED                     [ 15%]
tests/test_n8n_provider.py::TestN8nProvider::test_provider_initialization_invalid_method PASSED                  [ 23%]
tests/test_n8n_provider.py::TestN8nProvider::test_provider_initialization_success PASSED                         [ 30%]
tests/test_n8n_provider.py::TestN8nProvider::test_provider_default_values PASSED                                 [ 38%]
tests/test_n8n_provider.py::TestN8nProvider::test_get_models PASSED                                              [ 46%]
tests/test_n8n_provider.py::TestN8nProvider::test_get_current_key PASSED                                         [ 53%]
tests/test_n8n_provider.py::TestN8nProvider::test_set_key_raises_exception PASSED                                [ 61%]
tests/test_n8n_provider.py::TestN8nProvider::test_forget PASSED                                                  [ 69%]
tests/test_n8n_provider.py::TestN8nProvider::test_terminate PASSED                                               [ 76%]
tests/test_n8n_provider.py::TestN8nProvider::test_parse_n8n_result_string PASSED                                 [ 84%]
tests/test_n8n_provider.py::TestN8nProvider::test_parse_n8n_result_dict_with_output PASSED                       [ 92%]
tests/test_n8n_provider.py::TestN8nProvider::test_parse_n8n_result_dict_without_output_key PASSED                [100%]

================================================== 13 passed in 2.34s ==================================================

CodeQL Security Scan:

Analysis Result for 'python, javascript'. Found 0 alerts:
- **python**: No alerts found.
- **javascript**: No alerts found.

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

This is a purely additive change. New provider type with no impact on existing providers or configurations.


Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.
Original prompt

参考 coze, dify provider 以及 n8n 官方文档接口,增加n8n provider。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 9, 2025
Copilot AI changed the title [WIP] Add n8n provider based on coze and dify specifications Add n8n workflow provider with webhook-based execution Nov 9, 2025
Copilot AI requested a review from Soulter November 9, 2025 18:15
Copilot finished work on behalf of Soulter November 9, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants