Documentation
Sign inGet started

Sending events to a member

Some events concern one person rather than a topic: an order shipped, a document was shared with them, their balance changed. You can send those to the member directly, without creating a channel for each person.
This page covers how to receive member events in your app, how to send one from your server, and who receives it.

Before you start

The member must be signed in. A connection with no identity cannot receive member events. See Authorized connections for signin() and the endpoint it calls.

Receive events in your app

Bind the event name on bird.member after signin() succeeds. The name is the same string your server sends as event. There is no channel to subscribe to.
Exemplo de código
import { BirdRealtime } from "@messagebird/realtime";

const bird = new BirdRealtime({
  appKey: "your-app-key",
  region: "us1",
  memberAuthEndpoint: "/bird/auth/member",
});

await bird.signin();

bird.member.bind("order.shipped", (data) => {
  showToast(`Order ${data.order_id} is on its way`);
});
The binding keeps working across a dropped connection. The client signs in again when it reconnects and resumes delivery.

Send an event from your server

Call members.send with the app id, the member id, and the event:
Exemplo de código
await bird.realtime.members.send("rap_01krdgeqcxet5s7t44vh8rt9mg", "u_42", {
  event: "order.shipped",
  data: { order_id: "ord_123" },
});
The same call with curl:
Exemplo de código
curl -X POST \
  https://us1.platform.bird.com/v1/realtime/apps/rap_01krdgeqcxet5s7t44vh8rt9mg/members/u_42/events \
  -H "Authorization: Bearer $BIRD_API_KEY" \
  -H "X-Realtime-Key: $BIRD_REALTIME_KEY" \
  -H "X-Realtime-Secret: $BIRD_REALTIME_SECRET" \
  -H "Content-Type: application/json" \
  -d '{ "event": "order.shipped", "data": { "order_id": "ord_123" } }'
u_42 is the member_id your auth endpoint signed for that person. Use the identifier your own system already has, within the limits described in Authorized connections.

Who receives the event

  • Every connection that member holds, across their tabs and devices. One call, however many connections.
  • Nobody else, even if another member's app binds the same event name.
  • Nothing, if the member has no live connections. The call succeeds and the event is dropped, the same as an event published to a channel with no subscribers. Store anything a person must see later and load it when they return.

Member or private channel

Use a member eventUse a private channel
The recipient is the destination: personal notifications, account changesThe destination is a shared thing several people watch: a document, an order, a room
No channel to name or authorizeYou name the channel and authorize each subscription
No presence, connection counts, or client eventsPresence, connection counts, and client events are available

Next steps