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
3 changes: 3 additions & 0 deletions fern/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ navigation:
- page: Overview
icon: fa-solid fa-plug
path: pages/websockets.mdx
- page: Quickstart
icon: fa-solid fa-bolt
path: pages/websockets-quickstart.mdx
- section: Best Practices
contents:
- page: Email Deliverability
Expand Down
50 changes: 50 additions & 0 deletions fern/pages/websockets-quickstart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: "WebSockets Quickstart"
subtitle: "Get started with real-time email event streaming"
slug: websockets/quickstart
---

```typescript title="TypeScript"
import { AgentMailClient } from "agentmail";

const client = new AgentMailClient();

async function main() {
const socket = await client.websockets.connect({
apiKey: process.env.AGENTMAIL_API_KEY,
});

socket.on("message", async (event) => {
if (event.type === "subscribed") {
console.log("Subscribed to", event.inboxIds);
} else if (event.eventType === "message.received") {
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 13, 2026

Choose a reason for hiding this comment

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

P1: Inconsistent event discriminator: event.type is checked for the subscribed case but event.eventType for the message-received case. If the SDK uses a single discriminant field, one of these checks is wrong and the corresponding branch will never execute. Verify the SDK's actual event shape and use a consistent property name.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At fern/pages/websockets-quickstart.mdx, line 20:

<comment>Inconsistent event discriminator: `event.type` is checked for the subscribed case but `event.eventType` for the message-received case. If the SDK uses a single discriminant field, one of these checks is wrong and the corresponding branch will never execute. Verify the SDK's actual event shape and use a consistent property name.</comment>

<file context>
@@ -0,0 +1,50 @@
+  socket.on("message", async (event) => {
+    if (event.type === "subscribed") {
+      console.log("Subscribed to", event.inboxIds);
+    } else if (event.eventType === "message.received") {
+      console.log(`Received message from: ${event.message.from}`);
+    }
</file context>
Fix with Cubic

console.log(`Received message from: ${event.message.from}`);
}
});

await socket.waitForOpen();

socket.sendSubscribe({
type: "subscribe",
inboxIds: ["my-agent@agentmail.to"],
});
}

main();
```

```python title="Python"
from agentmail import AgentMail, MessageReceivedEvent, Subscribe, Subscribed

client = AgentMail()

with client.websockets.connect() as socket:
socket.send_subscribe(Subscribe(inbox_ids=["my-agent@agentmail.to"]))

for event in socket:
if isinstance(event, Subscribed):
print(f"Subscribed to {event.inbox_ids}")
elif isinstance(event, MessageReceivedEvent):
msg = event.message
print(f"Received message from: {msg.from_}")
```
Loading