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
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,15 @@ $ ably-interactive
* [`ably rooms`](#ably-rooms)
* [`ably rooms list`](#ably-rooms-list)
* [`ably rooms messages`](#ably-rooms-messages)
* [`ably rooms messages delete ROOM SERIAL`](#ably-rooms-messages-delete-room-serial)
* [`ably rooms messages history ROOM`](#ably-rooms-messages-history-room)
* [`ably rooms messages reactions`](#ably-rooms-messages-reactions)
* [`ably rooms messages reactions remove ROOM MESSAGESERIAL REACTION`](#ably-rooms-messages-reactions-remove-room-messageserial-reaction)
* [`ably rooms messages reactions send ROOM MESSAGESERIAL REACTION`](#ably-rooms-messages-reactions-send-room-messageserial-reaction)
* [`ably rooms messages reactions subscribe ROOM`](#ably-rooms-messages-reactions-subscribe-room)
* [`ably rooms messages send ROOM TEXT`](#ably-rooms-messages-send-room-text)
* [`ably rooms messages subscribe ROOMS`](#ably-rooms-messages-subscribe-rooms)
* [`ably rooms messages update ROOM SERIAL TEXT`](#ably-rooms-messages-update-room-serial-text)
* [`ably rooms occupancy`](#ably-rooms-occupancy)
* [`ably rooms occupancy get ROOM`](#ably-rooms-occupancy-get-room)
* [`ably rooms occupancy subscribe ROOM`](#ably-rooms-occupancy-subscribe-room)
Expand Down Expand Up @@ -3051,10 +3053,47 @@ EXAMPLES
$ ably rooms messages subscribe my-room

$ ably rooms messages history my-room

$ ably rooms messages update my-room "serial" "Updated text"

$ ably rooms messages delete my-room "serial"
```

_See code: [src/commands/rooms/messages/index.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/messages/index.ts)_

## `ably rooms messages delete ROOM SERIAL`

Delete a message in an Ably Chat room

```
USAGE
$ ably rooms messages delete ROOM SERIAL [-v] [--json | --pretty-json] [--client-id <value>] [--description <value>]

ARGUMENTS
ROOM The room containing the message to delete
SERIAL The serial of the message to delete

FLAGS
-v, --verbose Output verbose logs
--client-id=<value> Overrides any default client ID when using API authentication. Use "none" to explicitly set
no client ID. Not applicable when using token authentication.
--description=<value> Description of the delete operation
--json Output in JSON format
--pretty-json Output in colorized JSON format

DESCRIPTION
Delete a message in an Ably Chat room

EXAMPLES
$ ably rooms messages delete my-room "serial-001"

$ ably rooms messages delete my-room "serial-001" --description "spam removal"

$ ably rooms messages delete my-room "serial-001" --json
```

_See code: [src/commands/rooms/messages/delete.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/messages/delete.ts)_

## `ably rooms messages history ROOM`

Get historical messages from an Ably Chat room
Expand Down Expand Up @@ -3326,6 +3365,47 @@ EXAMPLES

_See code: [src/commands/rooms/messages/subscribe.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/messages/subscribe.ts)_

## `ably rooms messages update ROOM SERIAL TEXT`

Update a message in an Ably Chat room

```
USAGE
$ ably rooms messages update ROOM SERIAL TEXT [-v] [--json | --pretty-json] [--client-id <value>] [--description <value>]
[--headers <value>] [--metadata <value>]

ARGUMENTS
ROOM The room containing the message to update
SERIAL The serial of the message to update
TEXT The new message text

FLAGS
-v, --verbose Output verbose logs
--client-id=<value> Overrides any default client ID when using API authentication. Use "none" to explicitly set
no client ID. Not applicable when using token authentication.
--description=<value> Description of the update operation
--headers=<value> Additional headers for the message (JSON format)
--json Output in JSON format
--metadata=<value> Additional metadata for the message (JSON format)
--pretty-json Output in colorized JSON format

DESCRIPTION
Update a message in an Ably Chat room

EXAMPLES
$ ably rooms messages update my-room "serial-001" "Updated text"

$ ably rooms messages update my-room "serial-001" "Updated text" --description "typo fix"

$ ably rooms messages update my-room "serial-001" "Updated text" --metadata '{"edited":true}'

$ ably rooms messages update my-room "serial-001" "Updated text" --headers '{"source":"cli"}'

$ ably rooms messages update my-room "serial-001" "Updated text" --json
```

_See code: [src/commands/rooms/messages/update.ts](https://github.com/ably/ably-cli/blob/v0.17.0/src/commands/rooms/messages/update.ts)_

## `ably rooms occupancy`

Commands for monitoring room occupancy
Expand Down
143 changes: 143 additions & 0 deletions src/commands/rooms/messages/delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Args, Flags } from "@oclif/core";
import type { OperationDetails } from "@ably/chat";

import { productApiFlags, clientIdFlag } from "../../../flags.js";
import { ChatBaseCommand } from "../../../chat-base-command.js";
import {
formatProgress,
formatSuccess,
formatResource,
} from "../../../utils/output.js";

export default class MessagesDelete extends ChatBaseCommand {
static override args = {
room: Args.string({
description: "The room containing the message to delete",
required: true,
}),
serial: Args.string({
description: "The serial of the message to delete",
required: true,
}),
};

static override description = "Delete a message in an Ably Chat room";

static override examples = [
'$ ably rooms messages delete my-room "serial-001"',
'$ ably rooms messages delete my-room "serial-001" --description "spam removal"',
'$ ably rooms messages delete my-room "serial-001" --json',
];

static override flags = {
...productApiFlags,
...clientIdFlag,
description: Flags.string({
description: "Description of the delete operation",
}),
};

async run(): Promise<void> {
const { args, flags } = await this.parse(MessagesDelete);

try {
const chatClient = await this.createChatClient(flags);

if (!chatClient) {
return this.fail(
"Failed to create Chat client",
flags,
"roomMessageDelete",
);
}

this.setupConnectionStateLogging(chatClient.realtime, flags);

// Get the room and attach
this.logCliEvent(
flags,
"room",
"gettingRoom",
`Getting room handle for ${args.room}`,
);
const room = await chatClient.rooms.get(args.room);
this.logCliEvent(
flags,
"room",
"gotRoom",
`Got room handle for ${args.room}`,
);

this.logCliEvent(
flags,
"room",
"attaching",
`Attaching to room ${args.room}`,
);
await room.attach();
this.logCliEvent(
flags,
"room",
"attached",
`Successfully attached to room ${args.room}`,
);

if (!this.shouldOutputJson(flags)) {
this.log(
formatProgress(
"Deleting message " +
formatResource(args.serial) +
" in room " +
formatResource(args.room),
),
);
}

// Build operation details
const details: OperationDetails | undefined = flags.description
? { description: flags.description }
: undefined;

this.logCliEvent(
flags,
"roomMessageDelete",
"deleting",
`Deleting message ${args.serial} from room ${args.room}`,
{ room: args.room, serial: args.serial },
);

const result = await room.messages.delete(args.serial, details);

this.logCliEvent(
flags,
"roomMessageDelete",
"messageDeleted",
`Message ${args.serial} deleted from room ${args.room}`,
{ room: args.room, serial: args.serial },
);

if (this.shouldOutputJson(flags)) {
this.logJsonResult(
{
room: args.room,
serial: args.serial,
versionSerial: result.version.serial,
},
flags,
);
} else {
this.log(
formatSuccess(
`Message ${formatResource(args.serial)} deleted from room ${formatResource(args.room)}.`,
),
);
this.log(` Version serial: ${formatResource(result.version.serial)}`);
}
} catch (error) {
this.fail(error, flags, "roomMessageDelete", {
room: args.room,
serial: args.serial,
});
}
}
}
8 changes: 6 additions & 2 deletions src/commands/rooms/messages/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export default class MessagesHistory extends ChatBaseCommand {
const chatClient = await this.createChatClient(flags);

if (!chatClient) {
this.fail("Failed to create Chat client", flags, "roomMessageHistory");
return this.fail(
"Failed to create Chat client",
flags,
"roomMessageHistory",
);
}

// Get the room
Expand Down Expand Up @@ -122,7 +126,7 @@ export default class MessagesHistory extends ChatBaseCommand {
historyParams.end !== undefined &&
historyParams.start > historyParams.end
) {
this.fail(
return this.fail(
"--start must be earlier than or equal to --end",
flags,
"roomMessageHistory",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/rooms/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ export default class MessagesIndex extends BaseTopicCommand {
'<%= config.bin %> <%= command.id %> send my-room "Hello world!"',
"<%= config.bin %> <%= command.id %> subscribe my-room",
"<%= config.bin %> <%= command.id %> history my-room",
'<%= config.bin %> <%= command.id %> update my-room "serial" "Updated text"',
'<%= config.bin %> <%= command.id %> delete my-room "serial"',
];
}
2 changes: 1 addition & 1 deletion src/commands/rooms/messages/reactions/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class MessagesReactionsRemove extends ChatBaseCommand {
const chatClient = await this.createChatClient(flags);

if (!chatClient) {
this.fail(
return this.fail(
"Failed to create Chat client",
flags,
"roomMessageReactionRemove",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/rooms/messages/reactions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class MessagesReactionsSend extends ChatBaseCommand {
flags.count !== undefined &&
flags.count <= 0
) {
this.fail(
return this.fail(
"Count must be a positive integer for Multiple type reactions",
flags,
"roomMessageReactionSend",
Expand All @@ -71,7 +71,7 @@ export default class MessagesReactionsSend extends ChatBaseCommand {
this.chatClient = await this.createChatClient(flags);

if (!this.chatClient) {
this.fail(
return this.fail(
"Failed to create Chat client",
flags,
"roomMessageReactionSend",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/rooms/messages/reactions/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class MessagesReactionsSubscribe extends ChatBaseCommand {
this.chatClient = await this.createChatClient(flags);

if (!this.chatClient) {
this.fail(
return this.fail(
"Failed to initialize clients",
flags,
"roomMessageReactionSubscribe",
Expand Down
6 changes: 5 additions & 1 deletion src/commands/rooms/messages/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ export default class MessagesSend extends ChatBaseCommand {
this.chatClient = await this.createChatClient(flags);

if (!this.chatClient) {
this.fail("Failed to create Chat client", flags, "roomMessageSend");
return this.fail(
"Failed to create Chat client",
flags,
"roomMessageSend",
);
}

// Set up connection state logging
Expand Down
Loading
Loading