quitoque/slack
A Laravel package for integrating Slack into your application, making it easy to send messages and notifications to Slack channels through a simple, configurable API.
Install the package
composer require quitoque/slack
Register the service provider (if not auto-discovered)
Laravel 5.5+ should auto-discover Quitoque\Slack\SlackServiceProvider and the Slack facade. On older apps, add them manually in config/app.php:
'providers' => [
Quitoque\Slack\SlackServiceProvider::class,
],
'aliases' => [
'Slack' => Quitoque\Slack\Facades\Slack::class,
],
Publish the config and set credentials
php artisan vendor:publish --provider="Quitoque\Slack\SlackServiceProvider"
Then set a Slack token in .env (typically SLACK_TOKEN=xoxb-...). The package is token-based, so use a bot/user token with the scopes you need (chat:write, channels:read, users:read, etc.).
Where to look first
config/slack.php for the token, base URI, and any HTTP/timeout options.vendor/quitoque/slack/src to see which Slack endpoints are wrapped and how methods are named. The package exposes Slack Web API endpoints as PHP objects/methods (e.g. chat, users, channels), so the source is the fastest reference for supported calls.First use case — send a message
use Quitoque\Slack\Facades\Slack;
Slack::chat()->postMessage([
'channel' => '#general',
'text' => 'Deploy finished ✅',
]);
Verify in php artisan tinker before wiring it into application code.
Slack::... calls through controllers. Create a small class (e.g. App\Services\SlackNotifier) that takes the client via the container, so you can test and swap it later.DeploymentSucceeded, NewOrderReceived) rather than inline array literals. Keeps channel names, text formatting, and blocks in one place.ShouldQueue on the job/notification that sends the message, or dispatch a queued listener.attachments or blocks arrays directly in the payload. Keep a small builder per message type so colors/fields stay consistent.services.slack.alerts_channel) and default to a dev/sandbox channel outside production:
'channel' => app()->isProduction() ? '#alerts' : '#dev-alerts',
Slack::shouldReceive('chat')...) or bind a fake notifier in the container. Never call live Slack from the test suite.missing_scope or not_in_channel response is returned in the Slack payload, not always as an exception. Check the response body, not just for thrown errors. The bot must be invited to private channels.C01234567-style IDs; #general can work for posting but breaks for reads and private channels. Cache the name→ID map in config or a DB table.Retry-After. Catch it and back off; don't retry in a tight loop. Queued + retried jobs should be idempotent (use text + a unique key, or accept duplicates)..env, run php artisan config:clear. A cached config with the old token is a common "why doesn't it work" cause.maknz/slack or another Slack package, two Slack aliases conflict. Alias one explicitly in config/app.php.Guzzle responses, or custom result objects. Don't assume ->get('ok') or ['ok'] — check the package source or dump once with dd() in tinker.retry_after.composer.json, skim the source before relying on a method, and keep a thin wrapper around it so you can swap in jolicode/slack-php-api or slack-php/slack-php with minimal churn.How can I help you explore Laravel packages today?