Lightweight PHP wrapper for Slack Web API. Zero dependencies.
Send messages, blocks, and attachments to channels. Incoming webhooks and slash command verification with HMAC-SHA256.
Author: Renzo Johnson
- PHP 8.4+
- ext-curl
- ext-json
composer require renzojohnson/slack-apiuse RenzoJohnson\Slack\Slack;
$slack = new Slack('xoxb-your-bot-token');
// Send a text message
$slack->sendText('#general', 'Hello from PHP!');$slack->sendText('#general', 'Hello World');
// Thread reply
$slack->sendText('#general', 'Replying...', threadTs: '1234567890.123456');use RenzoJohnson\Slack\Message\Block;
$slack->sendBlocks('#alerts', [
Block::header('Deploy Alert'),
Block::divider(),
Block::section('Production deploy completed for *v2.1.0*'),
Block::image('https://example.com/chart.png', 'CPU chart'),
], text: 'Deploy Alert — fallback for notifications');$slack->sendAttachment(
'#ops',
fallback: 'Server CPU at 95%',
color: '#ff0000',
title: 'Server Alert',
text: 'CPU usage has exceeded threshold.',
fields: [
['title' => 'Server', 'value' => 'web-01', 'short' => true],
['title' => 'CPU', 'value' => '95%', 'short' => true],
],
);$response = $slack->sendText('#general', 'Loading...');
$ts = $response['ts'];
$slack->updateMessage('#general', $ts, 'Done!');$slack->deleteMessage('#general', '1234567890.123456');$slack->addReaction('#general', '1234567890.123456', 'thumbsup');$channels = $slack->listConversations();$info = $slack->authTest();
echo $info['user']; // bot usernameNo bot token needed — just a webhook URL.
use RenzoJohnson\Slack\Webhook\IncomingWebhook;
$webhook = new IncomingWebhook('https://hooks.slack.com/services/T.../B.../xxx');
// Simple text
$webhook->send('Deploy complete!');
// Rich message
use RenzoJohnson\Slack\Message\WebhookMessage;
$webhook->send(new WebhookMessage(
'Deploy complete!',
username: 'DeployBot',
iconEmoji: ':rocket:',
));use RenzoJohnson\Slack\Webhook\SlashCommand;
// Verifies X-Slack-Signature via HMAC-SHA256, returns parsed params
$params = SlashCommand::verify('your-signing-secret');
echo $params['command']; // /weather
echo $params['text']; // 94070
echo $params['user_name']; // john// Ephemeral (only visible to user)
SlashCommand::respond('Processing your request...');
// Visible to entire channel
SlashCommand::respond('Weather: 72F, Sunny', inChannel: true);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
} catch (SlackException $e) {
// Other API errors (channel_not_found, etc.)
$errorData = $e->getErrorData();
}composer install
vendor/bin/phpunitMIT License. Copyright (c) 2026 Renzo Johnson.