Skip to content

Extending: alert channel

The NotificationChannelContract interface behind Slack, Discord and Telegram — and why it cannot yet be registered from outside the plugin.

Last updated View as MarkdownAsk ClaudeAsk ChatGPT

A notification channel is anything that can send a delivery-failure alert and describe its own settings to the admin UI. Slack, Discord and Telegram are each one implementation of NotificationChannelContract.

namespace BooleanSmtp\Contracts;
interface NotificationChannelContract
{
public function getIdentifier(): string;
public function getName(): string;
public function send( string $message, array $settings, array $context = [] ): bool;
public function validateSettings( array $settings ): array;
public function getSettingsSchema(): array;
}
Method Returns Purpose
getIdentifier() string The unique channel type — slack, discord, telegram.
getName() string The display name shown in the admin UI.
send($message, $settings, $context) bool Deliver the alert; true when it was accepted for delivery.
validateSettings($settings) array<string, string> Validation errors keyed by field name.
getSettingsSchema() array<string, array{type, label, required}> Field definitions the admin UI’s channel form renders from.
use BooleanSmtp\Contracts\NotificationChannelContract;
class WebhookChannel implements NotificationChannelContract {
public function getIdentifier(): string { return 'webhook'; }
public function getName(): string { return 'Generic Webhook'; }
public function send( string $message, array $settings, array $context = [] ): bool {
$response = wp_remote_post( $settings['url'] ?? '', [ 'body' => wp_json_encode( [ 'text' => $message ] ) ] );
return ! is_wp_error( $response );
}
public function validateSettings( array $settings ): array { return []; }
public function getSettingsSchema(): array { return []; }
}

There is currently no filter to register one

Section titled “There is currently no filter to register one”

Unlike transports (boolean_smtp_transports), the map of available channel types is a plain PHP array in the plugin’s own config/notifications.php — NotificationManager reads it once, at construction, with no filter over it:

config/notifications.php
'channels' => [
'telegram' => \BooleanSmtp\Services\Notification\Channels\TelegramChannel::class,
'slack' => \BooleanSmtp\Services\Notification\Channels\SlackChannel::class,
'discord' => \BooleanSmtp\Services\Notification\Channels\DiscordChannel::class,
],