ConnectorRegistrarInterface.
No channel needs a change in Core. This page is the reference for the contracts a channel
implements. Connectors explains how to package and register them.
A channel has two halves. Ingress accepts and verifies what the provider sends you.
Egress delivers what the assistant says back.
Two references
Read the contracts below next to two working channels. Both describe themselves with the sameConnectorChannel and implement the same interfaces.
- Telegram is built into Core, in
app/Domains/Channels/Telegram. It uploads media to the provider and declares every kind of button. - Slack is a package,
fapost-lab/connector-slack. It is the connector an outsider would write: a manifest, its own translations, a signed timestamp and a URL challenge on ingress, and media sent by link. It has been run end to end against a real Slack app but has no release yet.
Identity
Fapost\Foundation\Channel\ChannelInterface is the minimal identity exposed across
the extension boundary. Core’s channel models implement it, so code outside Core can
read identity and credentials without depending on App\…:
getType() is a string rather than an enum, so that Foundation stays free of Core’s
taxonomies.
Ingress
The ingress side is declarative. The inbound adapter describes how its webhook is authenticated and deduplicated in anIngressSpec, and does no verification in code:
Because the spec is data rather than code, the same description is executed by PHP
and by the Go webhook gateway in front of it. The spec also
carries the idempotency key template, such as
tg:{channel}:{body.update_id}. Signed
timestamps, form-encoded bodies and URL challenges are covered by
IngressSpec version 2.
Verified traffic becomes an InboundWebhookPayload. The adapter’s normalize() turns it
into an IncomingMessage with its IncomingMessageType and any IncomingMedia, or throws
InboundEventIgnoredException for a delivery that is not a person’s message. Providers
echo the bot’s own messages and its edits back to the webhook, so this matters: Slack sends
both, and an adapter that normalized them would make the assistant answer itself.
Egress
Delivery goes through a transport sender:$channel->getConfig() during the
call (token, secret_token, and the channel’s settings under options), and never
keep or log them. TypingCapableProviderInterface receives the channel the same way and
exposes a typing or processing indicator through a ProcessingIndicatorHandle.
DeliveryResult reports sent, the provider’s message id and, on failure, an error.
When the provider refuses a message, put its reason in the error or the exception, not
only its code: a refusal such as Slack’s invalid_blocks says nothing until you add the
detail the provider sent with it. A failed send moves the flow to the node’s error edge;
with no such edge the flow ends.
A message with buttons carries them as a channel-neutral ButtonSet in
MessagePayload::$buttons, and the sender translates it into the provider’s format. What a
channel can show is declared through ChannelCapabilities. A press on a callback button
comes back as an IncomingMessage of type CallbackQuery whose text is the payload
unchanged. See Buttons and capabilities.
Media
Sending. A channel either uploads files to the provider or lets the provider fetch them.-
ChannelMediaUploaderInterfaceuploads the file and gives the provider’s id back. Telegram works this way. A provider can store a file as another kind than the method asked for (Telegram answers a WAV sent as audio with adocument), and a cached file id has to be sent by the method that matches it. An uploader whose provider may do this puts the kind it got back inUploadResult::$providerKindand implements the markerFapost\Foundation\Media\ReportsProviderKind(needsfapost/foundation^0.41). Core keeps the kind with the cached id and sends by it: the kind becomes the outgoingMessagePayload::$typeand the key undermediathat your sender receives. The accepted values arephoto,video,audio,voiceanddocument; any other value is stored with the cached id (so the id stays cached), but when sending Core takes the message type from the MIME type instead. For a marked uploader, a cached id with no kind predates this and is uploaded again once, so the kind gets stored. An uploader without the marker keeps its cached ids as they are. Files that come in are cached the same way, so the adapter’snormalize()sets the kind on eachIncomingMediait returns, in the same vocabulary:IncomingMedia::$providerKind(needsfapost/foundation^0.49). Telegram’s adapter sets the field the file came in, such asvoiceordocument. Core stores what you report and does not derive it from the message type; when it is null, the incoming file id is cached without a kind, as described above. -
A provider that accepts pictures, video and files only as a URL it fetches itself registers
ChannelMediaLinkPolicyInterfaceinstead. Core then puts a signed public link to the file in the outgoing payload, issued just before delivery:media.url, withmime_type,size(bytes),file_name(with its extension) andkind(image,video,audioordocument).linkTtlSeconds()asks for how long the link stays valid; Core caps it. The payload’stypeis shaped for channels that upload, so choose the provider’s message type frommime_type. A channel type with an uploader keeps uploading.
invalid_blocks. Use a tunnel to test.
Receiving. ChannelMediaDownloaderInterface::download() returns a DownloadResult: a
PSR-7 stream, the MIME type, the size and optionally the file name. The stream may be the
body of a streamed HTTP response. It need not be seekable: Core reads it once, from where it
stands. Core downloads files of incoming messages in a queued job after the message is
logged, so the flow does not wait for them.
Rate limits are preventive
Provider rate limits and backpressure are handled before sending, not as a reaction to the provider’s error. A sender that discovers the limit by being rejected has already spent the request, and on a broadcast that failure multiplies.Checking a channel against the real provider
ConnectorTestCase and recorded payloads prove the code. Before you call a channel done,
run it against the provider itself through a tunnel. Slack
was checked this way:
- the URL challenge is answered, and every request’s signature is verified;
- a person’s text reaches the flow, and the flow’s text, formatting and emoji reach the person;
- buttons arrive, a press takes the right branch, and the buttons are removed afterwards;
- the bot’s own messages and edits are ignored, so the assistant never answers itself;
- a picture from the flow arrives with its caption, and a file from the person is stored.