Skip to content

Conversation

@jamesjhonatan123
Copy link

@jamesjhonatan123 jamesjhonatan123 commented Nov 19, 2025

📋 Description
This PR addresses an issue where the quotedMessage information was missing from the payload sent to N8N webhooks. When a user replied to a message, the N8N workflow received the new message content but lacked the context of the quoted message, unlike the standard webhook behavior.

This change adds the quotedMessage field to the N8N payload, extracting it from msg.contextInfo.quotedMessage, ensuring that workflows can properly handle replies and context.

🧪 Type of Change
✨ New feature (non-breaking change which adds functionality)
Manual testing completed
Functionality verified in development environment and production environment
No breaking changes introduced
Tested with different connection types (if applicable)
Testing Details:
Verified that when a message is replied to in WhatsApp, the N8N webhook now receives the quotedMessage object containing the original message content.

📸 Screenshots (if applicable)
Captura de tela de 2025-11-19 00-00-15

✅ Checklist
My code follows the project's style guidelines
I have performed a self-review of my code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
My changes generate no new warnings
I have manually tested my changes thoroughly
I have verified the changes work with different scenarios
Any dependent changes have been merged and published
📝 Additional Notes
This aligns the N8N integration payload more closely with the standard webhook payload regarding quoted messages.

Summary by Sourcery

Enable N8N workflows to receive quoted message context when relaying WhatsApp replies and clean up code formatting in the proxy agent utility.

New Features:

  • Include the quotedMessage field from msg.contextInfo in the payload sent to N8N webhooks

Enhancements:

  • Standardize formatting and semicolon usage in the makeProxyAgent implementation with no functional changes

Copilot AI review requested due to automatic review settings November 19, 2025 03:05
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures that when handling WhatsApp message replies, the original quoted message context is propagated through the N8N integration by extracting and including the quotedMessage field in the webhook payload, while also standardizing code style in the proxy agent utility.

Sequence diagram for WhatsApp reply message payload to N8N webhook

sequenceDiagram
    participant User as actor User
    participant WhatsApp
    participant "Chatbot Service"
    participant N8N
    User->>WhatsApp: Reply to a message
    WhatsApp->>"Chatbot Service": Send message with contextInfo.quotedMessage
    "Chatbot Service"->>N8N: Send webhook payload (includes quotedMessage)
    N8N->>"Chatbot Service": Process payload (now with quotedMessage)
Loading

Class diagram for updated N8nService payload structure

classDiagram
    class N8nService {
        +sendWebhookPayload(msg, instance)
    }
    class Message {
        +key
        +contextInfo
    }
    class ContextInfo {
        +quotedMessage
    }
    N8nService --> Message : uses
    Message --> ContextInfo : has
    ContextInfo : quotedMessage
Loading

File-Level Changes

Change Details Files
Include quotedMessage in N8N webhook payload
  • Extract quotedMessage from msg.contextInfo
  • Add quotedMessage property to payload object
src/api/integrations/chatbot/n8n/services/n8n.service.ts
Standardize formatting and semicolon usage in proxy agent utility
  • Add missing semicolons after declarations
  • Reformat import and variable declarations for consistency
src/utils/makeProxyAgent.ts

Possibly linked issues

  • #Issue-1: PR ensures N8N webhooks receive quoted message context, directly addressing the reported N8N automation breakdown.

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/utils/makeProxyAgent.ts:63-64` </location>
<code_context>

-    const auth = username && password ? `${username}:${password}@` : ''
-    proxyUrl = `${protocol}://${auth}${host}:${port}`
+    const auth = username && password ? `${username}:${password}@` : '';
+    proxyUrl = `${protocol}://${auth}${host}:${port}`;
   }
</code_context>

<issue_to_address>
**suggestion:** Authentication string construction may not handle special characters in username or password.

Encoding the username and password will prevent malformed URLs when special characters are present.

```suggestion
    const encodedUsername = username ? encodeURIComponent(username) : '';
    const encodedPassword = password ? encodeURIComponent(password) : '';
    const auth = encodedUsername && encodedPassword ? `${encodedUsername}:${encodedPassword}@` : '';
    proxyUrl = `${protocol}://${auth}${host}:${port}`;
```
</issue_to_address>

### Comment 2
<location> `src/utils/makeProxyAgent.ts:79-80` </location>
<code_context>

     default:
-      throw new Error(`Unsupported proxy protocol: ${protocol}`)
+      throw new Error(`Unsupported proxy protocol: ${protocol}`);
   }
 }
</code_context>

<issue_to_address>
**suggestion:** Error message could include the original input for better debugging.

Adding the full proxy input to the error message will make it easier to diagnose issues with malformed or unexpected input.

```suggestion
    default:
      throw new Error(`Unsupported proxy protocol: ${protocol}. Full proxy input: ${typeof proxy === 'string' ? proxy : JSON.stringify(proxy)}`);
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +63 to +64
const auth = username && password ? `${username}:${password}@` : '';
proxyUrl = `${protocol}://${auth}${host}:${port}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Authentication string construction may not handle special characters in username or password.

Encoding the username and password will prevent malformed URLs when special characters are present.

Suggested change
const auth = username && password ? `${username}:${password}@` : '';
proxyUrl = `${protocol}://${auth}${host}:${port}`;
const encodedUsername = username ? encodeURIComponent(username) : '';
const encodedPassword = password ? encodeURIComponent(password) : '';
const auth = encodedUsername && encodedPassword ? `${encodedUsername}:${encodedPassword}@` : '';
proxyUrl = `${protocol}://${auth}${host}:${port}`;


default:
throw new Error(`Unsupported proxy protocol: ${protocol}`)
throw new Error(`Unsupported proxy protocol: ${protocol}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Error message could include the original input for better debugging.

Adding the full proxy input to the error message will make it easier to diagnose issues with malformed or unexpected input.

Suggested change
default:
throw new Error(`Unsupported proxy protocol: ${protocol}`)
throw new Error(`Unsupported proxy protocol: ${protocol}`);
default:
throw new Error(`Unsupported proxy protocol: ${protocol}. Full proxy input: ${typeof proxy === 'string' ? proxy : JSON.stringify(proxy)}`);

Copilot finished reviewing on behalf of jamesjhonatan123 November 19, 2025 03:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for quoted message context in N8N webhook payloads. When a user replies to a message in WhatsApp, the N8N workflow now receives the quotedMessage field containing the original message content, aligning the N8N integration with standard webhook behavior.

  • Adds quotedMessage field to N8N webhook payload extracted from msg.contextInfo.quotedMessage
  • Includes code formatting improvements (semicolon additions) in makeProxyAgent.ts

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/utils/makeProxyAgent.ts Code formatting improvements - added missing semicolons throughout the file for consistency
src/api/integrations/chatbot/n8n/services/n8n.service.ts Added quotedMessage field to the N8N webhook payload to provide reply context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DavidsonGomes DavidsonGomes changed the base branch from main to develop November 19, 2025 20:45
} else {
const { host, password, port, protocol: proto, username } = proxy
protocol = (proto || 'http').replace(':', '')
const { host, password, port, protocol: proto, username } = proxy;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
} else {
const { host, password, port, protocol: proto, username } = proxy
protocol = (proto || 'http').replace(':', '')
const { host, password, port, protocol: proto, username } = proxy;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
} else {
const { host, password, port, protocol: proto, username } = proxy
protocol = (proto || 'http').replace(':', '')
const { host, password, port, protocol: proto, username } = proxy;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
} else {
const { host, password, port, protocol: proto, username } = proxy
protocol = (proto || 'http').replace(':', '')
const { host, password, port, protocol: proto, username } = proxy;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
} else {
const { host, password, port, protocol: proto, username } = proxy
protocol = (proto || 'http').replace(':', '')
const { host, password, port, protocol: proto, username } = proxy;

Check failure

Code scanning / CodeQL

Insecure randomness High

This uses a cryptographically insecure random number generated at
Math.random()
in a security context.
@DavidsonGomes
Copy link
Collaborator

fix the lint please, use npm run lint

@jamesjhonatan123
Copy link
Author

jamesjhonatan123 commented Nov 19, 2025

I ran npm run lint and fixed all lint issues — that’s why the changes above appeared.

In that specific section:

image
module.exports = {
  semi: true,
  trailingComma: 'all',
  singleQuote: true,
  printWidth: 120,
  arrowParens: 'always',
  tabWidth: 2,
  useTabs: false,
  bracketSameLine: false,
  bracketSpacing: true,
  parser: 'typescript'
}

The project’s ESLint config has "semi": true, so semicolons are required.

image

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