Skip to content

fix: mentionsEveryOne always active even when set to false#2470

Open
enzowilliam wants to merge 1 commit intoEvolutionAPI:mainfrom
enzowilliam:fix/mentions-everyone-false-bug
Open

fix: mentionsEveryOne always active even when set to false#2470
enzowilliam wants to merge 1 commit intoEvolutionAPI:mainfrom
enzowilliam:fix/mentions-everyone-false-bug

Conversation

@enzowilliam
Copy link

@enzowilliam enzowilliam commented Mar 11, 2026

Summary

  • Fixed bug where mentionsEveryOne was always active even when set to false
  • Fixed validation schema property name mismatch (everyOnementionsEveryOne)

Root Cause

The check if (options?.mentionsEveryOne) used truthy evaluation. When clients (like n8n) send "false" as a string instead of a boolean, JavaScript evaluates it as truthy because it's a non-empty string.

Changes

  1. whatsapp.baileys.service.ts: Changed truthy check to strict equality (=== true)
  2. message.schema.ts: Renamed everyOne to mentionsEveryOne in all message schemas to match DTO

Test plan

  • Send message to group with mentionsEveryOne: false → should NOT mention anyone
  • Send message to group with mentionsEveryOne: true → should mention everyone
  • Send message to group without mentionsEveryOne → should NOT mention anyone

Fixes #2431

🤖 Generated with Claude Code

Summary by Sourcery

Align WhatsApp group mention handling with the message DTO and prevent unintended @everyone mentions when the option is false or omitted.

Bug Fixes:

  • Ensure mentionsEveryOne only triggers @everyone mentions when explicitly set to true, avoiding truthy evaluation of string values like "false".
  • Correct validation schemas to use mentionsEveryOne instead of the mismatched everyOne property so options are validated and mapped consistently across message types.

- Changed truthy check to strict equality (=== true) to properly handle
  string values like "false" sent by clients (e.g., n8n)
- Fixed validation schema property name from 'everyOne' to 'mentionsEveryOne'
  to match DTO and service code

Fixes EvolutionAPI#2431

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 11, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes WhatsApp group mention logic so that mentionsEveryOne only triggers when explicitly set to true, and aligns JSON message validation schemas with the DTO by renaming the everyOne flag to mentionsEveryOne across all message types.

Sequence diagram for WhatsApp group message mentionsEveryOne handling

sequenceDiagram
  actor Client
  participant MessageAPI
  participant Validator
  participant BaileysStartupService
  participant WhatsAppGroup

  Client->>MessageAPI: sendGroupMessage(groupId, content, options)
  MessageAPI->>Validator: validate(content, options) using messageSchema
  Validator-->>MessageAPI: validationResult (mentionsEveryOne boolean)

  MessageAPI->>BaileysStartupService: sendGroupMessage(groupId, content, options)

  BaileysStartupService->>WhatsAppGroup: getGroup(groupId)
  WhatsAppGroup-->>BaileysStartupService: group(participants)

  alt mentionsEveryOne explicitly true
    BaileysStartupService->>BaileysStartupService: if options.mentionsEveryOne === true
    BaileysStartupService->>BaileysStartupService: mentions = group.participants.ids
  else mentioned list provided
    BaileysStartupService->>BaileysStartupService: else if options.mentioned.length > 0
    BaileysStartupService->>BaileysStartupService: mentions = options.mentioned.ids
  else no mentions
    BaileysStartupService->>BaileysStartupService: mentions = []
  end

  BaileysStartupService-->>MessageAPI: send result
  MessageAPI-->>Client: response
Loading

Class diagram for BaileysStartupService and message mention options

classDiagram
  class BaileysStartupService {
    +sendGroupMessage(groupId, content, options)
  }

  class MessageOptions {
    +boolean mentionsEveryOne
    +string[] mentioned
  }

  class TextMessageSchema {
    +boolean mentionsEveryOne
  }

  class MediaMessageSchema {
    +boolean mentionsEveryOne
  }

  class PtvMessageSchema {
    +boolean mentionsEveryOne
  }

  class AudioMessageSchema {
    +boolean mentionsEveryOne
  }

  class StickerMessageSchema {
    +boolean mentionsEveryOne
  }

  class LocationMessageSchema {
    +boolean mentionsEveryOne
  }

  class PollMessageSchema {
    +boolean mentionsEveryOne
  }

  class ListMessageSchema {
    +boolean mentionsEveryOne
  }

  class ButtonsMessageSchema {
    +boolean mentionsEveryOne
  }

  BaileysStartupService --> MessageOptions : uses

  MessageOptions <.. TextMessageSchema : validated_by
  MessageOptions <.. MediaMessageSchema : validated_by
  MessageOptions <.. PtvMessageSchema : validated_by
  MessageOptions <.. AudioMessageSchema : validated_by
  MessageOptions <.. StickerMessageSchema : validated_by
  MessageOptions <.. LocationMessageSchema : validated_by
  MessageOptions <.. PollMessageSchema : validated_by
  MessageOptions <.. ListMessageSchema : validated_by
  MessageOptions <.. ButtonsMessageSchema : validated_by
Loading

File-Level Changes

Change Details Files
Make mentions-everyone behavior strictly opt-in and resilient to stringified boolean inputs.
  • Change conditional check from a generic truthy check to a strict equality check against true for the mentionsEveryOne option.
  • Ensure that when clients send "false" (string) or omit mentionsEveryOne, the code no longer treats it as an active mentions-everyone request.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Align validation schema flag name with DTO by renaming everyOne to mentionsEveryOne across message schemas.
  • Rename the everyOne boolean property to mentionsEveryOne in the text, media, ptv, audio, sticker, location, poll, list, and buttons message JSON schemas.
  • Keep the boolean type and enum [true, false] constraints unchanged while updating the property name.
src/validate/message.schema.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#2431 Ensure that sending a message to a WhatsApp group with mentionsEveryOne explicitly set to false does not mention everyone in the group.
#2431 Ensure that omitting the mentionsEveryOne field when sending a message to a WhatsApp group results in no mentions.

Possibly linked issues


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 - I've left some high level feedback:

  • The options?.mentionsEveryOne === true check fixes the immediate bug but will now ignore a string 'true'; consider normalizing this field at the validation/DTO layer (e.g., coercing 'true'/'false' to booleans) so the service logic can stay simple and robust to client quirks.
  • Since the schema property was renamed from everyOne to mentionsEveryOne, double-check any other internal usages or serializers that might still refer to everyOne to avoid inconsistent payload shapes at the boundaries.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `options?.mentionsEveryOne === true` check fixes the immediate bug but will now ignore a string `'true'`; consider normalizing this field at the validation/DTO layer (e.g., coercing `'true'`/`'false'` to booleans) so the service logic can stay simple and robust to client quirks.
- Since the schema property was renamed from `everyOne` to `mentionsEveryOne`, double-check any other internal usages or serializers that might still refer to `everyOne` to avoid inconsistent payload shapes at the boundaries.

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.

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.

"sendMessage" to group with "menstionsEveryOne" always active even the value is "false"

1 participant