nimble-nl / laravel-slack
Laravel 发送 Slack 消息的包
v1.0.0
2018-01-12 13:40 UTC
Requires
- php: >=5.5.9
- guzzlehttp/psr7: 1.4.*
- illuminate/support: ^5.1
- php-http/httplug: 1.1.*
Requires (Dev)
- php-http/mock-client: ^1.0
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2024-09-29 04:49:36 UTC
README
Laravel Slack 包
用于发送 Slack 消息的 Laravel 包
更多信息请参阅 Slack
需求
Laravel 5.1 或更高版本
安装
安装是一个快速的三步过程
- 使用 composer 下载 laravel-slack
- 配置您的 HTTP 适配器
- 在 app.php 中启用包
- 配置您的 Slack 凭据
- (可选) 配置包门面
步骤 1: 使用 composer 下载 laravel-slack
运行以下命令添加 nimbles-nl/laravel-slack
composer require nimbles-nl/laravel-slack
步骤 2: 在服务容器中配置您 HTTP 适配器
在 AppServiceProvider.php 中配置 http 适配器
use GuzzleHttp\Client as GuzzleClient; use Http\Adapter\Guzzle6\Client as GuzzleAdapter; $this->app->singleton('http.client', function() { return new GuzzleAdapter(new GuzzleClient()); });
步骤 3: 在 app.php 中启用包
在 config/app.php 中注册服务
Nimbles\Slack\SlackServiceProvider::class,
步骤 4: 配置 Slack 凭据
php artisan vendor:publish
在您的 .env 文件中添加以下内容
SLACK_ACCESS_TOKEN=your_secret_slack_access_token
步骤 5 (可选): 配置包门面
在 config/app.php 中注册 Slack 门面
'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, ... 'Slack' => Nimbles\Slack\Facade\Slack::class,
用法
$slackMessage = new SlackMessage('You re looking great today!', '#general', 'AwesomeBot', 'https://www.link-to-avatar.com/image.png'); app('slack')->sendMessage($slackMessage);
或者如果您想使用门面,在类声明后添加以下内容
Slack::sendMessage(new SlackMessage('You are looking great today!'));