Skip to content

fix(baileys): allow sending captions with document messages#363

Merged
rmyndharis merged 1 commit into
rmyndharis:mainfrom
Fernixp:bugfix/add-message-caption
Jun 20, 2026
Merged

fix(baileys): allow sending captions with document messages#363
rmyndharis merged 1 commit into
rmyndharis:mainfrom
Fernixp:bugfix/add-message-caption

Conversation

@Fernixp

@Fernixp Fernixp commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

The baileys adapter was ignoring the caption field when sending document messages. This commit passes the caption
from the media payload to the sendContent method. Additionally, it updates message.service.ts to correctly store the document's caption in the database instead of defaulting to the filename.

Description

This PR fixes an issue where the caption field was being completely ignored when sending document payloads (like PDFs) using the Baileys adapter.

  • Updated baileys.adapter.ts to properly pass the caption property to the underlying sendContent method.
    • Updated message.service.ts so the database stores the caption as the message body for documents, falling back to the filename if a caption isn't provided.
    • Added test coverage in baileys.adapter.spec.ts to prevent future regressions.

Type of Change

  • [x ] Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • Tests added/updated
  • Documentation updated
  • Lint passes
  • Self-reviewed

Screenshots (if applicable)

N/A

Related Issues

Closes #

The baileys adapter was ignoring the `caption` field when sending document messages. This commit passes the `caption`
  from the media payload to the `sendContent` method. Additionally, it updates `message.service.ts` to correctly store the document's caption in the database instead of defaulting to the filename.

@rmyndharis rmyndharis left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice catch and a clean fix, @Fernixp — approving.

I verified the gap: the whatsapp-web.js adapter already forwards the caption for documents (sendMediaMessageclient.sendMessage(..., { caption: media.caption })), so the Baileys sendDocumentMessage was the only path dropping it. This brings the two engines to parity.

The message.service change (body: dto.caption || dto.filename || '') is a good engine-neutral improvement too: both engines now store the document's caption as the message body, falling back to the filename when there's no caption — and it's backward-compatible (the no-caption case is unchanged). The added spec assertion locks it in.

CI is green (Lint/Test/Build/Dashboard) and the change is minimal and well-scoped. 👍 Thanks for including the test.

@rmyndharis

Copy link
Copy Markdown
Owner

Thanks for the clean, well-scoped fix, @Fernixp — and for including a regression test. I traced it through end to end and everything lines up:

  • The caption now flows correctly: dto.captionMediaInput.captionsendContent({ document, ..., caption }) → Baileys sendMessage. MediaInput.caption and the validated caption DTO field (max 1024) were already in place, so this was purely the adapter dropping it.
  • This brings Baileys to parity with whatsapp-web.js, whose sendDocumentMessage already forwarded caption: media.caption. Baileys was the only path losing it — nice catch.
  • The message.service.ts change (body: dto.caption || dto.filename || '') is a good engine-neutral improvement and is backward-compatible: the no-caption case is unchanged.
  • The added spec assertion (sendMessage called with caption: 'a document') locks the behavior in nicely.

CI is green across Lint/Test/Build/Dashboard and the change is minimal. This is ready to merge — I'll fold a short CHANGELOG note in on my end so it shows up in the next release. Appreciate the contribution!

@rmyndharis rmyndharis merged commit 84e6e29 into rmyndharis:main Jun 20, 2026
5 checks passed
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