spatie/interactive-slack-notification-channel
Send interactive Slack notifications from Laravel using Slack Block Kit. Configure a token and optional channel on your Notifiable, post rich messages with buttons/inputs, and use Slack API responses to reply in threads for follow-up order events.
Notifiable contracts, Notification classes). Leverages Laravel’s NotificationChannel interface, making it a drop-in replacement for Slack notifications with interactive elements.notifiable:sent events) for tracking/debugging interactive notifications.Mailable, Mailable (via Notification), and Bus queues. Supports Laravel’s via() method for multi-channel notifications.action.id) must persist across requests. Laravel’s Session or database may be needed for complex flows.cache() or database for ephemeral state; document limits (e.g., Slack’s 30-day ephemeral storage)..env, Laravel Forge)?Illuminate\Notifications\Notification and Illuminate\Bus\Queueable.slack:app credentials in .env).database, redis, beanstalkd) for async delivery.HttpTests and Pest/PHPUnit for mocking Slack responses.composer require spatie/interactive-slack-notification-channel.chat:write, chat:write.public, and commands scopes).use Spatie\SlackNotificationChannel\SlackChannel;
use Spatie\SlackNotificationChannel\SlackMessage;
class AlertNotification extends Notification {
public function via($notifiable) {
return [SlackChannel::class];
}
public function toSlack($notifiable) {
return SlackMessage::create()
->content('Critical alert!')
->attachment([
'text' => 'Resolve now',
'callback_id' => 'alert_resolve',
'actions' => [
['type' => 'button', 'text' => 'Acknowledge', 'value' => 'acknowledged'],
],
]);
}
}
// routes/web.php
Route::post('/slack/interactive', [SlackInteractiveHandler::class]);
composer.json constraints).chat.postMessage if possible..env.php artisan vendor:publish --provider="Spatie\SlackNotificationChannel\SlackNotificationChannelServiceProvider".$this->mockSlackApi()->shouldReceive('sendMessage')->andReturn(['ok' => true]);
guzzlehttp/guzzle (for HTTP requests); update alongside Laravel.SlackMessage.SlackInteractiveEvent).SlackChannel::setLogger()).SLACK_SIGNING_SECRET and SLACK_APP_TOKEN in .env.afterCommit() for critical notifications to avoid queue delays.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Slack API downtime | Notifications lost | Fallback to email/SMS; retry with exponential backoff. |
| Invalid Slack credentials | All notifications fail silently | Health checks (e.g., php artisan queue:failed) and alerts. |
| Interactive button timeouts | User actions lost | Store state in DB/cache; use Slack’s ephemeral messages for time-sensitive data. |
| Slack rate limits | Throttled messages | Implement queue delays; monitor Slack’s API usage. |
| Malicious interactive payloads | Security risks (e.g., CSRF) | Validate action.id and user_id server-side; use Slack’s signing secrets. |
How can I help you explore Laravel packages today?