Write a gateway connector
A gateway connector brings a chat platform into the
Gateway without a change to Fleet. A connector is
any program. Fleet runs it once per call, through fleet-exec, as it runs a
runtime. The connector is the
platform's adapter: it maps the Gateway port
onto the platform's API. Fleet's controllers do not change.
Slack and Discord are built-in adapters
(gateway adapters). Every other platform
is a connector. The reference connector,
examples/gateway-connectors/file.sh,
keeps its platform in files. The end-to-end tests drive it through the built
fleet binary.
Microsoft Teams is planned as a connector in a repository of its own,
fleet-gateway-teams
(Thurbeen/thurbox#1999).
The parts #
| Part | Who runs it | What it does |
|---|---|---|
| The connector | Fleet, one bounded process per call | Parses addresses and events, reads history, posts, opens threads. |
| The listener | The operator's service manager | Holds the platform's connection or queue. Pipes each event into fleet gateway receive. |
fleet gateway receive |
The listener, once per event | Asks the connector's event verb to read the event. Stores the result in the thread's Conversation. |
The listener is transport only, as for Slack and Discord (inbound transport). A connector and its listener can be one program with two modes.
The protocol #
Fleet runs <program> [args] <verb>. The request is one JSON object on
stdin. The answer is one JSON object on stdout, with exit status 0:
{"known": <value>}: the verb's answer.{"unknown": {"why": "…"}}: the connector cannot tell.
Fleet takes these as Unknown: a program that is not there, a non-zero exit, a timeout, and output that does not parse. Unknown never concludes. Fleet never takes an Unknown write as absent.
Every request carries "protocol": 1 and account:
account field |
Meaning |
|---|---|
name |
The account's name under [gateway.accounts]. Absent on event: two accounts with the same settings read events alike. |
platform |
The connector's name. |
bot |
Fleet's bot id on the platform. |
inbound |
How the listener delivers. |
team |
The platform's workspace identity, when the account sets one. |
credentials |
A path to the operator's credential file, when the account sets one. |
options |
The account's options table, as JSON, when the account sets one. |
The verbs map one to one onto the Gateway port. Each value has the JSON shape
that Fleet's resources use: ConversationRef, Delivery, Message,
Capabilities and History are in Conversation
and in crates/fleet-api/src/gateway.rs.
| Verb | Required | Request (besides protocol, account) |
Known answer |
|---|---|---|---|
manifest |
yes | — | {"protocol": 1, "platform", "verbs": [...]} |
parse |
yes | address |
a ConversationRef |
event |
yes | envelope, as the listener sent it |
a Delivery, or null for a payload that carries nothing for Fleet |
whoami |
yes | — | an Identity: {"id", "name"} |
capabilities |
yes | — | Capabilities: history, marker, unmentioned, threads, reactions |
post |
yes | conversation, text, intentKey |
{"type": "posted", "message", "at"} or {"type": "failed", "why"} |
history |
no | conversation, query |
a History: messages, leftOut, starter |
open |
no | channel, text, intentKey |
{"type": "opened", "conversation", "message", "at"} or failed |
react |
no | conversation, message, reaction, on |
{"type": "reacted", "already"} or failed |
link |
no | thread |
a URL string, or null |
fetch |
no | conversation, file, dir, a directory that Fleet made for this call |
{"outcome": "saved", "path", "bytes"} or {"outcome": "refused", "why"} |
Fleet reads the manifest once per process. It refuses the connector when:
- the manifest's
protocolis not 1, - the manifest's
platformis not the connector's name, - a required verb is missing from
verbs.
Fleet does not call an optional verb that verbs does not list:
- Without
history, the account has no history. - Without
open,reactorfetch, that write fails with a reason. - Without
link, a log post names no link.
A history Unknown can carry kind (timeout, incomplete, throttled,
unreadable, refused) and retryAfter in milliseconds.
The rules a connector keeps #
The common rules of the built-in adapters apply. These rules apply to every connector:
- One verb, one bounded process. Finish inside the account's
callTimeoutMs. Fleet kills the process tree after it. - Every write is keyed. Two
postoropencalls with oneintentKeymake one message. Split a long text yourself, under keys derived from theintentKey. A connector with no way to find an earlier post reportsmarker: "none", and Fleet then never repeats an Unknown post. eventmakes no write. The receive verb runs it without the lease.- Names are your platform's. The
platformof eachConversationRefis the connector's name. An address is<platform>:<chat>[:<thread>]. Encode a:inside an id. - Identity is an opaque id.
author.idis the id that[gateway.people]maps. A message frombothas the author kindfleet. - A refusal is Known; anything unclear is Unknown.
fetchsaves one file directly indir. Fleet makesdirfor the call, under the directory thatfleet gateway filewrites to, and only Fleet's user can enter it. Fleet refuses a path anywhere else.historykeeps the newest. Anafterread answers at mostlimitmessages, the newest, and counts the rest inleftOut. Asinceread is complete. A channel address reads the channel's top-level messages.
Configuration #
[gateway.connectors.teams]
program = "fleet-gateway-teams" # on PATH, or an absolute path
args = [] # optional, before the verb
callTimeoutMs = 20000 # optional; else gateway.callTimeoutMs
[gateway.accounts.teams-main]
platform = "teams" # the connector's name
team = "<tenant id>"
bot = "28:<app id>"
inbound = "connection"
credentials = "/etc/fleet/teams.conf"
options = { serviceUrl = "https://smba.trafficmanager.net/emea/" }
- A connector's name cannot be a built-in platform's name.
- A connector account's
inboundisconnection. - A connector account takes
credentialsandoptions. It does not takecli,curlConfig,dirormessageContent. credentialsis an absolute path.
Configuration lists every key.
Secrets #
Fleet holds no platform credential:
- Fleet passes the
credentialspath in each request. Fleet never opens the file. credentialsandoptionsstay in the config file. Fleet writes neither to the store, to a Task's environment, or to the listener's digest.- The connector runs with the manager's environment.
Keep the credential file readable by the user that runs Fleet only.
Check a connector #
fleet gateway check -- <program> [args] is the conformance suite. It
prints one line per case: ok, skip with why, or FAIL with why. It
exits non-zero when any case fails. These cases need no platform:
manifestnames protocol 1, the platform that--platformgives, and every required verb, and lists no verb that protocol 1 does not have;- a request on another protocol answers
{"unknown": …}; - an unknown verb answers
{"unknown": …}; - an empty address does not parse, and every answer to
parseis a conversation on the connector's platform or Unknown; - the sample address
<platform>:C0CHECK:T0CHECK, when it parses, gives the same parts when its own address is parsed again. The case is skipped when the sample does not parse; - an event with an empty payload answers
{"known": null}or{"unknown": …}.
In these cases a crash, a non-zero exit or output that Fleet cannot read fails. Fleet takes such an answer as Unknown when it serves a connector, but the suite reports it. The remaining offline cases:
whoaminames an id;capabilitiesreporthistoryandreactionsonly when the manifest listshistoryandreact.
With --channel <address>, the suite also posts one message in that
channel. Give it a test channel:
- a post answers
posted; - a second post with the same intent key answers the same message. The case
is skipped when
markerisnone; - a
sinceread ofhistoryon the same address holds the message, under its key whenmarkerismetadata. The case is skipped without history.
The flags give the account that each request carries: --platform
(default check), --bot, --team, --credentials, and --option KEY=VALUE, once per option. A value that parses as JSON is JSON.
--call-timeout-ms bounds each call (default 15000).
fleet gateway check --platform teams --credentials /etc/fleet/teams.conf \
--option serviceUrl=https://smba.trafficmanager.net/emea/ -- fleet-gateway-teams
fleet version --json names the protocol as gatewayProtocol.
crates/fleet-cli/tests/e2e_gateway_connector.rs runs the suite against the
reference connector, and drives it through fleet gateway receive and
fleet reconcile.