Download the PHP package mountain/laraslack without Composer
On this page you can find all versions of the php package mountain/laraslack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mountain/laraslack
More information about mountain/laraslack
Files in mountain/laraslack
Package laraslack
Short Description Send alerts, notifications and Block Kit messages to Slack from Laravel via incoming webhooks.
License MIT
Homepage https://github.com/ThomasMountain/laraslack
Informations about the package laraslack
LaraSlack
Send alerts, notifications and Block Kit messages to Slack from Laravel, via incoming webhooks.
- No Slack SDK, no OAuth, no queue requirement. One HTTP POST.
- Posts through Laravel's
Httpclient, so it is fakeable in tests and uses your existing connection handling. - Sensible defaults for local and testing environments: with no webhook configured, nothing is sent.
Requirements
- PHP 8.1+
- Laravel 10, 11 or 12
Installation
The service provider is auto-discovered. Publish the config if you want to edit it in your application:
Then add your webhook URL to .env:
To create a webhook, go to https://api.slack.com/messaging/webhooks and create a Slack app with the Incoming Webhooks permission, or add an incoming webhook to an existing one.
Usage
send() returns true if Slack accepted the message, and false if it was
skipped or rejected. It does not throw unless you ask it to.
Block Kit
Attachments
Posting to more than one channel
See "Identity and channels" below for why this matters.
Anything else
Anything the builder does not cover can be passed straight through as a raw
Slack payload. This is also the reason the method is a single array rather
than key/value pairs: a text value containing = would otherwise be
misparsed as a form field.
Without the facade
Identity and channels
channel, username and icon are only honoured by legacy custom
integration webhooks. Webhooks that belong to a Slack app ignore all three,
because the app's own configuration wins:
You cannot override the default channel (chosen by the user who installed your app), username, or icon when you're using incoming webhooks to post messages. — Slack's documentation
So if SLACK_CHANNEL seems to be ignored, that is why. To post to a different
channel, post to a different webhook, which is scoped to a channel at creation
time. That is what webhook() is for.
If you need per-message identity as well, use the chat.postMessage Web API
method with a bot token and the chat:write.customize scope instead. This
package deliberately does not do that, to avoid pulling in token management.
Testing
With no SLACK_WEB_HOOK_URL configured, send() returns false and makes no
request, so nothing is posted to Slack from your test suite.
To assert on what would have been sent, fake the HTTP client:
Remember that Slack answers with HTTP 200 and a body of ok on success, so
fake that rather than a bare Http::response() if you want the transport to
see a success.
Configuration
| Key | Env | Default | Notes |
|---|---|---|---|
endpoint |
SLACK_WEB_HOOK_URL |
null |
Blank or missing disables sending entirely. |
channel |
SLACK_CHANNEL |
null |
Legacy webhooks only. |
username |
SLACK_USERNAME |
null |
Legacy webhooks only. |
icon |
SLACK_ICON |
null |
An emoji shortcode, e.g. :rocket:. Legacy webhooks only. |
enabled |
SLACK_ENABLED |
true |
Master switch. |
throw_exceptions |
SLACK_THROW_EXCEPTIONS |
false |
Throw SlackRequestException instead of logging. |
connect_timeout |
SLACK_CONNECT_TIMEOUT |
3 |
Seconds to establish a connection. |
timeout |
SLACK_TIMEOUT |
5 |
Seconds for the whole request. |
verify_tls |
SLACK_VERIFY_TLS |
true |
Leave this on. |
proxy |
SLACK_PROXY |
null |
e.g. http://user:[email protected]:3128. |
Error handling
By default a failed message is reported to your application logger and
send() returns false. That includes connection failures, DNS errors and
timeouts, so a Slack outage never breaks the request that triggered the alert.
Set SLACK_THROW_EXCEPTIONS=true to throw instead:
Note that Slack reports most webhook errors with an HTTP 200 and a plain
text body such as invalid_payload or channel_not_found, so a 2xx status on
its own does not mean the message arrived. This package checks both.
A message with no text, blocks or attachments throws
EmptyMessageException before any request is made, rather than being posted
as a blank message.
Contributing
Licence
MIT. See LICENSE.
All versions of laraslack with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.5
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0