WebhookChannel
in package
implements
NotificationChannelInterface
FinalYes
Generic JSON HTTP POST. Works with Discord, Microsoft Teams, custom webhooks, and most pull-style monitoring endpoints.
The payload-shaping callable lets you adapt the Notification to whatever JSON the target endpoint expects. Default payload is { title, body, severity, context }.
The default HTTP transport uses stream_context_create + file_get_contents and requires no PHP extensions beyond the core. Inject a custom $httpClient to use Guzzle, Symfony HttpClient, or any PSR-18 client.
Table of Contents
Interfaces
- NotificationChannelInterface
- A delivery mechanism for notifications. Implementations should swallow transient delivery errors rather than propagating them; the pipeline must not crash because Slack is down.
Methods
- __construct() : mixed
- name() : string
- Stable identifier for routing or filtering (e.g., "slack", "email", "log").
- send() : void
Methods
__construct()
public
__construct(string $url[, string $name = 'webhook' ][, array<int, string> $extraHeaders = [] ][, callable(Notification): array<string, mixed>|null $payloadFactory = null ][, callable(string, array<int, string>, string): void|null $httpClient = null ]) : mixed
Parameters
- $url : string
-
The webhook URL.
- $name : string = 'webhook'
-
Channel identifier used by routing/filtering.
- $extraHeaders : array<int, string> = []
-
Headers added on every send (e.g. auth tokens).
- $payloadFactory : callable(Notification): array<string, mixed>|null = null
-
Maps a Notification to the JSON body shape.
- $httpClient : callable(string, array<int, string>, string): void|null = null
-
Custom HTTP transport.
name()
Stable identifier for routing or filtering (e.g., "slack", "email", "log").
public
name() : string
Attributes
- #[Override]
Return values
stringsend()
public
send(Notification $notification) : void
Parameters
- $notification : Notification
Attributes
- #[Override]