Slack API PHP is a lightweight Composer package that lets you send messages, blocks, and attachments to Slack channels from any PHP application. In other words, instead of wiring up a heavy SDK with multiple dependencies, you install one package, pass your bot token, and start posting messages in three lines of code.
Additionally, the package supports incoming webhooks, slash command verification with HMAC-SHA256 signing, and the full Block Kit format. As a result, you can build Slack integrations — from simple notifications to interactive slash commands — without pulling in Guzzle, PSR-7, or any external HTTP library.
Furthermore, the package is available on Packagist and the source code is on GitHub.
Why a Zero-Dependency Slack API PHP Package?
Most Slack API PHP libraries require external dependencies. Specifically, the popular options either pull in Guzzle for HTTP, rely on PSR-7 and PSR-18 interfaces, or depend on auto-generated client code. However, this package takes a different approach:
- Zero external dependencies — the package uses only PHP’s built-in
ext-curlandext-jsonextensions. Consequently, your dependency tree stays clean and you avoid version conflicts. - PHP 8.4+ — built for modern PHP with named parameters, match expressions, and readonly properties.
- Block Kit support — send rich, interactive messages using Slack’s Block Kit format without a separate builder library.
- Slash command verification — validate incoming slash commands using HMAC-SHA256 signature checking, exactly as Slack’s security documentation recommends.
In short, the Slack API PHP package gives you full API coverage without the dependency overhead.
Installation
Install the package via Composer:
composer require renzojohnson/slack-api
Moreover, no additional configuration is needed. The package auto-loads via PSR-4 and is ready to use immediately after installation.
Sending Messages
The most common use case is sending a text message to a Slack channel. Specifically, you create a client instance with your bot token and call sendText():
use RenzoJohnson\Slack\Slack;
$slack = new Slack('xoxb-your-bot-token');
$slack->sendText('#general', 'Hello from PHP!');
Additionally, you can send messages to threads by passing the parent message timestamp:
$slack->sendText('#general', 'Thread reply', threadTs: '1234567890.123456');
As a result, the message appears as a threaded reply rather than a new channel message.
Block Kit Messages
For richer formatting, the Slack API PHP package supports Block Kit — Slack’s framework for building interactive messages. Specifically, you pass an array of block elements:
$slack->sendBlocks('#alerts', [
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => '*Deploy Complete* :white_check_mark:',
],
],
[
'type' => 'section',
'fields' => [
['type' => 'mrkdwn', 'text' => '*Environment:* Production'],
['type' => 'mrkdwn', 'text' => '*Version:* 2.4.1'],
],
],
]);
Moreover, blocks support buttons, dropdowns, date pickers, and other interactive components. The package sends whatever block structure you provide directly to Slack’s API.
Message Management
Beyond sending, the package also handles message updates, deletion, and reactions:
// Update a message
$slack->updateMessage('#general', '1234567890.123456', 'Updated text');
// Delete a message
$slack->deleteMessage('#general', '1234567890.123456');
// Add a reaction
$slack->addReaction('#general', '1234567890.123456', 'thumbsup');
Consequently, you can build workflows that post a message, update it as a process runs, and add a reaction when the task completes.
Incoming Webhooks
If you do not need a bot token, the package supports incoming webhooks. In particular, webhooks are useful for one-way notifications where you simply post a message to a channel:
use RenzoJohnson\Slack\IncomingWebhook;
$webhook = new IncomingWebhook('https://hooks.slack.com/services/T.../B.../xxx');
$webhook->send('Build failed on main branch');
Furthermore, webhook messages support the same Block Kit format and attachments as bot messages.
Slash Command Verification
When building slash commands, Slack sends a signed request to your server. The package verifies that signature using HMAC-SHA256 to ensure the request actually came from Slack:
use RenzoJohnson\Slack\SlashCommand;
$command = SlashCommand::verify('your-signing-secret');
// $command contains: command, text, user_id, channel_id, etc.
SlashCommand::respond('Processing your request...');
Specifically, the verification checks the X-Slack-Signature header against a hash of the request body and timestamp. As a result, you are protected against forged requests without writing the HMAC logic yourself.
Slack API PHP vs Other Libraries
There are several Slack API PHP libraries available on Packagist. However, each takes a different approach. The following table compares the most common options:
| Feature | renzojohnson/slack-api | jolicode/slack-php-api | maknz/slack |
|---|---|---|---|
| PHP version | 8.4+ | 8.1+ | 5.5+ |
| Dependencies | Zero | PSR-7, PSR-18, Jane | Guzzle |
| Block Kit | Yes | Yes | No |
| Slash commands | HMAC verification | No | No |
| Webhooks | Yes | No | Yes |
| Message management | Update, delete, react | Full API coverage | Send only |
| Maintained | Active | Active | Abandoned |
| Installs | New | 4.1M | 11.4M |
In particular, if you need a simple, dependency-free way to send Slack messages and handle slash commands, this package is the right choice. If you need full API coverage for every Slack endpoint (files, users, conversations), jolicode’s auto-generated SDK covers more surface area at the cost of a heavier dependency tree.
Error Handling
The package provides specific exception types for common failure scenarios:
use RenzoJohnson\Slack\Exception\AuthenticationException;
use RenzoJohnson\Slack\Exception\RateLimitException;
use RenzoJohnson\Slack\Exception\SlackException;
try {
$slack->sendText('#general', 'Hello');
} catch (AuthenticationException $e) {
// Invalid bot token
} catch (RateLimitException $e) {
$retryAfter = $e->getRetryAfter(); // seconds to wait
} catch (SlackException $e) {
// General API error
}
Specifically, the RateLimitException includes the retry delay from Slack’s response headers. Consequently, you can implement backoff logic without parsing headers manually.
Common Questions
Do I need a Slack bot token or a webhook?
It depends on your use case. A bot token (xoxb-...) lets you send messages, update them, add reactions, and list channels. A webhook URL only lets you post messages to a specific channel. In short, use a bot token for interactive features and a webhook for simple notifications.
Does the package support file uploads?
The package focuses on messaging, blocks, and slash commands. For file uploads, you would use Slack’s files.upload endpoint directly or use a full-coverage SDK like jolicode/slack-php-api.
Can I use this in Laravel?
Yes. The package is framework-agnostic. Similarly, it works with Symfony, WordPress, or any PHP project that uses Composer. There are no framework-specific dependencies or service providers required.
Getting Started
The Slack API PHP package gives you a clean, dependency-free way to integrate Slack into any PHP application. Send messages, build Block Kit interfaces, and verify slash commands — all without external HTTP libraries.
Additionally, check out these other open source contributions and developer tools:
- Discord API PHP — send messages and embeds to Discord channels.
- WhatsApp Cloud API PHP — lightweight wrapper for Meta’s WhatsApp API.
- CF7 Mailchimp Extension — connect contact forms to Mailchimp.
- Arc — VS Code Terminal Bridge for AI coding agents.
If you need help with the Slack API PHP package or want to report an issue, contact us directly or open an issue on GitHub.