Erlang
Erlang API
src/wiregrid_api.erl is the plain-term boundary. Callers do not build Elixir structs, expand macros, or guess keyword defaults. Every option-bearing function has an explicit arity. New BEAM bindings should target this module. Gleam and LFE already do.
{ok, _} = wiregrid_api:start_instance(chat),
{ok, Sid} = wiregrid_api:connect(chat, <<"alice">>, self()),
Topic = wiregrid_api:topic_channel(<<"general">>),
ok = wiregrid_api:subscribe(chat, Sid, Topic),
{ok, _} = wiregrid_api:publish(chat, Topic, #{type => message}).
Deliveries use the same mailbox tuple, {'$wiregrid', Envelope}. Acknowledge with wiregrid_api:ack(Name, Session, DeliveryId). ack/2 releases one reservation for the session, matching Wiregrid.ack/2.
Constructors
| Function | Term |
|---|---|
topic_user/1 | {user, Id} |
topic_channel/1 | {channel, Id} |
topic_thread/1 | {thread, Id} |
topic_room/1 | {room, Id} |
topic_game/1 | {game, Id} |
topic_document/1 | {document, Id} |
topic_custom/2 | {custom, Namespace, Value} |
target_topic/1 | {topic, Topic} |
target_room/1 | {room, Topic} |
target_user/1 | {user, UserId} |
target_session/1 | {session, SessionId} |
presence_status/1 and presence_custom/1 build status terms. signal_kind/1 checks a signal kind before signal/5 or signal/6.
What is exported
The export list mirrors the Elixir façade: version and capability calls (version/0, protocol_version/0, foreign_protocol_version/0, c_abi_major/0, capabilities/1, describe/1, deployment_report/1), instance start and stop, connect and resume, subscribe and sync_topology/3,4, prepare and every publish/send variant, dispatch and dispatch plans, ack and pending, presence, rooms, activity, typing, receipts, signal, rate limit, webhook, replay, storage, cache, the query functions (session/2, limits/1, subscribed/3, room_member/3, the counts), health, drain, await_idle/1,2, and graceful_shutdown/1,2.
Option lists are plain proplists, the same keys documented for Elixir: {profile, balanced}, {persist, true}, {class, ephemeral}, {session_id, Sid}. Prepared handles stay opaque and instance-local.
Replay
{ok, Stats} = wiregrid_api:replay_session(chat, Sid, Topic),
{ok, Stats} = wiregrid_api:replay_session(chat, Sid, Topic, [{limit, 50}]).
One call reads one bounded storage page and sends it to a live session through normal authorization and delivery pressure. The map includes resume_cursor, next_cursor, delivered, dropped, and stopped.