Slack API 的轻量级 PHP 实现。

1.1.0 2018-08-07 07:05 UTC

This package is auto-updated.

Last update: 2024-09-07 00:02:09 UTC


README

Scrutinizer Code Quality Build Status Code Intelligence Status codecov

Slack API 的轻量级 PHP 实现。

为什么这个库要分叉和重新编码

  • 遗留代码(仓库闲置超过2年)不允许支持 PHP >= 7.1 的新功能
  • 一些小错误和不稳定的功能
  • 没有单元测试覆盖率

提供

  • Slacky\Contracts

    一组小型合约,允许消费 Slack API。包括 InteractorResponseResponseFactory

    • Interactor 负责提供 Http GET/POST 方法。
    • Response 负责提供一个简单的 Http 响应包装器,用于存储正文、头信息和状态码。
    • ResponseFactory 负责提供一个工厂来实例化和构建 Response

要使用此包,非常简单。不过请注意,这个实现非常轻量级,这意味着你需要做更多的工作。此包不提供如 Chat::postMessage(string message) 这样的方法,它实际上只提供了一个方法(Commander::execute(string command, array parameters = []))。

以下是一个使用此包的非常简单的示例

<?php

use Slacky\Http\SlackResponseFactory;
use Slacky\Http\CurlInteractor;
use Slacky\Core\Commander;

$interactor = new CurlInteractor;
$interactor->setResponseFactory(new SlackResponseFactory);

$commander = new Commander('xoxp-some-token-for-slack', $interactor);

$response = $commander->execute('chat.postMessage', [
    'channel' => '#general',
    'text'    => 'Hello, world!'
]);

if ($response['ok'])
{
    // Command worked
}
else
{
    // Command didn't work
}

请注意,Commander 会自动格式化大多数输入以符合 Slack 的要求,但不支持附件 - 你需要手动调用 $text = Commander::format($text) 来转换它。