定制 renzojohnson/slack-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renzojohnson/slack-api

最新稳定版本:v1.0.0

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

Latest Version PHP Version License

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.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固