Skip to content

fix: pass quoted option in audioWhatsapp to support replies#2516

Open
octo-patch wants to merge 1 commit intoEvolutionAPI:mainfrom
octo-patch:fix/issue-2485-audio-quoted-reply
Open

fix: pass quoted option in audioWhatsapp to support replies#2516
octo-patch wants to merge 1 commit intoEvolutionAPI:mainfrom
octo-patch:fix/issue-2485-audio-quoted-reply

Conversation

@octo-patch
Copy link
Copy Markdown

@octo-patch octo-patch commented Apr 26, 2026

Fixes #2485

Problem

When sending audio with sendWhatsAppAudio and a quoted key in the payload:

{
  "number": "55489999999999",
  "audio": "<base64>",
  "quoted": {
    "key": {
      "id": "3EB0006934B47898977C8C"
    }
  }
}

The audio was delivered as a standalone message rather than as a reply. The quoted field was ignored.

Root Cause

The audioWhatsapp method built the options object passed to sendMessageWithTyping as:

{ presence: 'recording', delay: data?.delay }

The quoted field from data was never forwarded, unlike every other message-sending method (textMessage, pollMessage, mediaMessage, etc.) which all pass quoted: data?.quoted.

Solution

Added quoted: data?.quoted to the options in both sendMessageWithTyping call sites inside audioWhatsapp (the encoding path and the direct path).

Testing

Send a POST /message/sendWhatsAppAudio/{instance} request with a valid quoted.key.id. The audio message will now appear as a reply to the referenced message in WhatsApp.

Summary by Sourcery

Bug Fixes:

  • Forward the quoted message reference when sending WhatsApp audio so replies are delivered as threaded responses instead of standalone messages.

…olutionAPI#2485)

The `audioWhatsapp` method was not forwarding `data.quoted` to
`sendMessageWithTyping`, so audio messages sent with a `quoted` key
were delivered as standalone messages instead of replies.

Added `quoted: data?.quoted` to the options object in both
`sendMessageWithTyping` call sites inside `audioWhatsapp` (the
encoding path and the direct path), matching the pattern used by all
other message-sending methods (textMessage, pollMessage, etc.).

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 26, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Passes the incoming quoted payload through to WhatsApp audio messages so they are sent as replies rather than standalone messages, by forwarding data?.quoted into the options object for sendMessageWithTyping in the audioWhatsapp flow.

Sequence diagram for sending WhatsApp audio reply with quoted option

sequenceDiagram
  actor ApiClient
  participant ApiServer
  participant BaileysStartupService
  participant WhatsAppGateway

  ApiClient->>ApiServer: POST /message/sendWhatsAppAudio/{instance}
  ApiServer->>BaileysStartupService: audioWhatsapp(number, audio, quoted, delay, isIntegration)

  alt audioRequiresEncoding
    BaileysStartupService->>BaileysStartupService: encodeToOggOpus(audio)
    BaileysStartupService->>WhatsAppGateway: sendMessageWithTyping(number, audioContent, optionsWithQuoted, isIntegration)
  else audioAlreadyEncoded
    BaileysStartupService->>WhatsAppGateway: sendMessageWithTyping(number, audioContent, optionsWithQuoted, isIntegration)
  end

  Note over BaileysStartupService,WhatsAppGateway: optionsWithQuoted = { presence: recording, delay: delay, quoted: quoted }

  WhatsAppGateway-->>ApiServer: messageSentAsReply
  ApiServer-->>ApiClient: 200 OK
Loading

Class diagram for BaileysStartupService audioWhatsapp options including quoted

classDiagram
  class BaileysStartupService {
    +audioWhatsapp(number, audioBase64, quoted, delay, isIntegration) Promise~void~
    +sendMessageWithTyping(number, content, options, isIntegration) Promise~AnyMessageContent~
  }

  class AudioOptions {
    +presence string
    +delay number
    +quoted object
  }

  class AudioContent {
    +audio any
    +ptt boolean
    +mimetype string
  }

  BaileysStartupService ..> AudioOptions : uses
  BaileysStartupService ..> AudioContent : uses

  AudioOptions : presence = recording
  AudioOptions : delay = delay
  AudioOptions : quoted = quoted

  AudioContent : ptt = true
  AudioContent : mimetype = audio/ogg, codecs=opus
Loading

File-Level Changes

Change Details Files
Forward the quoted option when sending WhatsApp audio so replies work consistently with other message types.
  • Update the sendMessageWithTyping options in the audio encoding path to include quoted: data?.quoted alongside presence and delay.
  • Update the sendMessageWithTyping options in the direct audio path to include quoted: data?.quoted so both paths support replies.
src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#2485 Ensure that the sendWhatsAppAudio endpoint correctly sends an audio message as a reply when a quoted field is provided in the payload (i.e., forward the quoted option to the underlying WhatsApp send function in all code paths).

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
Copy Markdown
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:

  • Since multiple WhatsApp send methods now share the same { presence, delay, quoted } options pattern, consider extracting a small helper to build these options so future updates don’t accidentally omit fields in one code path (as happened here with audioWhatsapp).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since multiple WhatsApp send methods now share the same `{ presence, delay, quoted }` options pattern, consider extracting a small helper to build these options so future updates don’t accidentally omit fields in one code path (as happened here with `audioWhatsapp`).

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.

@octo-patch
Copy link
Copy Markdown
Author

Thanks for the suggestion! You're right that the { presence, delay, quoted } pattern is repeated across the WhatsApp send methods. Extracting a helper would be a worthwhile cleanup, but it touches several methods beyond audioWhatsapp and changes their internal shape — I'd rather keep this PR scoped to the one-line bug fix for #2485 so it stays easy to backport / review.

Happy to open a follow-up refactor PR if maintainers want one — just let me know.

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.

sendWhatsAppAudio does not send a reply

1 participant