oslegend23/slack-laravel

maknz/slack 包的 Laravel 4 和 5 集成,包括门面和服务提供者。

1.2.1 2019-03-22 00:12 UTC

This package is auto-updated.

Last update: 2024-09-22 12:45:11 UTC


README

此包允许您轻松且优雅地在 Laravel 4 或 5 应用中使用 Slack for PHP。阅读以下说明以进行设置,然后前往 Slack for PHP 了解使用详情。

要求

Laravel 4 或 5。

安装

您可以使用 Composer 包管理器安装此包。您可以在项目根目录中运行以下命令来安装它

composer require oslegend23/slack-laravel

然后为要向其发送消息的每个 Slack 团队创建一个 入站 webhook。您将需要 webhook URL(s)来配置此包。

Laravel 5

OsLegend23\Slack\SlackServiceProvider 提供者添加到 config/app.php 中的 providers 数组。

'providers' => [
  OsLegend23\Slack\SlackServiceProvider::class,
],

然后向您的 aliases 数组添加门面

'aliases' => [
  ...
  'Slack' => OsLegend23\Slack\Facade::class,
],

最后,使用 php artisan vendor:publish 发布配置文件。您可以在 config/slack.php 中找到它。

Laravel 4

OsLegend23\Slack\Laravel\ServiceProvider 提供者添加到 app/config.php 中的 providers 数组。

'providers' => [
  ...
  'OsLegend23\Slack\SlackServiceProvider',
],

然后向您的 aliases 数组添加门面

'aliases' => [
  ...
  'Slack' => 'OsLegend23\Slack\Facade',
],

最后,使用 php artisan config:publish oslegend23/slack 发布配置文件。您可以在 app/config/packages/oslegend23/slack-laravel/config.php 中找到配置文件。

配置

配置文件包含默认值和占位符。至少配置一个团队以及您想要更改的任何默认值。

使用

Slack 门面现在是您与库的接口。您可以看到任何调用 OsLegend23\Slack\Client 实例的方法都在 Slack 门面上可用,以便于使用。

请注意,如果您在命名空间中使用门面(例如 Laravel 5 中的 App\Http\Controllers),您需要在上面的类顶部使用 use Slack 来导入它,或者在使用方法时直接访问根命名空间,例如 \Slack::method()

// Send a message to the default channel
Slack::send('Hello world!');

// Send a message to a different channel
Slack::to('#accounting')->send('Are we rich yet?');

// Send a private message
Slack::to('@username')->send('psst!');

现在,前往 Slack for PHP 查看更多示例,包括附件和消息按钮。