Channel Adapters
A channel adapter connects one messaging platform (Signal, Telegram, a webhook, or your own) to an agent. The adapter owns the platform: inbound, outbound, sender identity, receipts and reconnect. The gateway and ChannelService only see the normalized shapes below, so no platform-specific code lives in the runtime.
Signal, Telegram and webhook adapters ship in @reactive-agents/channels. See Messaging Channels to use them. This guide is the canonical home of the adapter contract and is for writing a new adapter.
The contract
Section titled “The contract”interface ChannelAdapter { id, platform, capabilities accountFingerprint?: string // non-secret hash of the account; the router leases one poller per fingerprint inbound: Stream<InboundEnvelope, ChannelError> // backpressured state: Stream<ConnectionState> currentState: Effect<ConnectionState> deliveryUpdates?: Stream<DeliveryUpdate> // when capabilities.receipts setSenderGate?(gate): void // adapters that download attachments consult it first sendTyping?(conversation): Effect<void, ChannelError> // optional typing indicator; absence means unsupported start(): Effect<void, ChannelError, Scope> // closing the scope disconnects send(message: OutboundMessage): Effect<DeliveryReceipt, ChannelError>}The gateway and ChannelService only see these shapes:
| Shape | What it carries |
|---|---|
InboundEnvelope |
platform message id (idempotency key), conversation (channelId, threadId?, isGroup), sender (platform, userId, displayName?), text, attachments, replyTo?, mentionsSelf, isEcho, receivedAt, metadata? (small extras, never secrets) |
OutboundMessage |
conversation (channelId, threadId?), text, format? (plain or markdown), attachments?, replyTo? |
DeliveryReceipt |
the platform’s real messageId, adapterId, platform, status (sent, queued, delivered), sentAt |
DeliveryUpdate |
a later confirmation for an earlier send: messageId, status (delivered or read), at |
ChannelError |
kind, retryable, retryAfterMs?, a generic message, and the raw error in cause |
ConnectionState |
connecting, connected, reconnecting (with error), disconnected, failed (with error) |
capabilities |
threads, attachments, markdown, receipts, groups, maxTextLength?, maxAttachmentBytes? |
Rules the contract enforces:
inboundis backpressured. A slow consumer slows the adapter; messages are not dropped.InboundEnvelope.idis an idempotency key. The adapter never emits the same id twice. Echoes of the bot’s own sends setisEcho: true, andChannelServicedrops them.- Identity is namespaced.
senderis{ platform, userId }. Access control keys onplatform:userId, so ids on different platforms never collide. sendreturns a real receipt (the platform’s message id, withstatusofsent,queuedordelivered) or fails with a typedChannelError. Never fabricate an id.- Errors are typed.
ChannelError.kindis one ofauth,rate_limited,not_found,forbidden,too_large,unsupported,network,conflict(another consumer owns the account, for example Telegram 409),unknown. Onlyrate_limitedandnetworkare retryable;conflictstops the channel instead of retrying in a loop. The message is generic by design: the raw platform error goes incauseand is never logged or published, because it can contain URLs and tokens. - Secrets are
Redacted(or read from env or a key store) and never appear in errors, receipts, state or logs. capabilitiesare honest. Declarethreads,attachments,markdown,receipts,groupsand the size limits so callers degrade instead of guessing.
What ChannelService does with an adapter
Section titled “What ChannelService does with an adapter”ChannelService consumes the adapter’s backpressured inbound stream, drops echoes, applies access control keyed on platform:userId, runs the trigger and session, and sends the reply itself through adapter.send. Compared with the legacy MCP-server path (the model decides to call a send tool), that gives you:
- Receipts.
ChannelMessageSentis published only after a successful send and carries the platform’s real message id. - Typed failures. A failed send is counted in
status()(deliveryFailures,lastError) and published as aChannelDeliveryFailedevent.channelService.deliver(adapterId, message)returns the receipt or fails with aChannelError, so a workflow can branch onrate_limitedorauth. The raw platform error stays incauseand is never published. - Honest status.
status().adapters[].connectedreflects the adapter’s reportedConnectionState.
The adapter’s deliveryUpdates stream is not published as an EventBus event by ChannelService; read it directly if you need delivery or read confirmations.
Shared building blocks
Section titled “Shared building blocks”Do not re-invent these. They are exported from @reactive-agents/channels.
| Helper | What it gives you |
|---|---|
makeConnectionState() |
An observable ConnectionState (state, current, set), disconnected until you set it |
withReconnect(adapterId, open, conn, schedule?) |
Turns “open a connection and stream from it” into a stream that survives drops. A retryable error sets reconnecting and reopens with backoff (default: exponential from 500 ms, capped at 30 s). A non-retryable error such as auth sets failed and stops, because retrying a bad credential only hammers the platform. open must resume from your cursor so a reconnect neither loses nor repeats messages |
makeOutboundRateLimiter(max, window) |
Wraps an effect so at most max run per sliding window. Excess sends wait; they are never dropped |
makeInboundDedupe(capacity?) |
A bounded “seen this id” check (default 1024, oldest evicted). Returns true the first time, false on a repeat |
classifyChannelFailure(adapter, cause) |
Maps a thrown error (network codes and so on) to a ChannelError |
A minimal adapter
Section titled “A minimal adapter”This in-memory adapter has no real platform behind it. It shows where each piece goes.
import { Effect, Queue, Stream } from "effect";import { channelError, makeConnectionState, makeInboundDedupe, makeOutboundRateLimiter, type ChannelAdapter, type DeliveryReceipt, type InboundEnvelope, type OutboundMessage,} from "@reactive-agents/channels";
export interface MemoryAdapter extends ChannelAdapter { /** Test hook: pretend the platform delivered a message. */ readonly receive: (id: string, userId: string, text: string) => Effect.Effect<void>; readonly sent: () => readonly OutboundMessage[];}
export const makeMemoryAdapter = (id = "memory"): MemoryAdapter => { const inboundQueue = Effect.runSync(Queue.bounded<InboundEnvelope>(256)); const conn = Effect.runSync(makeConnectionState()); const limited = Effect.runSync(makeOutboundRateLimiter(10, "1 second")); const firstSeen = makeInboundDedupe(); const outbox: OutboundMessage[] = []; let counter = 0;
return { id, platform: "memory", capabilities: { threads: false, attachments: false, markdown: false, receipts: false, groups: false, }, inbound: Stream.fromQueue(inboundQueue), state: conn.state, currentState: conn.current, start: () => conn.set({ status: "connected" }), send: (message: OutboundMessage) => message.text.length === 0 ? Effect.fail(channelError(id, "unsupported", { message: "empty message" })) : limited( Effect.sync((): DeliveryReceipt => { outbox.push(message); counter += 1; return { messageId: `${id}-${counter}`, adapterId: id, platform: "memory", status: "sent", sentAt: Date.now(), }; }), ), receive: (msgId, userId, text) => firstSeen(msgId) ? Queue.offer(inboundQueue, { id: msgId, conversation: { channelId: userId, isGroup: false }, sender: { platform: "memory", userId }, text, attachments: [], mentionsSelf: true, isEcho: false, receivedAt: Date.now(), }).pipe(Effect.asVoid) : Effect.void, sent: () => outbox, };};A real adapter replaces receive with a platform connection. Wrap the connection in withReconnect so drops reconnect and a bad credential stops cleanly:
inbound = withReconnect(id, openPlatformStream(cursor), conn)Register an adapter with .withChannels({ adapters: [adapter] }). ChannelService consumes inbound, applies access control, runs the agent and sends the reply through adapter.send.
Conformance suite
Section titled “Conformance suite”Every shipped adapter passes one shared suite, runAdapterConformance, in packages/channels/tests/conformance/ of the Reactive Agents repository. It is test code in the repo, not a published export. If you contribute an adapter, add a harness (a fake platform with no network and no tokens) and call:
runAdapterConformance("MyAdapter", makeMyHarness)The suite checks inbound normalization, idempotency, echo handling, group and thread identity, attachments, receipts, typed errors, secret redaction, namespaced identity, honest connection state, backpressure, outbound rate limiting and reconnect. A case that cannot apply (a stateless webhook has no connection to drop) is skipped by name with a stated reason, so skips show in the test output. If you keep an adapter outside the repo, copy the cases you can and treat the list above as your checklist.
What’s Next
Section titled “What’s Next”- Messaging Channels: the shipped Signal and Telegram adapters
- Agent Gateway: access control, ingress and the inbound queue
- Deploying Agents: run the adapter-backed agent unattended
Install
Bun (recommended)bun add reactive-agentsNode 22.5+npm install reactive-agentsGet notified on new releases