Skip to content
Merged
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
}
},
"dependencies": {
"@ably/chat": "^0.7.0",
"@ably/chat": "^0.10.0",
"@ably/spaces": "^0.4.0",
"@inquirer/prompts": "^5.1.3",
"@modelcontextprotocol/sdk": "^1.8.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/rooms/messages/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class MessagesGet extends ChatBaseCommand {
}

// Get historical messages
const messagesResult = await room.messages.get({ limit: flags.limit });
const messagesResult = await room.messages.history({ limit: flags.limit });
const { items } = messagesResult;

if (this.shouldOutputJson(flags)) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/rooms/messages/reactions/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default class MessagesReactionsAdd extends ChatBaseCommand {
}
);

await room.messages.reactions.add({ serial: messageSerial }, reactionParams);
await room.messages.reactions.send({ serial: messageSerial }, reactionParams);

this.logCliEvent(
flags,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/rooms/messages/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Args, Flags } from "@oclif/core";
import * as Ably from "ably";
import { Subscription, StatusSubscription, MessageEvent } from "@ably/chat"; // Import ChatClient and StatusSubscription
import { Subscription, StatusSubscription, ChatMessageEvent } from "@ably/chat"; // Import ChatClient and StatusSubscription
import chalk from "chalk";

import { ChatBaseCommand } from "../../../chat-base-command.js";
Expand Down Expand Up @@ -29,7 +29,7 @@ interface StatusChange {
// Define room interface
interface ChatRoom {
messages: {
subscribe: (callback: (event: MessageEvent) => void) => Subscription;
subscribe: (callback: (event: ChatMessageEvent) => void) => Subscription;
};
onStatusChange: (callback: (statusChange: unknown) => void) => StatusSubscription;
attach: () => Promise<void>;
Expand Down Expand Up @@ -191,7 +191,7 @@ export default class MessagesSubscribe extends ChatBaseCommand {
`Subscribing to messages in room ${this.roomId}`,
);
this.messageSubscription = room.messages.subscribe(
(messageEvent: MessageEvent) => {
(messageEvent: ChatMessageEvent) => {
const { message } = messageEvent;
const messageLog: ChatMessage = {
clientId: message.clientId,
Expand Down
10 changes: 5 additions & 5 deletions src/commands/rooms/occupancy/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Args } from "@oclif/core";
import * as Ably from "ably";
import { ChatClient, Room, OccupancyEvent } from "@ably/chat";
import { ChatClient, Room, OccupancyData } from "@ably/chat";
import { ChatBaseCommand } from "../../../chat-base-command.js";

export default class RoomsOccupancyGet extends ChatBaseCommand {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class RoomsOccupancyGet extends ChatBaseCommand {
// Release room from chat client
if (this.chatClient && this.room) {
await Promise.race([
this.chatClient.rooms.release(this.room.roomId),
this.chatClient.rooms.release(this.room.name),
new Promise(resolve => setTimeout(resolve, 1000)) // 1s timeout
]);
}
Expand Down Expand Up @@ -117,9 +117,9 @@ export default class RoomsOccupancyGet extends ChatBaseCommand {
// Get occupancy metrics using the Chat SDK's occupancy API
const occupancyMetrics = await Promise.race([
this.room.occupancy.get(),
new Promise<OccupancyEvent>((_, reject) =>
setTimeout(() => reject(new Error('Occupancy get timeout')), 5000)
)
new Promise<OccupancyData>((_, reject) =>
setTimeout(() => reject(new Error("Occupancy get timeout")), 5000),
),
]);

// Output the occupancy metrics based on format
Expand Down
11 changes: 9 additions & 2 deletions src/commands/rooms/occupancy/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { OccupancyEvent, RoomStatus, Subscription, RoomStatusChange, ChatClient } from "@ably/chat";
import {
OccupancyEvent,
RoomStatus,
Subscription,
RoomStatusChange,
ChatClient,
} from "@ably/chat";
import { Args } from "@oclif/core";
import * as Ably from "ably";
import chalk from "chalk";
Expand Down Expand Up @@ -260,7 +266,8 @@ export default class RoomsOccupancySubscribe extends ChatBaseCommand {
"Subscribing to occupancy updates",
);
this.unsubscribeOccupancyFn = room.occupancy.subscribe(
(occupancyMetrics: OccupancyEvent) => {
(occupancyEvent: OccupancyEvent) => {
const occupancyMetrics = occupancyEvent.occupancy;
this.logCliEvent(
flags,
"occupancy",
Expand Down
26 changes: 13 additions & 13 deletions src/commands/rooms/presence/enter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatClient, Room, RoomStatus, RoomStatusChange, Subscription as ChatSubscription, StatusSubscription } from "@ably/chat";
import { ChatClient, Room, RoomStatus, RoomStatusChange, Subscription as ChatSubscription, StatusSubscription, PresenceEvent, PresenceEventType } from "@ably/chat";
import { Args, Flags, Interfaces } from "@oclif/core";
import * as Ably from "ably";
import chalk from "chalk";
Expand Down Expand Up @@ -142,23 +142,24 @@ export default class RoomsPresenceEnter extends ChatBaseCommand {
);

this.unsubscribePresenceFn = currentRoom.presence.subscribe(
(event) => {
if (event.clientId !== this.chatClient?.clientId) {
(event: PresenceEvent) => {
const member = event.member;
if (member.clientId !== this.chatClient?.clientId) {
const timestamp = new Date().toISOString();
const eventData = { action: event.action, member: { clientId: event.clientId, data: event.data }, roomId: this.roomId, timestamp };
this.logCliEvent(flags, "presence", event.action, `Presence event '${event.action}' received`, eventData);
const eventData = { type: event.type, member: { clientId: member.clientId, data: member.data }, roomId: this.roomId, timestamp };
this.logCliEvent(flags, "presence", event.type, `Presence event '${event.type}' received`, eventData);
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput({ success: true, ...eventData }, flags));
} else {
let actionSymbol = "•"; let actionColor = chalk.white;
if (event.action === "enter") { actionSymbol = "✓"; actionColor = chalk.green; }
if (event.action === "leave") { actionSymbol = "✗"; actionColor = chalk.red; }
if (event.action === "update") { actionSymbol = "⟲"; actionColor = chalk.yellow; }
this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(event.clientId || "Unknown")} ${actionColor(event.action)}`);
if (event.data && typeof event.data === 'object' && Object.keys(event.data).length > 0) {
const profile = event.data as { name?: string };
if (event.type === PresenceEventType.Enter) { actionSymbol = "✓"; actionColor = chalk.green; }
if (event.type === PresenceEventType.Leave) { actionSymbol = "✗"; actionColor = chalk.red; }
if (event.type === PresenceEventType.Update) { actionSymbol = "⟲"; actionColor = chalk.yellow; }
this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(member.clientId || "Unknown")} ${actionColor(event.type)}`);
if (member.data && typeof member.data === 'object' && Object.keys(member.data).length > 0) {
const profile = member.data as { name?: string };
if (profile.name) { this.log(` ${chalk.dim("Name:")} ${profile.name}`); }
this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: event.data }, flags)}`);
this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: member.data }, flags)}`);
}
}
}
Expand Down Expand Up @@ -294,4 +295,3 @@ export default class RoomsPresenceEnter extends ChatBaseCommand {
this.logCliEvent(flags, "connection", "AFTER_properlyCloseAblyClient", "Finished awaiting properlyCloseAblyClient.");
}
}

24 changes: 13 additions & 11 deletions src/commands/rooms/presence/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
StatusSubscription,
RoomStatusChange,
Room,
PresenceEvent
PresenceEvent,
PresenceEventType
} from "@ably/chat";
import { Args, Interfaces, Flags } from "@oclif/core";
import * as Ably from "ably";
Expand Down Expand Up @@ -177,20 +178,21 @@ export default class RoomsPresenceSubscribe extends ChatBaseCommand {
this.logCliEvent(flags, "presence", "subscribingToEvents", "Subscribing to presence events");
this.presenceSubscription = currentRoom.presence.subscribe((event: PresenceEvent) => {
const timestamp = new Date().toISOString();
const eventData = { action: event.action, member: { clientId: event.clientId, data: event.data }, roomId: this.roomId, timestamp };
this.logCliEvent(flags, "presence", event.action, `Presence event '${event.action}' received`, eventData);
const member = event.member;
const eventData = { type: event.type, member: { clientId: member.clientId, data: member.data }, roomId: this.roomId, timestamp };
this.logCliEvent(flags, "presence", event.type, `Presence event '${event.type}' received`, eventData);
if (this.shouldOutputJson(flags)) {
this.log(this.formatJsonOutput({ success: true, ...eventData }, flags));
} else {
let actionSymbol = "•"; let actionColor = chalk.white;
if (event.action === "enter") { actionSymbol = "✓"; actionColor = chalk.green; }
if (event.action === "leave") { actionSymbol = "✗"; actionColor = chalk.red; }
if (event.action === "update") { actionSymbol = "⟲"; actionColor = chalk.yellow; }
this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(event.clientId || "Unknown")} ${actionColor(event.action)}`);
if (event.data && typeof event.data === 'object' && Object.keys(event.data).length > 0) {
const profile = event.data as { name?: string };
if (event.type === PresenceEventType.Enter) { actionSymbol = "✓"; actionColor = chalk.green; }
if (event.type === PresenceEventType.Leave) { actionSymbol = "✗"; actionColor = chalk.red; }
if (event.type === PresenceEventType.Update) { actionSymbol = "⟲"; actionColor = chalk.yellow; }
this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(member.clientId || "Unknown")} ${actionColor(event.type)}`);
if (member.data && typeof member.data === 'object' && Object.keys(member.data).length > 0) {
const profile = member.data as { name?: string };
if (profile.name) { this.log(` ${chalk.dim("Name:")} ${profile.name}`); }
this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: event.data }, flags)}`);
this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: member.data }, flags)}`);
}
}
});
Expand Down Expand Up @@ -294,4 +296,4 @@ export default class RoomsPresenceSubscribe extends ChatBaseCommand {
await this.properlyCloseAblyClient();
this.logCliEvent(flags, "connection", "clientClosedFinally", "Ably client close attempt finished.");
}
}
}
2 changes: 1 addition & 1 deletion src/commands/rooms/reactions/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class RoomsReactionsSend extends ChatBaseCommand {
{ emoji, metadata: this.metadataObj || {} },
);
await room.reactions.send({
type: emoji,
name: emoji,
metadata: this.metadataObj || {},
});
this.logCliEvent(
Expand Down
9 changes: 5 additions & 4 deletions src/commands/rooms/reactions/subscribe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatClient, RoomStatus, Subscription } from "@ably/chat";
import { ChatClient, RoomReactionEvent, RoomStatus, Subscription } from "@ably/chat";
import { Args } from "@oclif/core";
import * as Ably from "ably"; // Import Ably
import chalk from "chalk";
Expand Down Expand Up @@ -186,14 +186,15 @@ export default class RoomsReactionsSubscribe extends ChatBaseCommand {
"subscribing",
"Subscribing to reactions",
);
this.unsubscribeReactionsFn = room.reactions.subscribe((reaction) => {
this.unsubscribeReactionsFn = room.reactions.subscribe((event: RoomReactionEvent) => {
const reaction = event.reaction;
const timestamp = new Date().toISOString(); // Chat SDK doesn't provide timestamp in event
const eventData = {
clientId: reaction.clientId,
metadata: reaction.metadata,
roomId,
timestamp,
type: reaction.type,
name: reaction.name,
};
this.logCliEvent(
flags,
Expand All @@ -209,7 +210,7 @@ export default class RoomsReactionsSubscribe extends ChatBaseCommand {
);
} else {
this.log(
`[${chalk.dim(timestamp)}] ${chalk.green("⚡")} ${chalk.blue(reaction.clientId || "Unknown")} reacted with ${chalk.yellow(reaction.type || "unknown")}`,
`[${chalk.dim(timestamp)}] ${chalk.green("⚡")} ${chalk.blue(reaction.clientId || "Unknown")} reacted with ${chalk.yellow(reaction.name || "unknown")}`,
);

// Show any additional metadata in the reaction
Expand Down
Loading