定制 ntimyeboah/php-slack 二次开发

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

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

ntimyeboah/php-slack

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ntimyeboah/php-slack

包简介

A package to integrate Slack in your PHP applications

README 文档

README

Build Status Software License

This package makes it easier to integrate Slack into your PHP application. It provides intuitive and simple API to send simple messages and complex messages using the BlockKit framework.

Requirements

This package requires at least PHP 8.2.

Installation

composer require ntimyeboah/php-slack

Basic Usage

Sending messages

You have the option to send messages by configuring the Slack token and channel methods on the SlackMessage object using the token() and channel() methods respectively.

use NtimYeboah\PhpSlack\SlackMessage;

(new SlackMessage)
    ->token('xoxb-123abc')
    ->channel('general')
    ->text('Hello')
    ->send();

You can also configure the Slack token and channel using the Credentials object.

use NtimYeboah\PhpSlack\Credentials

$credentials = Credentials::make('general', 'xoxb-123abc');

$slackMessage = new SlackMessage($credentials);

$slackMessage->text('Hello')
$slackMessage->send();

Advanced Usage

This package make it easy to send messages using the BlockKit framework to customize and order the appearance of your messages.

Sending messages using the Section block

Use the section($closure) method to send a Section block.

use NtimYeboah\PhpSlack\Credentials;
use NtimYeboah\PhpSlack\BlockKit\Blocks\Section;

$credentials = Credentials::make('general', 'xoxb-123abc');

(new SlackMessage($credentials))
    ->section(function (Section $section) {
        $section->field('This is a field')->markdown();
        $section->field('This is another field');
    })
    ->send();

The above generates these blocks.

[
    {
        "type": "section",
        "fields": [
            {
                "type": "mrkdwn",
                "text": "This is a field"
            },
            {
                "type": "plain_text",
                "text": "This is another field"
            }
        ]
    }
]

Sending messages using the Context block

Use the context($closure) method to send a Context block.

use NtimYeboah\PhpSlack\Credentials;
use NtimYeboah\PhpSlack\BlockKit\Blocks\Context;

$credentials = Credentials::make('general', 'xoxb-123abc');

(new SlackMessage($credentials))
    ->context(function (Context $block) {
        $block->text("*This* is :smile markdown")->markdown();
        $block->image('http://path/to/image.jpg')->altText('cute cat');
        $block->text('This is a plain text');
    })
    ->send()

The above generates these blocks.

[
    {
        "type": "context",
        "elements": [
            {
                "type": "mrkdwn",
                "text": "*This* is :smile markdown"
            },
            {
                "type": "image",
                "image_url": "http:\/\/path\/to\/image.jpg",
                "alt_text": "cute cat"
            },
            {
                "type": "plain_text",
                "text": "This is a plain text"
            }
        ]
    }
]

Sending messages using the Header block

Use the header($closure) method to send a Header block.

use NtimYeboah\PhpSlack\Credentials;
use NtimYeboah\PhpSlack\BlockKit\Blocks\Header;

$credentials = Credentials::make('general', 'xoxb-123abc');

(new SlackMessage($credentials))
    ->header(function (Header $block) {
        $block->text('This is a header text');
    })
    ->send();

The code above generates these blocks.

[
    {
        "type": "header",
        "text": {
            "type": "plain_text",
            "text": "This is a header text"
        }
    }
]

Sending messages using the RichText block

Use the richText($closure) method to send a Rich Text block.

use NtimYeboah\PhpSlack\Credentials;
use NtimYeboah\PhpSlack\BlockKit\Blocks\RichText;

$credentials = Credentials::make('general', 'xoxb-123abc');

(new SlackMessage($credentials))
    ->richText(function (RichText $block) {
        $block->text('This is a text');
        $block->text('This is a bold text')->bold();
        $block->text('This is an italic text')->italic();
        $block->text('This is a strikethrough text')->strike();
        $block->emoji('basketball');
    })
    ->send();

The above generates these blocks.

[
    {
        "type": "rich_text",
        "elements": [
            {
                "type": "rich_text_section",
                "elements": [
                    {
                        "type": "text",
                        "text": "This is a text"
                    },
                    {
                        "type": "text",
                        "text": "This is a bold text",
                        "style": {
                            "bold": true
                        }
                    },
                    {
                        "type": "text",
                            "text": "This is an italic text",
                            "style": {
                                "italic": true
                        }
                    },
                    {
                        "type": "text",
                        "text": "This is a strikethrough text",
                        "style": {
                            "strike": true
                        }
                    },
                    {
                        "type": "emoji",
                        "name": "basketball"
                    }
                ]
            }
        ]
    }
]

Sending messages using the Divider block

Use the divider() method to send a Divider block.

use NtimYeboah\PhpSlack\Credentials;

$credentials = Credentials::make('general', 'xoxb-123abc');

(new SlackMessage($credentials))
    ->divider()
    ->send();

The above generates this block.

[
    {
        type": "divider"
    }
]

Consider hiring me

I am currently seeking new employment opportunities and would appreciate it if you'd keep me in mind for roles such as Backend Developer. Kindly contact me at: ntimobedyeboah@gmail.com

This is a link to my CV: Ntim Yeboah CV

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover a security vulnerability within this package, please send an e-mail to Ntim Yeboah at ntimobedyeboah@gmail.com. All security vulnerabilities will be promptly addressed.

License

Php Slack is licensed under The MIT License (MIT).

统计信息

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

GitHub 信息

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

其他信息

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