Skip to content

docs(websockets): fix event type check for incoming messages - #208

Open
DigitalVeer wants to merge 1 commit into
agentmail-to:mainfrom
DigitalVeer:fix/websockets-event-discriminator
Open

docs(websockets): fix event type check for incoming messages#208
DigitalVeer wants to merge 1 commit into
agentmail-to:mainfrom
DigitalVeer:fix/websockets-event-discriminator

Conversation

@DigitalVeer

Copy link
Copy Markdown

tldr; the WebSockets documentation incorrectly checks event.type for the value "message_received".


The WebSockets overview checks if event.type equals "message_received". However, the server and SDK actually emit { type: "event", event_type: "message.received" }.

As a result, the example code ends up skipping incoming email events since that branch is not executable.

This PR updates the code examples, doc comments, and overly strict type annotations across the WebSockets overview.


Comparison

  • What the WebSocket Docs check:

    if (event.type === "message_received") { ... }
  • What the server actually sends:

    { "type": "event", "event_type": "message.received", ... }

Changes

  1. Fixed five checks across code and documentation to correctly use event.type === "event" && event.eventType === "message.received".
  2. Removed annotations on message handler to remove compilation errors.
  3. Corrected the Message Properties table and code to use the correct from.
  4. Removed two unused AgentMail imports.

tldr; the WebSockets documentation incorrectly checks `event.type` for the value `"message_received"`

---
Right now, the WebSockets documentation checks if `event.type` equals `"message_received"`. In contrast, the API and SDK send `type: "event"` with `event_type: "message.received"`. This example code runs fine, but as a side effect ends up skipping incoming email events since the event branch is never reached.

This PR updates the code examples, doc comments, and overly strict type annotations across the WebSockets overview.

---

### Comparison

* What the WebSocket Docs check:

  ```js
  if (event.type === "message_received") { ... }
  ```

* What the server actually sends:

  ```json
  { "type": "event", "event_type": "message.received", ... }
  ```

### Changes

1. Fixed five checks across code and documentation to correctly use `event.type === "event" && event.eventType === "message.received"`.
1. Removed annotations on message handler to remove compilation errors.
1. Corrected the Message Properties table and code to use the correct `from`.
1. Removed two unused `AgentMail` imports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant