Slack

alek13/slack image

Slack stats

Downloads
1.9M
Stars
131
Open Issues
0
Forks
26

View on GitHub →

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

  1. Create an incoming webhook on your Slack workspace.
  2. 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.

php-slack photo

Founder of @PhpProfi. Maintainer at @php-slack & @PHPColibri . Love @minetest. Lead @lord-server . Born on the 13th.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Alek13 Slack Related Articles

SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel