refactor: validate the shape of chat.sendMessage blocks in its schema by KevLehman · Pull Request #42978 · RocketChat/Rocket.Chat · GitHub
Skip to content

refactor: validate the shape of chat.sendMessage blocks in its schema - #42978

Merged
KevLehman merged 3 commits into
fix-sendmessage-issuesfrom
fix/sendmessage-blocks-ajv
Oct 21, 2026
Merged

KevLehman merged 3 commits into
fix-sendmessage-issuesfrom
fix/sendmessage-blocks-ajv

Conversation

@KevLehman

@KevLehman KevLehman commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Stacked on #42975.

assertValidMessageBlocks checked the shape of blocks in code. The checks that a JSON Schema can express now live in the chat.sendMessage AJV schema:

  • actions and context blocks must have elements, a list of objects.
  • section fields, when present, must be a list of objects.
  • input blocks must have an element object.

The code keeps only what a schema cannot express: the 100-point limit of linear_scale, its integer bounds wherever it is nested, and the nesting depth.

The accepted and rejected inputs do not change. Every unit case keeps its result; the unit spec now runs each case through the schema and the code, as the route does. For the shape errors the API now returns AJV's invalid-params message (e.g. must have required property 'elements') instead of Invalid blocks: …, so the e2e assertions match the new message. The status stays 400.

t is not touched, so video conference messages keep working.

Issue(s)

https://rocketchat.atlassian.net/browse/VLN-706

Steps to test or reproduce

chat.sendMessage with blocks: [{ type: 'actions' }] returns 400.

Further comments

The schema could also reject more fields (t, content, e2eMentions, location), but that would refuse requests that are accepted today, so it is left out of this change.

View guided diff

The checks that actions and context blocks carry a list of elements, that section fields are objects and that an input block has an element now live in the chat.sendMessage AJV schema. The code keeps only what a schema cannot express: the linear scale point limit and the nesting depth.
@dionisio-bot

dionisio-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@changeset-bot

changeset-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c2350ed

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7e750c0a-9d21-4473-ae31-33dd904084c5
📥 Commits

Reviewing files that changed from the base of the PR and between 1506bba and c2350ed.

📒 Files selected for processing: 4
  • apps/meteor/server/api/lib/assertValidMessageBlocks.spec.ts
  • apps/meteor/server/api/lib/assertValidMessageBlocks.ts
  • apps/meteor/tests/end-to-end/api/chat.ts
  • packages/rest-typings/src/v1/chat.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.05%. Comparing base (1506bba) to head (c2350ed).
⚠️ Report is 1 commits behind head on fix-sendmessage-issues.

Additional details and impacted files

Impacted file tree graph

@@                    Coverage Diff                     @@
##           fix-sendmessage-issues   #42978      +/-   ##
==========================================================
+ Coverage                   71.03%   71.05%   +0.02%     
==========================================================
  Files                        5432     5432              
  Lines                      231833   231810      -23     
  Branches                    42236    42293      +57     
==========================================================
+ Hits                       164680   164717      +37     
+ Misses                      61864    61802      -62     
- Partials                     5289     5291       +2     
Flag Coverage Δ
e2e 58.98% <ø> (+0.02%) ⬆️
e2e-api 46.31% <100.00%> (+0.21%) ⬆️
unit 71.56% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevLehman
KevLehman marked this pull request as ready for review October 21, 2026 05:13
@KevLehman
KevLehman requested review from a team as code owners October 21, 2026 05:13
@KevLehman
KevLehman merged commit 8294302 into fix-sendmessage-issues Oct 21, 2026
61 checks passed
@KevLehman
KevLehman deleted the fix/sendmessage-blocks-ajv branch October 21, 2026 05:13
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.

1 participant