feat(push): support realtime message data in batch-publish channel items#346
feat(push): support realtime message data in batch-publish channel items#346
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds support for including realtime message data alongside channel-routed push notifications in push:batch-publish, aligning batch behavior with the --message capability introduced for push publish (PR #310).
Changes:
- Extend channel-routed batch items to accept an optional
messagefield and forward it asmessages.datawhen publishing viaPOST /messages. - Update CLI help/examples and argument description to document the new
messagefield for channel items. - Add unit tests covering string message data, JSON object message data, and the omission case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/commands/push/batch-publish.ts | Maps optional message on channel batch items to realtime message data while still wrapping push payload under extras.push; updates examples/arg description. |
| test/unit/commands/push/batch-publish.test.ts | Adds unit tests verifying message is forwarded into messages.data (string/object) and omitted when absent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
WalkthroughThis PR extends Changes
Review Notes
|
There was a problem hiding this comment.
Review Summary
| File | Status | Issues |
|---|---|---|
src/commands/push/batch-publish.ts |
✅ OK | — |
test/unit/commands/push/batch-publish.test.ts |
✅ OK | — |
Assessment
The change is minimal, correct, and well-tested. The entry.message !== undefined guard is the right approach — it correctly passes falsy-but-present values ("", 0, false) to the API while skipping the field entirely when absent. This mirrors how Ably message data fields are handled elsewhere.
Three things worth noting, none blocking:
-
nulledge case — if a user passes"message": null"in the JSON,null !== undefinedevaluates totrue, somessageObj.data = nullgets sent to the API. The PR description says the field accepts "string or JSON", but the code accepts any value including null. Unlikely to cause problems in practice since the Ably API will either accept or reject it, but worth knowing the guard isn't a type filter. -
Recipient items silently forward the
messagefield —recipientItems.map(({ entry }) => entry)sends the raw entry object, so if a user includes"message"on a recipient item, it goes to/push/batch/publishas-is. The PR description says "message field is ignored/not applicable" for recipients, but it's actually forwarded to the API rather than stripped. The API will likely ignore it, but the behaviour is technically different from what the description says. Not a bug, just a documentation nuance. -
Test assertion for "omit" case —
expect.not.objectContaining({ data: expect.anything() })passes whendatais absent, null, or undefined — which is exactly the right matcher here sinceexpect.anything()excludes both null and undefined. No issue, just confirming the matcher semantics are intentional.
LGTM. Ready to merge.
Reuses prepareMessageFromInput (already used by channels publish) so JSON input can set name, data, and extras — not just data. The CLI push payload is still attached as extras.push; user-supplied extras are merged, and extras.push in --message is rejected with a clear error since the CLI owns that field via its push flags. JSON output includes messageName and messageData when present.
Explicitly assert that --message '{"data":"x"}' now unwraps to
data: "x" rather than data: { data: "x" } — a behaviour change
from the previous JSON.parse-into-data implementation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cae33da to
c0ddf56
Compare
Fixes #345
Summary
--messageflag added topush publishin Realtime message send + push message send on channel #310"message"field whose value is sent as realtime messagedataalongside the push notification inextras.pushExample
[ { "channels": ["my-channel"], "payload": {"notification": {"title": "Hello", "body": "World"}}, "message": "Hello from push" } ]or with a JSON object as message data:
[ { "channels": ["my-channel"], "payload": {"notification": {"title": "Hello"}}, "message": {"event": "push", "text": "Hello"} } ]Test plan
pnpm test:unitpasses (20 tests in batch-publish, 3 new ones covering string message, JSON object message, and omitted message)pnpm exec eslint .clean🤖 Generated with Claude Code