folkwaysDocs
Realtime API

POST /v1/dm/open

Open a direct-message or group room for 2 to 50 users and invite each of them on their personal topic.

Your backend opens a room for a set of users. The Realtime API names the room, adds the members to it if it is private, and posts an invite on each member's personal topic. JSON, not frames; service tokens only.

Request

HTTP
POST https://realtime.folkways.net/v1/dm/open
Authorization: Bearer <service token>
Content-Type: application/json

{ "members": ["user:1", "user:2"], "prefix": "dm", "data": { "startedBy": "user:1" } }
FieldDefaultMeaning
membersrequired2 to 50 distinct identities, each one topic level
prefix"dm"Where the room goes: {prefix}/{id}. The room must match a topic rule
datanullAny JSON, passed through in every invite

The service token needs publish on the room (e.g. dm/>) and on every member's $user/{identity} (e.g. $user/>). All rights are checked before anything is written.

Response

200 OK
JSON
{
  "topic": "dm/5f0c8e1d2a9b44c7e1f03a6d",
  "members": ["user:1", "user:2"],
  "invites": [
    { "identity": "user:1", "topic": "$user/user:1", "duplicate": false },
    { "identity": "user:2", "topic": "$user/user:2", "duplicate": false }
  ]
}
  • One room per set of members. The ID is derived from the sorted, distinct members, so the same members always get the same room in this segment, and two simultaneous opens land in one room. The name isn't a secret: access comes from rules, tokens and member lists.
  • Invites are invite stream events with { "type": "dm", "topic", "members", "data" }. Opening the same room with the same data again within 10 minutes sends nobody a second invite (duplicate: true).
  • Members-only rooms. If the room's rule is members-only, members not yet on its list are added with every op the rule allows before any invite goes out. Members already on it keep their entry, so reopening never undoes a block. Each member's token then only needs a ceiling such as dm/> with subscribe and publish. For a public rule, put the room in each member's token instead.
  • Partial failure. Invites go out one member at a time. If one fails, send the same request again: invites already sent come back duplicate: true and only the rest are written.

The member's app receives the invite on $user/{identity} and subscribes to its topic.

Errors

StatuserrorWhen
401AuthRequired, AuthInvalid, AuthExpiredNo token, or a bad one
403ForbiddenNot a service token; no rule for the room; no publish on the room or a member's $user topic. Nobody is invited
403SuspendedThe segment is suspended
400InvalidArgumentFewer than 2 or more than 50 members, an identity that can't have a personal topic, unknown fields
400InvalidTopicprefix isn't a valid topic name
429QuotaExceededA topic, personal-topic or monthly limit would be passed. Nobody is invited
429RateLimitedThe segment's backend request budget is used up. Wait retry_after_ms; nothing was written
503Unavailable, DrainingTry again

No CORS: browsers never hold service tokens.

On this page