ocolin/slack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ocolin/slack

最新稳定版本:v4.0.1

Composer 安装命令:

composer require ocolin/slack

包简介

Basic PHP Slack Client

README 文档

README

Description

This is a very small light-weight PHP client for querying the Slack API server. It has no default methods and is just a simple HTTP interface to make your own calls with.

It is meant to be used in conjunction with the API docs found here:

https://docs.slack.dev/reference/methods/

You need to simply paste the desired Slack API method, include any required query parameters, POST body object (if making a POST request), and use the get() or post() method depending on what the Slack method requires.

Installation

composer require ocolin/slack

Requirements

In order to use the tool you must provide a Bearer token in order to authenticate with the Slack API server. There are two ways this can be done.

  • PHP >= 8.4
  • guzzlehttp/guzzle >= 7.10
  • ocolin/global-type >= 2.0
  • Supplying a token to the constructor
  • Using an environment variable.

Instantiating

Constructor arguments

  • token - Slack authentication token. Optional if using environment variable.
  • options - Array of optional Guzzle client settings.

EXAMPLE: Using environment variable

// Manual env for demonstration.
$_ENV['SLACK_TOKEN'];
$slack = new Ocolin\Slack\Client();

EXAMPLE: Using all constructor arguments

$slack = new Ocolin\Slack\Client(
      token: 'yourtokengoeshere',
    options: [
        'timeout' => 20,
        'verify'  => true
    ]
);

Making API calls.

Once you have your class instantiated, you are ready to make calls. SLack API takes two types of requests, POST and GET. The Post function has parameters for both query and body parameters as some methods may use both at the same time. Both GET and POST parameters can be an associative array or an object.

EXAMPLE: GET Request

$reqponse = $slack->get( 
    method: 'emoji.list'
    query: [ 'include_categories' => false ]
);

Expected output:

stdClass Object
(
    [ok] => 1
    [emoji] => stdClass Object
        (
            [bowtie] => https://emoji.slack-edge.com/T04KULNSASH/bowtie/f3ec6f2bb0.png
            [squirrel] => https://emoji.slack-edge.com/T04KULNSASH/squirrel/465f40c0e0.png
            [glitch_crab] => https://emoji.slack-edge.com/T04KULNSASH/glitch_crab/db049f1f9c.png
            [piggy] => https://emoji.slack-edge.com/T04KULNSASH/piggy/b7762ee8cd.png
            [cubimal_chick] => https://emoji.slack-edge.com/T04KULNSASH/cubimal_chick/85961c43d7.png
            [dusty_stick] => https://emoji.slack-edge.com/T04KULNSASH/dusty_stick/6177a62312.png
            [slack] => https://emoji.slack-edge.com/T04KULNSASH/slack/7d462d2443.png
            [pride] => https://emoji.slack-edge.com/T04KULNSASH/pride/56b1bd3388.png
            [thumbsup_all] => https://emoji.slack-edge.com/T04KULNSASH/thumbsup_all/50096a1020.png
            [slack_call] => https://emoji.slack-edge.com/T04KULNSASH/slack_call/b81fffd6dd.png
            [shipit] => alias:squirrel
            [white_square] => alias:white_large_square
            [black_square] => alias:black_large_square
            [simple_smile] => https://a.slack-edge.com/80588/img/emoji_2017_12_06/apple/simple_smile.png
        )

    [cache_ts] => 1560987000.000000
)

EXAMPLE: Post Request

In order to test parameters, we are invoking a test error.

$response = $slack->post(
    method: 'api.test',
    params: [ 'error' => 'This is a test' ]
);

Output Format

property type Description
ok Boolean Call was success/failure
status Int HTTP status code
body Object The full Slack response object
error string Error message from server.
warning string Warning from server
retry_after int Seconds to wait for rate limit

UPDATES NEEDED

  • Unit testing.
  • README revamp

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固