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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

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.

Latest Stable Version Total Downloads

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

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)

  1. Go to Slack 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)

  1. Go to Slack Apps
  2. Create a new app or select an existing one
  3. Navigate to "OAuth & 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

You can specify channels in multiple ways:

For Private Channels:

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:

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

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hkwise/laravel-slack-notifier contains the following files

Loading the files please wait ...