Download the PHP package nguyenanhung/slack without Composer
On this page you can find all versions of the php package nguyenanhung/slack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nguyenanhung/slack
More information about nguyenanhung/slack
Files in nguyenanhung/slack
Package slack
Short Description A simple PHP package for sending messages to Slack, with a focus on ease of use and elegant syntax. Includes Laravel support out of the box.
License BSD-2-Clause
Informations about the package slack
Slack
A simple PHP package for sending messages to Slack with incoming webhooks, focussed on ease-of-use and elegant syntax. Includes Laravel 4 and 5 support out of the box.
Requirements
- PHP 5.4 or greater
Version
- [x] V1.x support all PHP version
>=5.4
- [x] V2.x support all PHP version
>=7.0
Installation
You can install the package using the Composer package manager. You can install it by running this command in your project root:
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).
Laravel
We include service providers and a facade for easy integration and a nice syntax for Laravel.
Firstly, add the nguyenanhung\Slack\SlackServiceProvider
provider to the providers array in config/app.php
(or app/config.php
for Laravel 4)
and then add the facade to your aliases
array
Configuration
Publish the configuration file with:
Head into the file and configure the defaults you'd like the package to use. If null
is set for any, the package will fall back on the default set on the webhook.
The configuration file is used to bypass the client instantiation process to make using the package easier. Therefore, you can skip the the Instantiate the client section below and dive right into using the package.
Basic Usage
Instantiate the client
Settings
All settings are optional, but are a convenient way of specifying how the client should behave beyond the defaults.
channel
: the default channel that messages will be sent to- string
- default: the setting on the webhook
username
: the default username that messages will be sent from- string
- default: the setting on the webhook
icon
: the default icon messages will be sent with, either :emoji: or a URL to an image- string
- default: the setting on the webhook
link_names
: whether names like @regan or #accounting should be linked- bool
- default:
false
unfurl_links
: whether Slack should unfurl text-based URLs- bool
- default:
false
unfurl_media
: whether Slack should unfurl media-based URLs- bool
- default:
true
allow_markdown
: whether Markdown should be parsed in messages- bool
- default:
true
markdown_in_attachments
: which attachment fields should have Markdown parsed- array
- default:
[]
Sending messages
To send messages, you will call methods on your client instance, or use the Slack
facade if you are using the package in Laravel.
Sending a basic message
Sending a message to a non-default channel
Sending a message to a user
Sending a message to a channel as a different username
Sending a message with a different icon
Send an attachment
Send an attachment with fields
Send a message modifying Markdown parsing on the fly
Send an attachment specifying Markdown parsing on the fly
Send an attachment with an author
Advanced usage
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:
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.4.3 || ^6.5.6
ext-mbstring Version *
ext-json Version *
ext-curl Version *