Skip to main content
Experimental. The contract has been run end to end with the Slack connector against a real Slack app, but it may still change in a minor release until the first connector has a release of its own.
A connector brings one or more messaging channels — Telegram, Viber — to an installation. It is a Composer package, installed when the image is built, like a Solution. Unlike a Solution it is not activated per tenant: once installed, its channel types exist for the whole installation, and which tenant may use them is the operator’s decision. Two channels serve as references: Telegram, built into Core, and Slack, the package fapost-lab/connector-slack. Channel contracts maps each contract to their classes.

The manifest

A connector describes itself in its own composer.json: "type": "fapost-connector" and an extra.fapost block. Core reads it on platform:update without running your code.
Any other field is an error. When two packages claim one id, or two connectors one channel type, none of them is booted and platform:update stops with nothing changed. The rules live in Foundation (Fapost\Foundation\Connector\Manifest\ConnectorManifestParser), a pure function you can run in your package’s CI.

The service provider

Core calls registerChannels() once per process, after every provider’s register() and before any boot(). registerBindings() runs in register(), bootConnector() in boot(). Core boots connectors before Solutions. A ConnectorChannel names classes, not instances: Core builds each service inside the request or job that uses it and never shares one across requests or jobs, so a service may depend on tenant-scoped bindings. Core also builds one instance at boot to check it, so constructors must be cheap and must not touch tenant data. A sender gets the channel with each call: deliver(OutboundMessage $message, ChannelInterface $channel). Read the token and the channel’s settings from $channel->getConfig() (token, and the values your profile declares under options, such as sender_name for Viber) while you call the provider, and keep none of them. Boot fails, naming your connector, when you register a type your manifest does not declare, a type Core serves itself (such as telegram), a type twice, a class that does not implement its interface, a media class or a profile whose channelType() is another type, or a profile whose settings contradict themselves. platform:update also refuses a declared type you never register.

Buttons and capabilities

A channel that declares no capabilities is text and media only, and Core sends it nothing else. Declare what the channel can do with ChannelCapability: CallbackButtons, ReplyButtons, ShareContact, ShareLocation, RemoveButtons (strip the buttons of a message already sent) and PersistentButtons (callback buttons of older messages stay pressable). Core describes the buttons of a message by what a press does, not by where a channel draws them: MessagePayload::$buttons is a ButtonSet of rows of Button. Each button has a label and an action: Callback (the press returns a hidden payload), Reply (the press sends the label as the user’s message), ShareContact or ShareLocation. A set holds either callback buttons only or none. Translate it into the provider’s format in your sender. Core’s flow messages carry buttons and leave MessagePayload::$keyboard null; keyboard is deprecated, so a sender that reads only it shows no buttons. The flow builder reads these declarations: when a flow uses something one of the assistant’s channels does not declare (for example a contact request on a channel without ShareContact), validation shows a warning naming the channel and the capability. A warning never blocks publishing, so an undeclared capability only means that part of the flow degrades on that channel.

Button limits

ChannelCapabilities takes a ButtonLimits as its second argument: maxButtons (in one message), maxButtonsPerRow and maxLabelLength (in UTF-8 characters). null, the default, means the channel declares no limit and nothing is checked. When a flow’s keyboard is larger than a declared limit, validation shows a channel_button_limit_exceeded warning naming the channel, the limit and the actual size. It is a warning only and never blocks publishing, so declare what the provider documents or what you have observed it to enforce. You need no limit for the payload length: it is at most 64 bytes on every channel. Telegram, for example, declares 100 buttons and 8 per row and leaves the label length open: its Bot API documents no keyboard counts or label length, and clients truncate long labels. When the user presses a Callback button, report it as an IncomingMessage of type IncomingMessageType::CallbackQuery whose text is the button’s payload, unchanged. How the provider delivers the press is the connector’s business. The payload is at most Button::MAX_PAYLOAD_BYTES (64) bytes and Core treats it as opaque to you. Core knows nothing about your provider, so the channel form, the rules that check it and the link to your bot come from a profile you declare:
A managed value is reported when the provider has told it, for example in the registrar that sets the webhook:
A setting is one of five types: Text, Integer, Boolean, Choice (one value of choices) and Choices (a list of them). Core builds the validation rules and the form control from the type, min, max, required and choices; you never validate a value yourself. Values live under their key in the channel’s config. A field is never secret, because config is plain JSON that reaches queued jobs: keep secrets in the channel’s token and secret token.
  • Texts. label, help and the labels of choices are English. Set translationKey to show a translation: Core looks for {translationKey}.label, .help and .choices.{value}, and falls back to your English text. Load your translation files with loadTranslationsFrom in your provider. A help text may use :min, :max and :default.
  • Managed fields. A field with managed: true holds a value the integration reads from the provider, such as Telegram’s bot name or Viber’s account URI. The form neither shows nor accepts it, and saving the form keeps the stored value. You never write it yourself: inject Fapost\Foundation\Channel\Settings\ManagedChannelSettingsInterface into your webhook registrar and call report($payload->channelId, ['account_uri' => $uri]) after the provider answers (see below). It needs the channel’s id and runs in the channel’s tenant, which the registrar has; the inbound adapter has neither, so it cannot report a value yet. A null removes the key. Core checks each value against the field’s type, min, max and choices, stores it, and does not synchronize the provider again because of it. A key that is not a managed field of your schema, or a value that does not fit, throws InvalidManagedSettingException: that is a mistake in the connector, and it shows in the failed job. A channel deleted in the meantime is ignored.
  • Secret token. Set usesSecretToken: false when the provider has no webhook secret; the form then does not ask for one. A secretTokenPattern (PCRE, no delimiters) restricts what an operator may enter.
  • Public link. publicLink() reads the stored config, managed fields included, and returns how a person finds the bot: the handle, and a link that opens the chat. Core shows it in the channel list and gives it to flows as system.channel.
  • No profile. A channel without one has no settings, any secret token and no link.
  • Your own configuration. A connector is an ordinary Laravel package: publish and merge its configuration file with mergeConfigFrom in your provider.
mediaLimits names a class that says how large a file the provider accepts for each kind of media; Core warns before someone attaches a larger one.

Inbound webhooks

The inbound adapter does not verify signatures in code. It declares how in an IngressSpec, which Core and the ingress gateway both execute, and turns a verified body into an IncomingMessage in the worker:
If your provider signs requests in a way no SignatureScheme covers, the scheme is extended in Foundation and the gateway; a connector cannot ship its own check.

Signed timestamps, forms and challenges (IngressSpec version 2)

Some providers sign more than the body, send the event inside a form field or ask the URL to prove it is yours first. These are optional parameters of the IngressSpec constructor; a spec that sets none of them stays version 1: A template placeholder may list alternatives: {body.event_id|body.trigger_id} takes the first one that is not empty. {body.*} placeholders read the request document: the JSON body, or the JSON in the form field. That document is also what your adapter’s normalize() receives. A refused request, as before, is answered 200 {"ok":true}. Every delivery your adapter accepts must give the idempotency key a non-empty id. A key whose placeholders all resolve empty (acme:{channel}:) is one shared slot for 24 hours, so every later delivery of that shape is dropped as a duplicate. Add an alternative, or treat such a delivery as one to ignore.
A gateway built before version 2 does not understand such a spec and forwards the request to the application, which verifies it itself, so the connector works before the gateway is upgraded; it only loses the gateway’s speed.

Deliveries that are not messages

Providers also send the bot’s own messages, edits and system events. When normalize() meets one, throw Fapost\Foundation\Channel\InboundEventIgnoredException with a short reason. Core drops the delivery: no contact is created, nothing reaches the transcript and the job is not retried. The reason is written to the debug log.

The setup guide

A person connecting a channel often has work to do at the provider: paste the webhook URL, add a manifest. Let your profile also implement ChannelSetupGuideInterface and the console shows those steps beside the channel form:
$webhookUrl is the channel’s public webhook URL, or null while the channel is not yet created; $config is its stored configuration. The method does no I/O. A step has a title, an optional text, an optional value to copy (Text, Url or Code, such as a manifest) and an optional translation key: Core looks for {key}.title and {key}.text in its translations (add yours with loadTranslationsFrom) and falls back to the English text of the step. The URL contains the channel’s public hash, so only users who can manage channels see the guide.

Testing a connector

Fapost\Testing\ConnectorTestCase boots Core with its test database and gives a connector’s own tests what they need, without importing anything from App\. Nothing reaches a real Redis or queue. It is experimental and may change in minor versions before 1.0. Fake the provider’s HTTP API with Http::fake().

When a connector is removed

Channels of a type no connector serves any more stay in the database untouched. The console marks them unavailable and lets you delete them; their incoming webhooks are logged and acknowledged without being processed, and php artisan platform:update lists them per tenant. Installing the connector again brings them back.

Installing

The connectors that exist today are listed in Connectors. Add the package to your image through the build overlay (Building your own images), then run php artisan platform:update: it lists the installed connectors with their channel types, or refuses with every manifest problem it found.