Download the PHP package alek13/slack without Composer
On this page you can find all versions of the php package alek13/slack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package slack
Slack for PHP
A simple PHP package for sending messages to Slack with incoming webhooks, focused on ease-of-use and elegant syntax.
supports: PHP 7.1
, 7.2
, 7.3
, 7.4
or 8.0
, 8.1
, 8.2
, 8.3
, 8.4
require: guzzlehttp/guzzle
any of versions ~7.0|~6.0|~5.0|~4.0
This is the fork of popular, great, but abandoned package
maknz/slack
Quick Tour
- create an incoming webhook & copy
hook_url
composer require alek13/slack
-
add the following code
use Maknz\Slack\Client; require(__DIR__ .'/vendor/autoload.php'); $client = new Client('https://hook_url'); $client->to('#general')->send('Good morning');
Done!
Installation
You can install the package using the Composer package manager by running in your project root:
Incoming WebHook
Then create an incoming webhook on your Slack account for the package to use. You'll need the webhook URL to instantiate the client (or for the configuration file if using Laravel).
Basic Usage
Instantiate the client
Settings
The default settings are pretty good, but you may wish to set up default behaviour for your client to be used for all messages sent. All settings are optional and you don't need to provide any. Where not provided, we'll fallback to what is configured on the webhook integration, which are managed at Slack, or our sensible defaults.
Field | Type | Description | |
---|---|---|---|
channel |
string | The default channel that messages will be sent to | |
username |
string | The default username for your bot | |
icon |
string | The default icon that messages will be sent with, either :emoji: or a URL to an image |
|
response_type |
string | Whether to show the response in the channel to all members or privately ('ephemeral' | 'in_channel') |
link_names |
bool | Whether names like @regan or #accounting should be linked in the message (defaults to false) |
|
unfurl_links |
bool | Whether Slack should unfurl text-based URLs (defaults to false) | |
unfurl_media |
bool | Whether Slack should unfurl media-based URLs, like tweets or Youtube videos (defaults to true) | |
allow_markdown |
bool | Whether markdown should be parsed in messages, or left as plain text (defaults to true) | |
markdown_in_attachments |
array | Which attachment fields should have markdown parsed (defaults to none) |
Sending messages
Sending a basic message (preview)
Sending a message to a non-default channel
Sending a message to a user
Sending a message to a channel as a different bot name (preview)
Sending a message with a different icon (preview)
Send an attachment (preview)
Send an attachment with fields (preview)
Send an attachment with an author (preview)
Using blocks (Block Kit)
Advanced usage
Markdown
By default, Markdown is enabled for message text, but disabled for attachment fields. This behaviour can be configured in settings, or on the fly:
Send a message enabling or disabling Markdown
Send an attachment specifying which fields should have Markdown enabled
Explicit message creation
For convenience, message objects are created implicitly by calling message methods on the client. We can however do this explicitly to avoid hitting the magic method.
Attachments
When using attachments, the easiest way is to provide an array of data as shown in the examples, which is actually converted to an Attachment object under the hood. You can also attach an Attachment object to the message:
Each attachment field is also an object, an AttachmentField. They can be used as well instead of their data in array form:
You can also set the attachments and fields directly if you have a whole lot of them:
Playground
There is the php-slack/playground
simple console script to test messaging and to see how messages looks really.
Questions
If you have any questions how to use or contribute,
you are welcome in our Slack Workspace.
Contributing
If you're having problems, spot a bug, or have a feature suggestion, please log and issue on Github. If you'd like to have a crack yourself, fork the package and make a pull request. Please include tests for any added or changed functionality. If it's a bug, include a regression test.
All versions of slack with dependencies
guzzlehttp/guzzle Version ~7.0|~6.0|~5.0|~4.0
ext-mbstring Version *
ext-json Version *