PHPackages                             hkwise/laravel-slack-notifier - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. hkwise/laravel-slack-notifier

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hkwise/laravel-slack-notifier
=============================

A comprehensive Laravel package for sending Slack notifications via Webhooks and Web API with support for simple and block messages

v1.0.0(7mo ago)013MITPHPPHP ^8.1

Since Nov 21Pushed 7mo agoCompare

[ Source](https://github.com/hassankhan-wise/laravel-slack-notifier)[ Packagist](https://packagist.org/packages/hkwise/laravel-slack-notifier)[ Docs](https://github.com/hassankhan-wise/laravel-slack-notifier)[ RSS](/packages/hkwise-laravel-slack-notifier/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

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.

[![Latest Stable Version](https://camo.githubusercontent.com/57c0dcbc7c915184b04a534682ba839e2bc6241c98473a0847e6395edb3a9aac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686b776973652f6c61726176656c2d736c61636b2d6e6f7469666965722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hkwise/laravel-slack-notifier)[![Total Downloads](https://camo.githubusercontent.com/5b6278002ec3946abac78f38ebde6b13b3ef3604c08dccd9d20dc4fcb9dfbe73/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686b776973652f6c61726176656c2d736c61636b2d6e6f7469666965722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hkwise/laravel-slack-notifier)

Features
--------

[](#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
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 9.x, 10.x, 11.x, or 12.x
- Guzzle HTTP Client 7.x

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require hkwise/laravel-slack-notifier
```

### Publish Configuration (Optional)

[](#publish-configuration-optional)

The package works out of the box with environment variables, but you can publish the config file if needed:

```
php artisan vendor:publish --tag=slack-notifier-config
```

This will create a `config/slack-notifier.php` file.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add the following variables to your `.env` file:

```
# Default method: webhook or api
SLACK_DEFAULT_METHOD=webhook

# Webhook Configuration
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK/URL

# Web API Configuration
SLACK_BOT_TOKEN=xoxb-your-bot-token-here
SLACK_DEFAULT_CHANNEL=#general

# Optional Settings
SLACK_TIMEOUT=10
SLACK_NOTIFICATIONS_ENABLED=true
SLACK_BOT_USERNAME="Laravel Bot"
SLACK_BOT_ICON=:robot_face:
```

### Getting Slack Credentials

[](#getting-slack-credentials)

#### Option 1: Incoming Webhooks (Recommended for Simple Use)

[](#option-1-incoming-webhooks-recommended-for-simple-use)

1. Go to [Slack Apps](https://api.slack.com/apps)
2. Create a new app or select an existing one
3. Navigate to **"Incoming Webhooks"**
4. Activate Incoming Webhooks
5. Click **"Add New Webhook to Workspace"**
6. Select the channel where you want to post messages
7. Copy the webhook URL and add it to your `.env` as `SLACK_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)

[](#option-2-web-api-recommended-for-multiple-channels)

1. Go to [Slack Apps](https://api.slack.com/apps)
2. Create a new app or select an existing one
3. Navigate to **"OAuth &amp; Permissions"**
4. 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)
5. Click **"Install to Workspace"** at the top
6. Copy the **"Bot User OAuth Token"** (starts with `xoxb-`)
7. Add it to your `.env` as `SLACK_BOT_TOKEN`

**Pros**: Can send to any channel dynamically
**Cons**: Requires more setup, need to manage tokens

### Channel Formatting

[](#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**: `@username` or user ID `U1234567890`

**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
-----

[](#usage)

### Basic Text Message (Webhook)

[](#basic-text-message-webhook)

```
use HKWise\LaravelSlackNotifier\Facades\SlackNotifier;

// Simple webhook message
SlackNotifier::text('Hello from Laravel!')
    ->send();
```

### Basic Text Message (Web API)

[](#basic-text-message-web-api)

```
// Send to a specific channel using Web API
SlackNotifier::via('api')
    ->to('#general')
    ->text('Hello from Laravel!')
    ->send();

// Send to a user
SlackNotifier::via('api')
    ->to('@username')
    ->text('Hey! Check this out.')
    ->send();
```

### Ephemeral Messages (Visible Only to One User)

[](#ephemeral-messages-visible-only-to-one-user)

```
// Send an ephemeral message (only visible to specific user)
SlackNotifier::via('api')
    ->to('#general')
    ->toUser('U1234567890')  // Slack user ID
    ->text('This message is only visible to you!')
    ->asEphemeral()
    ->send();

// Quick ephemeral message
SlackNotifier::quickEphemeralMessage(
    'You have a pending approval request',
    'U1234567890',
    '#approvals'
);

// Ephemeral block message
SlackNotifier::via('api')
    ->to('#team')
    ->toUser('U1234567890')
    ->addHeader('Private Notification')
    ->addSection('This is visible only to you')
    ->asEphemeral()
    ->send();
```

### Quick Methods

[](#quick-methods)

```
// Quick simple message
SlackNotifier::quickMessage('Server is up and running!', '#monitoring');

// Quick block message with header
SlackNotifier::quickBlockMessage(
    'Deployment Complete',
    'Your application has been successfully deployed to production.',
    '#deployments'
);
```

### Rich Block Messages

[](#rich-block-messages)

```
use HKWise\LaravelSlackNotifier\Facades\SlackNotifier;

SlackNotifier::via('api')
    ->to('#general')
    ->addHeader('📊 Daily Report')
    ->addDivider()
    ->addSection('*Sales Overview*')
    ->addSection('Total Sales: $12,450\nNew Customers: 23\nOrders: 145')
    ->addDivider()
    ->addContext([
        [
            'type' => 'mrkdwn',
            'text' => 'Generated on: ' . now()->format('M d, Y')
        ]
    ])
    ->send();
```

### Custom Block Messages

[](#custom-block-messages)

```
SlackNotifier::blocks([
    [
        'type' => 'header',
        'text' => [
            'type' => 'plain_text',
            'text' => '🚨 System Alert'
        ]
    ],
    [
        'type' => 'section',
        'text' => [
            'type' => 'mrkdwn',
            'text' => '*High CPU Usage Detected*\nServer: web-01\nUsage: 95%'
        ]
    ],
    [
        'type' => 'section',
        'fields' => [
            [
                'type' => 'mrkdwn',
                'text' => '*Server:*\nweb-01'
            ],
            [
                'type' => 'mrkdwn',
                'text' => '*CPU:*\n95%'
            ]
        ]
    ]
])->send();
```

### Customizing Bot Appearance

[](#customizing-bot-appearance)

```
SlackNotifier::username('Custom Bot')
    ->iconEmoji(':fire:')
    ->text('Message with custom appearance')
    ->send();
```

### Complete Example: Error Notification

[](#complete-example-error-notification)

```
try {
    // Your code here
} catch (\Exception $e) {
    SlackNotifier::via('api')
        ->to('#errors')
        ->username('Error Bot')
        ->iconEmoji(':warning:')
        ->addHeader('⚠️ Application Error')
        ->addDivider()
        ->addSection("*Error:* {$e->getMessage()}")
        ->addSection("*File:* {$e->getFile()}:{$e->getLine()}")
        ->addDivider()
        ->addContext([
            [
                'type' => 'mrkdwn',
                'text' => 'Environment: ' . app()->environment()
            ],
            [
                'type' => 'mrkdwn',
                'text' => 'Time: ' . now()->toDateTimeString()
            ]
        ])
        ->send();
}
```

### Using in Controllers

[](#using-in-controllers)

```
namespace App\Http\Controllers;

use HKWise\LaravelSlackNotifier\Facades\SlackNotifier;

class OrderController extends Controller
{
    public function store(Request $request)
    {
        $order = Order::create($request->all());

        // Notify team about new order
        SlackNotifier::via('api')
            ->to('#orders')
            ->addHeader('🛍️ New Order Received')
            ->addSection("*Order ID:* #{$order->id}")
            ->addSection("*Customer:* {$order->customer_name}")
            ->addSection("*Total:* \${$order->total}")
            ->send();

        return response()->json($order);
    }
}
```

### Using in Jobs

[](#using-in-jobs)

```
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use HKWise\LaravelSlackNotifier\Facades\SlackNotifier;

class NotifySlack implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public function handle()
    {
        SlackNotifier::quickMessage('Background job completed!', '#notifications');
    }
}
```

Testing Your Configuration
--------------------------

[](#testing-your-configuration)

The package includes an artisan command to test your Slack configuration:

```
# Test webhook method (default)
php artisan slack:test

# Test Web API method
php artisan slack:test --method=api --channel=#general

# Test with a specific channel
php artisan slack:test --method=api --channel=@username
```

Available Methods
-----------------

[](#available-methods)

### Configuration Methods

[](#configuration-methods)

MethodDescriptionExample`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

[](#message-methods)

MethodDescriptionExample`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

[](#sending-methods)

MethodDescriptionExample`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
---------------------

[](#block-types-reference)

### Header Block

[](#header-block)

```
->addHeader('My Header')
```

### Section Block

[](#section-block)

```
->addSection('*Bold text* and _italic text_')
->addSection('Plain text', 'plain_text')
```

### Divider Block

[](#divider-block)

```
->addDivider()
```

### Context Block

[](#context-block)

```
->addContext([
    ['type' => 'mrkdwn', 'text' => 'Context info'],
    ['type' => 'mrkdwn', 'text' => 'More context']
])
```

### Custom Blocks

[](#custom-blocks)

```
->blocks([
    [
        'type' => 'section',
        'text' => [
            'type' => 'mrkdwn',
            'text' => 'Custom section'
        ],
        'accessory' => [
            'type' => 'button',
            'text' => [
                'type' => 'plain_text',
                'text' => 'Click Me'
            ],
            'url' => 'https://example.com'
        ]
    ]
])
```

For more block types and options, see the [Slack Block Kit Builder](https://api.slack.com/block-kit/building).

Error Handling
--------------

[](#error-handling)

The package throws exceptions when things go wrong. Always wrap your calls in try-catch blocks:

```
try {
    SlackNotifier::quickMessage('Hello!');
} catch (\Exception $e) {
    Log::error('Slack notification failed: ' . $e->getMessage());
}
```

Common errors:

- `Slack webhook URL is not configured` - Add `SLACK_WEBHOOK_URL` to `.env`
- `Slack API token is not configured` - Add `SLACK_BOT_TOKEN` to `.env`
- `Channel is required for API method` - Use `->to('#channel')` when using API method
- `channel_not_found` - Bot needs to be invited to the private channel. Use `/invite @BotName` in the channel

Disabling Notifications
-----------------------

[](#disabling-notifications)

You can disable notifications globally (useful for local development):

```
SLACK_NOTIFICATIONS_ENABLED=false
```

When disabled, all `send()` calls will return success without actually sending.

Advanced Configuration
----------------------

[](#advanced-configuration)

The config file (`config/slack-notifier.php`) contains additional options:

```
return [
    'default_method' => 'webhook',  // or 'api'
    'webhook_url' => env('SLACK_WEBHOOK_URL'),
    'api' => [
        'token' => env('SLACK_BOT_TOKEN'),
        'default_channel' => env('SLACK_DEFAULT_CHANNEL', '#general'),
    ],
    'timeout' => 10,  // HTTP request timeout in seconds
    'enabled' => true,  // Enable/disable globally
    'defaults' => [
        'username' => 'Laravel Bot',
        'icon_emoji' => ':robot_face:',
    ],
];
```

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Credits
-------

[](#credits)

Developed by [Hassan Khan](https://github.com/hassankhan-wise)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Support
-------

[](#support)

If you find this package helpful, please consider giving it a ⭐ on [GitHub](https://github.com/hassankhan-wise/laravel-slack-notifier)!

Useful Links
------------

[](#useful-links)

- [Slack API Documentation](https://api.slack.com/)
- [Slack Block Kit Builder](https://api.slack.com/block-kit/building)
- [Incoming Webhooks Guide](https://api.slack.com/messaging/webhooks)
- [Web API Reference](https://api.slack.com/methods/chat.postMessage)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance64

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

217d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/77392509?v=4)[Hassan Khan](/maintainers/hassankhan-wise)[@hassankhan-wise](https://github.com/hassankhan-wise)

---

Top Contributors

[![hassankhan-wise](https://avatars.githubusercontent.com/u/77392509?v=4)](https://github.com/hassankhan-wise "hassankhan-wise (2 commits)")

---

Tags

laravelnotificationsslackmessagingwebhookchat

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hkwise-laravel-slack-notifier/health.svg)

```
[![Health](https://phpackages.com/badges/hkwise-laravel-slack-notifier/health.svg)](https://phpackages.com/packages/hkwise-laravel-slack-notifier)
```

###  Alternatives

[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

252143.0k](/packages/erag-laravel-disposable-email)[snoeren-development/laravel-discord-webhook-channel

Send notifications to a Discord webhook.

1553.0k1](/packages/snoeren-development-laravel-discord-webhook-channel)[salamwaddah/laravel-mandrill-driver

Mandrill notification channel for Laravel 9, 10, 11, 12, 13

1176.4k](/packages/salamwaddah-laravel-mandrill-driver)[laravel-notification-channels/rocket-chat

Rocket.Chat Notifications channel for Laravel 5.6+

1346.9k](/packages/laravel-notification-channels-rocket-chat)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
