Routing
Slack routing is independent of the message content. It is selected via
Notification, Notification, or a
notifiable's route method.
Four route styles
| Route | Example | Notes |
|---|---|---|
| Named webhook | Slack | Recommended for queued delivery; no URL secret in the route object. |
| Direct webhook | Slack | Approved HTTPS Slack URL; the URL is a secret. |
| Web API | Slack | Supply the token here otherwise the engine will get it from the extension configuration. |
| url as string | Slack or Slack | The engine will try to guess whether it's an Incoming webhook and an API |
Named webhooks
$manager->route(
'slack',
SlackRoute::webhookNamed('security')
)->notify(new SecurityAlert());
// Shorthand accepted by SlackRoute::fromString():
$manager->route('slack', 'webhook:security')
->notify(new SecurityAlert());
The alias must exist in webhooks inside
$GLOBALS.
If it does not exist, delivery fails with a configuration exception.
Direct webhook
$manager->route('slack', SlackRoute::webhook($webhookUrl))
->notify(new SecurityAlert());
The validator permits HTTPS URLs with a Slack or GovSlack webhook host
and a /services/.../.../... path. A webhook URL is a credential.
Avoid serializing it into Messenger jobs; use a named webhook instead.
Slack Web API
$manager->route('slack', SlackRoute::api('C0123456789', '_optional_token_'))
->notify(new SecurityAlert());
// An ID string is also accepted:
$manager->route('slack', 'C0123456789')
->notify(new SecurityAlert());
Slack accepts a supported Slack conversation/user ID
prefix (C, D, G, U or W) followed by uppercase
letters/digits. The Slack API ultimately determines whether that ID can
receive messages and whether the app has access.
Multiple recipients
The core notification dispatcher can send one notification to a collection of notifiable objects, each returning a different Slack route:
$manager->send(
[$monitoringRecipient, $securityRecipient],
new SecurityAlert(),
);
Slack intentionally does not accept a channel or token
field: routing and credentials belong to the channel and transport.