renzojohnson/slack-api
Composer 安装命令:
composer require renzojohnson/slack-api
包简介
Lightweight PHP wrapper for Slack Web API. Send messages, blocks, and files to channels. Incoming webhooks and slash command verification. Zero dependencies.
README 文档
README
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
Requirements
- PHP 8.4+
- ext-curl
- ext-json
Installation
composer require renzojohnson/slack-api
Quick Start
use RenzoJohnson\Slack\Slack; $slack = new Slack('xoxb-your-bot-token'); // Send a text message $slack->sendText('#general', 'Hello from PHP!');
Web API Methods
Send Text
$slack->sendText('#general', 'Hello World'); // Thread reply $slack->sendText('#general', 'Replying...', threadTs: '1234567890.123456');
Send Blocks (Block Kit)
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');
Send Attachment (Legacy)
$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], ], );
Update Message
$response = $slack->sendText('#general', 'Loading...'); $ts = $response['ts']; $slack->updateMessage('#general', $ts, 'Done!');
Delete Message
$slack->deleteMessage('#general', '1234567890.123456');
Add Reaction
$slack->addReaction('#general', '1234567890.123456', 'thumbsup');
List Conversations
$channels = $slack->listConversations();
Auth Test
$info = $slack->authTest(); echo $info['user']; // bot username
Incoming Webhooks
No 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:', ));
Slash Commands
Verify and Parse
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
Respond
// Ephemeral (only visible to user) SlashCommand::respond('Processing your request...'); // Visible to entire channel SlashCommand::respond('Weather: 72F, Sunny', inChannel: true);
Error Handling
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(); }
Testing
composer install vendor/bin/phpunit
Links
License
MIT License. Copyright (c) 2026 Renzo Johnson.
renzojohnson/slack-api 适用场景与选型建议
renzojohnson/slack-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「notifications」 「messaging」 「chat」 「webhook」 「slack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 renzojohnson/slack-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 renzojohnson/slack-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 renzojohnson/slack-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
PHP SDK for Mobile Message SMS API
Azure service bus Transport
Official PHP client for NATS messaging system
Captures outgoing SMS notifications
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-24