Download the PHP package hkwise/laravel-slack-notifier without Composer
On this page you can find all versions of the php package hkwise/laravel-slack-notifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hkwise/laravel-slack-notifier
More information about hkwise/laravel-slack-notifier
Files in hkwise/laravel-slack-notifier
Package laravel-slack-notifier
Short Description A comprehensive Laravel package for sending Slack notifications via Webhooks and Web API with support for simple and block messages
License MIT
Homepage https://github.com/hassankhan-wise/laravel-slack-notifier
Informations about the package laravel-slack-notifier
Laravel Slack Notifier
A comprehensive Laravel package for sending beautiful Slack notifications using both Incoming Webhooks and the Slack Web API. Send simple text messages or rich block messages with an elegant, fluent interface.
Features
✅ Dual Sending Methods: Support for both Incoming Webhooks and Web API (chat.postMessage)
✅ Simple Text Messages: Send quick text notifications
✅ Block Messages: Create rich, interactive messages with blocks
✅ Fluent Interface: Chain methods for clean, readable code
✅ Easy Configuration: Simple .env based configuration
✅ Test Command: Built-in artisan command to test your setup
✅ Laravel Auto-Discovery: Zero configuration setup
✅ Highly Customizable: Control username, icon, channel, and more
Requirements
- PHP 8.1 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
- Guzzle HTTP Client 7.x
Installation
Install the package via Composer:
Publish Configuration (Optional)
The package works out of the box with environment variables, but you can publish the config file if needed:
This will create a config/slack-notifier.php file.
Configuration
Environment Variables
Add the following variables to your .env file:
Getting Slack Credentials
Option 1: Incoming Webhooks (Recommended for Simple Use)
- Go to Slack Apps
- Create a new app or select an existing one
- Navigate to "Incoming Webhooks"
- Activate Incoming Webhooks
- Click "Add New Webhook to Workspace"
- Select the channel where you want to post messages
- Copy the webhook URL and add it to your
.envasSLACK_WEBHOOK_URL
Pros: Simple setup, no token management
Cons: Can only post to the pre-configured channel
Option 2: Web API (Recommended for Multiple Channels)
- Go to Slack Apps
- Create a new app or select an existing one
- Navigate to "OAuth & Permissions"
- Under "Scopes" → "Bot Token Scopes", add these permissions:
chat:write(Send messages)chat:write.public(Send messages to public channels without joining)groups:read(May be required for private channels)groups:write(May be required for private channels)
- Click "Install to Workspace" at the top
- Copy the "Bot User OAuth Token" (starts with
xoxb-) - Add it to your
.envasSLACK_BOT_TOKEN
Pros: Can send to any channel dynamically
Cons: Requires more setup, need to manage tokens
Channel Formatting
You can specify channels in multiple ways:
- With hash:
#general,#my-channel - Without hash:
general,my-channel - Channel ID:
C1234567890(starts with 'C') - Direct messages:
@usernameor user IDU1234567890
For Private Channels:
- Your bot must be invited to the private channel before it can send messages
- In the private channel, type:
/invite @YourBotName - Or click channel name → Integrations → Add apps → Select your bot
Usage
Basic Text Message (Webhook)
Basic Text Message (Web API)
Ephemeral Messages (Visible Only to One User)
Quick Methods
Rich Block Messages
Custom Block Messages
Customizing Bot Appearance
Complete Example: Error Notification
Using in Controllers
Using in Jobs
Testing Your Configuration
The package includes an artisan command to test your Slack configuration:
Available Methods
Configuration Methods
| Method | Description | Example |
|---|---|---|
via(string $method) |
Set sending method ('webhook' or 'api') | ->via('api') |
to(string $channel) |
Set channel/user (API only) | ->to('#general') |
toUser(string $userId) |
Set user ID for ephemeral messages | ->toUser('U1234567890') |
username(string $name) |
Set bot username | ->username('Bot') |
iconEmoji(string $emoji) |
Set bot icon | ->iconEmoji(':robot_face:') |
asEphemeral(bool $ephemeral) |
Mark message as ephemeral | ->asEphemeral() |
Message Methods
| Method | Description | Example |
|---|---|---|
text(string $text) |
Set simple text message | ->text('Hello!') |
blocks(array $blocks) |
Set custom blocks | ->blocks([...]) |
addBlock(array $block) |
Add a single block | ->addBlock([...]) |
addHeader(string $text) |
Add header block | ->addHeader('Title') |
addSection(string $text, string $type) |
Add section block | ->addSection('Content') |
addDivider() |
Add divider block | ->addDivider() |
addContext(array $elements) |
Add context block | ->addContext([...]) |
addAttachment(array $attachment) |
Add attachment | ->addAttachment([...]) |
Sending Methods
| Method | Description | Example |
|---|---|---|
send() |
Send the message | ->send() |
sendTestMessage(?string $method, ?string $channel) |
Send test message | ->sendTestMessage('api', '#test') |
quickMessage(string $text, ?string $channel) |
Quick text message | ->quickMessage('Hello', '#general') |
quickBlockMessage(string $header, string $message, ?string $channel) |
Quick block message | ->quickBlockMessage('Title', 'Text', '#general') |
quickEphemeralMessage(string $text, string $userId, ?string $channel) |
Quick ephemeral message | ->quickEphemeralMessage('Private', 'U123', '#general') |
Block Types Reference
Header Block
Section Block
Divider Block
Context Block
Custom Blocks
For more block types and options, see the Slack Block Kit Builder.
Error Handling
The package throws exceptions when things go wrong. Always wrap your calls in try-catch blocks:
Common errors:
Slack webhook URL is not configured- AddSLACK_WEBHOOK_URLto.envSlack API token is not configured- AddSLACK_BOT_TOKENto.envChannel is required for API method- Use->to('#channel')when using API methodchannel_not_found- Bot needs to be invited to the private channel. Use/invite @BotNamein the channel
Disabling Notifications
You can disable notifications globally (useful for local development):
When disabled, all send() calls will return success without actually sending.
Advanced Configuration
The config file (config/slack-notifier.php) contains additional options:
Testing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
Developed by Hassan Khan
License
The MIT License (MIT). Please see License File for more information.
Support
If you find this package helpful, please consider giving it a ⭐ on GitHub!
Useful Links
All versions of laravel-slack-notifier with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0