Skip to content

Add N8n integration with models, services, and routes #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025

Conversation

gomessguii
Copy link
Contributor

@gomessguii gomessguii commented May 14, 2025

Add N8n integration with models, services, and routes

  • Introduced N8n and N8nSetting models in both MySQL and PostgreSQL schemas.
  • Implemented N8nController and N8nService for managing N8n bots.
  • Created N8nRouter for handling API requests related to N8n.
  • Added DTOs and validation schemas for N8n integration.
  • Updated server module and chatbot controller to include N8n functionality.
  • Configured environment settings for N8n integration.

Summary by Sourcery

Add a full N8n integration by defining database models, controllers, services, routes, DTOs, and validation schemas, wire them into the chatbot framework, and expose configuration to toggle the feature.

New Features:

  • Introduce N8nController, N8nService, and N8nRouter to manage N8n bots, settings, and sessions via REST endpoints
  • Add N8n and N8nSetting models with corresponding Prisma schema and migrations for MySQL and PostgreSQL
  • Create DTOs and JSON validation schemas for N8n integration payloads and settings
  • Extend ChatbotController, server module, and routers to emit and handle N8n workflow events
  • Add environment variable support to enable or disable N8n integration

Enhancements:

  • Reformat NodeCache initialization in the WhatsApp Baileys service

- Introduced N8n and N8nSetting models in both MySQL and PostgreSQL schemas.
- Implemented N8nController and N8nService for managing N8n bots.
- Created N8nRouter for handling API requests related to N8n.
- Added DTOs and validation schemas for N8n integration.
- Updated server module and chatbot controller to include N8n functionality.
- Configured environment settings for N8n integration.
Copy link
Contributor

sourcery-ai bot commented May 14, 2025

Reviewer's Guide

This PR adds full N8n integration by introducing database models and migrations, extending configuration, wiring new controllers and services into the chatbot flow, and providing routes along with DTOs and validation schemas.

File-Level Changes

Change Details Files
Introduce N8n integration configuration
  • Define N8n type in Env interface
  • Load N8N_ENABLED flag in ConfigService defaults
src/config/env.config.ts
Register N8n service and controller in server module
  • Instantiate N8nService and expose N8nController
  • Invoke n8nController.emit in ChatbotController workflow
src/api/server.module.ts
src/api/integrations/chatbot/chatbot.controller.ts
Extend Chatbot routing to include N8n endpoints
  • Import N8nRouter and mount '/n8n' path
  • Export N8n validation schema in chatbot.Schema
src/api/integrations/chatbot/chatbot.router.ts
src/api/integrations/chatbot/chatbot.schema.ts
Add Prisma schemas and migration for N8n entities
  • Define N8n and N8nSetting models in MySQL and PostgreSQL schemas
  • Add SQL migration with tables, indices and foreign keys
prisma/mysql-schema.prisma
prisma/postgresql-schema.prisma
prisma/postgresql-migrations/20250514232744_add_n8n_table/migration.sql
Implement N8nController handling CRUD and sessions
  • Extend ChatbotController to manage bots, settings and sessions
  • Enforce integration flag and repository validations
src/api/integrations/chatbot/n8n/controllers/n8n.controller.ts
Develop N8nService for business logic and webhook communication
  • Implement CRUD operations for N8n bots
  • Handle webhook calls, message parsing and session lifecycle
src/api/integrations/chatbot/n8n/services/n8n.service.ts
Define DTOs and validation schemas for N8n routes
  • Add N8nDto, N8nSettingDto and related classes
  • Create JSON schemas for bot, settings, status and ignoreJid
src/api/integrations/chatbot/n8n/dto/n8n.dto.ts
src/api/integrations/chatbot/n8n/validate/n8n.schema.ts
Minor code formatting adjustments in existing service
  • Fix indentation in userDevicesCache instantiation
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

gomessguii and others added 2 commits May 14, 2025 20:50
…, and enhance service logic

- Added export for N8n schema in chatbot.schema.ts.
- Improved import order in n8n.dto.ts and n8n.router.ts for better readability.
- Refactored variable declarations in n8n.service.ts for consistency and clarity.
@DavidsonGomes DavidsonGomes merged commit 0fd2e04 into EvolutionAPI:develop May 15, 2025
1 check passed
@muava12
Copy link

muava12 commented Jun 21, 2025

need more detail documentation for this update

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.

3 participants