Slack
Slack stats
- Downloads
- 1.9M
- Stars
- 131
- Open Issues
- 0
- Forks
- 26
A simple PHP package (fork of maknz/slack) for sending messages to Slack, with a focus on ease of use and elegant syntax.
Slack for PHP
Slack for PHP is a streamlined package that allows PHP developers to easily send messages to Slack using incoming webhooks. This package, a fork of the previously popular but abandoned maknz/slack, prides itself on its simplicity and elegant PHP syntax.
Features
- Easy Installation: Quickly integrate with Composer.
- Configurable: Set defaults like username, channel, and icons or adjust on a per-message basis.
- Robust Messaging Options: Send messages directly to channels or users, with options for different usernames, icons, and visibility.
- Attachments and Formatting: Supports rich content including attachments with fields, author details, and Slack's Block Kit for interactive messages.
- Markdown Support: Enable or disable Markdown parsing in messages and attachments.
- Advanced Usage: Directly manipulate message objects and attachment fields for complex scenarios.
Installation
- Create an incoming webhook on your Slack workspace.
- Install via Composer:
composer require alek13/slack
Usage
Basic Usage
Instantiate the client and send messages:
use Maknz\Slack\Client; $client = new Client('https://hooks.slack.com/services/...');$client->to('#general')->send('Good morning');
Advanced Messaging
- Customize appearance and responses: Change default settings like username or icon, and control message visibility.
- Attachments: Enhance messages with detailed attachments, specifying colors, pretext, author details, and more.
- Interactive Messages: Utilize Slack's Block Kit to add interactive elements like buttons to messages.
Practical Examples
// Sending a message with custom username and icon$client->from('Jake the Dog')->to('@FinnTheHuman')->send('Adventure time!'); // Sending an interactive message using Block Kit$client->to('@regan')->withBlock([ 'type' => 'section', 'text' => 'Do you love the app?'])->send('Notification fallback message');
Playground
Explore message formatting and features using the php-slack/playground script.
Support and Contribution
Join the Slack community if you need help, want to contribute, or simply connect with other users. Contributions via GitHub pull requests are welcome, please include tests for new or updated functionality.
For more details on using or contributing to the package, visit the GitHub repository.