Skip to content

feat: add limit sharing privacy toggle - #2625

Draft
piwel wants to merge 2 commits into
evolution-foundation:developfrom
piwel:codex/add-limit-sharing-privacy
Draft

piwel wants to merge 2 commits into
evolution-foundation:developfrom
piwel:codex/add-limit-sharing-privacy

Conversation

@piwel

@piwel piwel commented Jul 3, 2026 •

Copy link
Copy Markdown

📋 Description

Adds a chat API endpoint to toggle WhatsApp Advanced Chat Privacy / Limit Sharing for a chat or group.

Baileys already supports sending { limitSharing: boolean } and emits a LIMIT_SHARING protocol message. This change exposes that capability through Evolution API with request DTO and JSON schema validation.

Endpoint:

POST /chat/updateLimitSharing/{instance}

Payload:

{
  "chat": "120363000000000000@g.us",
  "limitSharing": true
}

🔗 Related Issue

N/A

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Configuration change
  • ♻️ Code refactoring
  • ⚡ Performance improvement
  • 🧪 Test improvement

🧪 Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

Validation performed:

npm ci --cache /private/tmp/npm-cache-apgl
cp .env.example .env
./Docker/scripts/generate_database.sh
npm run build
npm run lint:check

📸 Screenshots (if applicable)

N/A

✅ Checklist

  • My code follows the project's coding standards
  • 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 that my changes work with different scenarios
  • Any dependent changes have been merged and published

📝 Additional Notes

No live WhatsApp account manual test was performed from this checkout. Existing npm install audit/deprecation warnings are unrelated to this change.

Summary by Sourcery

Expose WhatsApp Advanced Chat Privacy controls through a validated chat API endpoint.

New Features:

  • Add an endpoint to enable or disable WhatsApp Advanced Chat Privacy (Limit Sharing) for chats and groups.
  • Expose the requested privacy state and resulting chat message in the API response.

@sourcery-ai

sourcery-ai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a guarded POST endpoint that validates a chat and boolean limit-sharing flag, forwards the toggle as a Baileys WhatsApp message, and returns structured success or internal-error responses.

Sequence diagram for the limit-sharing chat update

sequenceDiagram
    actor Client
    participant Router as ChatRouter
    participant Controller as ChatController
    participant Service as BaileysStartupService
    participant WhatsApp as BaileysWhatsApp

    Client->>Router: POST /chat/updateLimitSharing/{instance}
    Router->>Router: dataValidate(request, limitSharingSchema)
    Router->>Controller: updateLimitSharing(instanceName, data)
    Controller->>Service: updateLimitSharing(data)
    Service->>Service: createJid(data.chat)
    Service->>WhatsApp: sendMessage(remoteJid, limitSharing)
    WhatsApp-->>Service: response
    Service-->>Controller: chatId, limitSharing, message
    Controller-->>Client: 201 Created
Loading

Flow diagram for limit-sharing validation and error handling

flowchart TD
    A[POST updateLimitSharing] --> B{Valid chat and boolean limitSharing?}
    B -->|No| C[Validation error]
    B -->|Yes| D[Baileys sendMessage]
    D -->|Success| E[Return chatId, limitSharing, message]
    D -->|Failure| F[InternalServerErrorException]
Loading

File-Level Changes

Change Details Files
Expose a validated chat API operation for toggling WhatsApp Advanced Chat Privacy / Limit Sharing.
  • Added a required chat JID and boolean toggle DTO.
  • Added JSON schema validation for required, non-empty chat and boolean limit-sharing values.
  • Registered POST /chat/updateLimitSharing/{instance} with existing guards and controller dispatch.
src/api/dto/chat.dto.ts
src/validate/chat.schema.ts
src/api/routes/chat.router.ts
src/api/controllers/chat.controller.ts
Implement Limit Sharing delivery through the Baileys WhatsApp integration with structured success and failure responses.
  • Convert the supplied chat identifier to a remote JID and send the limitSharing message through the Baileys client.
  • Return the chat ID, requested state, and sent message on success.
  • Translate send failures into an InternalServerErrorException with an explanatory message.
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

@dpaes

dpaes commented Jul 3, 2026

Copy link
Copy Markdown

please @piwel , we will only accept this PR if its to develop

@piwel
piwel changed the base branch from main to develop October 30, 2026 16:32
@piwel
piwel force-pushed the codex/add-limit-sharing-privacy branch from 53d5862 to f402aa0 Compare October 30, 2026 16:34
@piwel
piwel marked this pull request as ready for review October 30, 2026 16:38
@piwel

piwel commented Oct 30, 2026

Copy link
Copy Markdown
Author

@dpaes This PR now targets develop. I rebased the feature commit onto the latest develop and resolved the conflicts. Both npm run build and npm run lint:check pass locally. The PR is now ready for review.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 3 issues

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

## Individual Comments

### Comment 1
<location path="src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts" line_range="4280" />
<code_context>
+    } catch (error) {
+      throw new InternalServerErrorException({
+        limitSharing: false,
+        message: ['An error occurred while updating advanced chat privacy.', error.toString()],
+      });
+    }
</code_context>
<issue_to_address>
**Error message uses wrong language**

When the Baileys send operation fails, the `InternalServerErrorException` returns an English error message to the API caller, so the user-facing error is not in Portuguese.

Return a Portuguese user-facing error message and keep any technical error details out of the public response.
</issue_to_address>

### Comment 2
<location path="src/api/dto/chat.dto.ts" line_range="93-96" />
<code_context>
   chat?: string;
 }

+export class LimitSharingDto {
+  chat: string;
+  limitSharing: boolean;
+}
+
 export class PrivacySettingDto {
</code_context>
<issue_to_address>
**DTO contract lacks documentation**

`LimitSharingDto` has no class-level or property-level JSDoc, so its purpose and the meaning or constraints of its fields are undocumented for maintainers and consumers.

Add class-level JSDoc for the DTO purpose and property-level JSDoc describing the fields and their constraints.
</issue_to_address>

### Comment 3
<location path="src/api/routes/chat.router.ts" line_range="110-119" />
<code_context>

         return res.status(HttpStatus.CREATED).json(response);
       })
+      .post(this.routerPath('updateLimitSharing'), ...guards, async (req, res) => {
+        const response = await this.dataValidate<LimitSharingDto>({
+          request: req,
+          schema: limitSharingSchema,
+          ClassRef: LimitSharingDto,
+          execute: (instance, data) => chatController.updateLimitSharing(instance, data),
+        });
+
+        return res.status(HttpStatus.CREATED).json(response);
+      })
       .delete(this.routerPath('deleteMessageForEveryone'), ...guards, async (req, res) => {
         const response = await this.dataValidate<DeleteMessage>({
</code_context>
<issue_to_address>
**New endpoint is undocumented**

The new route is registered without its required JSDoc route documentation, leaving the public endpoint’s path, request body, response, and errors undocumented for API consumers.

Add the required JSDoc documenting the method, path, description, instance parameter, DTO body, response, and errors.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. This sends the requested sharing setting to the chat, where it can change whether participants are restricted from sharing chat content. If the setting is wrong, copies shared while the restriction is off cannot be taken back; reverting the endpoint does not undo them.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/api/dto/chat.dto.ts Resolved
Comment thread src/api/routes/chat.router.ts Resolved
@piwel

piwel commented Oct 30, 2026

Copy link
Copy Markdown
Author

The three review comments have been addressed in commit 3c485e0, and all three conversations are resolved. Both npm run build and npm run lint:check pass locally.

@piwel
piwel marked this pull request as draft October 30, 2026 17:55
@piwel

piwel commented Oct 30, 2026

Copy link
Copy Markdown
Author

@dpaes I have moved this PR back to draft because the underlying functionality is not validated. In our July 3 test, sendMessage(jid, { limitSharing: false }) succeeded and returned a LIMIT_SHARING protocol message, but the Advanced Chat Privacy setting remained unchanged in the official WhatsApp UI. We therefore withdrew the feature from our downstream application.

This is tracked upstream in WhiskeySockets/Baileys#2685. That issue was closed after inactivity without a technical resolution.

The three review comments are fixed, and the build and lint pass locally, but these checks do not demonstrate that WhatsApp applies the setting. This PR should remain a draft until a supported setting update is available and verified against the official WhatsApp UI.

This branch has not been deployed

No deployments
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