Download the PHP package mcrumm/phlack without Composer
On this page you can find all versions of the php package mcrumm/phlack. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mcrumm/phlack
More information about mcrumm/phlack
Files in mcrumm/phlack
Informations about the package phlack
Phlack
Phlack eases the creation of Slack Integrations in PHP.
- Installation
- Basic Usage
- Send a Message
- Advanced Usage
- Legacy WebHook URLs
- Factory Method
- New Instance
- Messages
- Creating Messages
- Message Builder
- Attachment Builder
- Message Object
- Sending Messages
- Custom Messages
- Message Response
- More Examples
- Slack API
- Getting a Client
- Methods
- Resource Iterators
- Examples
- Disclaimer
- Credits
- Contributing
- License
Installation
via composer:
Basic Usage
Send a Message
Advanced Usage
Legacy WebHook URLs
Early versions of Incoming Webhooks used a generic webhook path for all teams. If your webhook URL starts with something like myteam.slack.com
, give Phlack your team name and Incoming Webhook token, and it will do the rest:
Factory Method
If you prefer, you can instantiate Phlack via its static factory()
method:
New Instance
Besides a webhook url or an array configuration, Phlack will also accept a PhlackClient
instance as a constructor argument:
Note: The constructor and factory method both accept the same types of arguments: a string representing the webhook url, an array of client config options, or a
PhlackClient
object.
:heart: for Guzzle
The PhlackClient is simply a web service client implemented with Guzzle. Examine its service description for more details.
Messages
Messages represent the payload for Slack's Incoming WebHook integration.
Creating Messages
Messages can be created using the provided builders, or they can be instantiated directly.
Message Builder
The MessageBuilder allows for programmatic creation of a Message object.
You can also use the MessageBuilder
directly to create the Message
object and add Attachments. The MessageBuilder
supports method chaining to allow for adding multiple Attachment
objects to a single message.
Note: When adding Attachments this way, you must call
end()
once for each attachment so that theMessageBuilder
knows to create theAttachment
object and return itself for further modification.
Attachment Builder
If you prefer, you may use the AttachmentBuilder in a standalone fashion:
Message Object
A Message can be instantiated with just a text
value:
But you can set optional parameters when constructing the message, too:
Sending Messages
Use Phlack's send()
command to fire off the message:
Custom Messages
Custom messages can be sent by using an array of valid parameters:
Note: No input validation is performed on custom message parameters. You are responsible for formatting channels, emojis, and text data yourself.
Message Response
The MessageResponse hash contains the status
, reason
, and text
from the response.
Responses from the Incoming Webhooks Integration are very sparse. Success messages will simply return a status
of 200
. Error messages will contain more details in the response text
and reason
.
More Examples
See the examples directory for more use cases.
Slack API
Programmatic access to the Slack API is provided via the ApiClient.
Note: Currently, bearer token authentication is the only supported authentication method. Contributions toward OAuth2 support would be greatly appreciated.
Getting a Client
Get an ApiClient object by instantiating it with a hash containing your API token, or passing a config hash to its factory
method.
via factory()
:
via new ApiClient()
:
API Methods
The methods currently implemented are:
Consult the client's service description for information on the responses returned by the API methods.
Example: Listing all Channels
Resource Iterators
Example: ListFilesIterator
The ListFilesIterator eases the ability to iterate through multiple pages of data from the Slack API. Using the iterator eliminates the need to manually call the API multiple times to retrieve all pages of the result set.
A complete example is available in the examples directory.
Note: The ListFilesIterator is not strictly necessary to page through file results, but it's certainly easier than the alternative. An example without the iterator is also available.
More API Examples
See the API examples directory for more use cases.
Disclaimer
Any undocumented portion of this library should be considered EXPERIMENTAL AT BEST. Proceed with caution, and, as always, pull requests are welcome.
Credits
- Michael Crumm [email protected]
- All contributors
The regex in the slack-notifier project.
Contributing
Please see the CONTRIBUTING file for details.
License
Phlack is released under the MIT License. See the bundled LICENSE file for details.
All versions of phlack with dependencies
guzzle/guzzle Version ~3.8
doctrine/collections Version >=1.0
symfony/options-resolver Version ~2.4|3.0.*