Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Product-Requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ The CLI uses topics (space-separated) to group related commands logically.
*(Interact with Ably Pub/Sub using the Realtime SDK)*

- `$ ably channels list`: Lists active channels via channel enumeration API. Supports `--prefix`, `--limit`.
- `$ ably channels publish CHANNEL MESSAGE`: Publishes a message. Supports `--name`, `--encoding`, `--count`, `--delay`, JSON/text message, message interpolation (`{{.Count}}`, `{{.Timestamp}}`), `--transport rest|realtime`.
- `$ ably channels publish CHANNEL MESSAGE`: Publishes a message. Supports `--name`, `--encoding`, `--count`, `--delay`, JSON/text message, message interpolation (`{{.Count}}`, `{{.Timestamp}}`), `--transport rest|realtime`. Supports `extras.push` for push notifications in message payload.
- `$ ably channels batch-publish [MESSAGE]`: Publishes multiple messages via REST batch API. Supports `--channels`, `--channels-json`, `--spec`.
- `$ ably channels subscribe CHANNELS...`: Subscribes to messages on one or more channels. Supports `--rewind`, `--delta`, `--cipher-*` flags for decryption. Runs until terminated.
- `$ ably channels history CHANNEL`: Retrieves message history. Supports `--start`, `--end`, `--limit`, `--direction`, `--cipher` flags.
Expand Down
8 changes: 8 additions & 0 deletions src/commands/channels/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class ChannelsPublish extends AblyBaseCommand {
'$ ably channels publish --transport realtime my-channel "Using realtime transport"',
'$ ably channels publish my-channel "Hello World" --json',
'$ ably channels publish my-channel "Hello World" --pretty-json',
'$ ably channels publish my-channel \'{"data":"Push notification","extras":{"push":{"notification":{"title":"Hello","body":"World"}}}}\'',
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add this as an --extras flag to the command? Right now what comes after my-channel is assumed to be the entire data field so implicitly taking something out of it might be confusing?

Copy link
Author

Choose a reason for hiding this comment

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

I thought that when you type it like publish my-channel "Hello World" - it's a data for the message, but if you specify the whole message like this publish my-channel \'{"data":"Push notification","extras":{"push..., then whatever can be inside the message.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops yes I misread that, that now makes sense!

];

static override flags = {
Expand Down Expand Up @@ -206,6 +207,13 @@ export default class ChannelsPublish extends AblyBaseCommand {
delete messageData.name;
}

// Add extras if provided in the message data (before processing data)
if ("extras" in messageData) {
message.extras = messageData.extras;
// Remove extras from messageData to avoid duplication in data
delete messageData.extras;
}

// If data is explicitly provided in the message, use it
if ("data" in messageData) {
message.data = messageData.data;
Expand Down
27 changes: 27 additions & 0 deletions test/unit/commands/channels/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,31 @@ describe("ChannelsPublish", function () {
expect(stdout).toMatch(/error/i);
});
});

describe("extras.push support", function () {
it("should include extras.push when provided in message data", async function () {
const restMock = getMockAblyRest();
const channel = restMock.channels._getChannel("test-channel");

await runCommand(
[
"channels:publish",
"test-channel",
'{"data":"hello","extras":{"push":{"notification":{"title":"Test","body":"Push notification"}}}}',
"--transport",
"rest",
],
import.meta.url,
);

expect(channel.publish).toHaveBeenCalledOnce();
const publishArgs = channel.publish.mock.calls[0][0];
expect(publishArgs).toHaveProperty("data", "hello");
expect(publishArgs).toHaveProperty("extras");
expect(publishArgs.extras).toHaveProperty("push");
expect(publishArgs.extras.push).toEqual({
notification: { title: "Test", body: "Push notification" },
});
});
});
});
Loading