tob0t / laravel-notification-channel-teams
适用于 Microsoft Teams 的 Laravel 通知通道
Requires
- php: >=7.2
- guzzlehttp/guzzle: ^6.5
- illuminate/notifications: ~5.5 || ~6.0 || ~7.0
- illuminate/support: ~5.5 || ~6.0 || ~7.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2020-06-26 20:41:55 UTC
README
我很高兴地宣布,这个仓库已被 Laravel 通知通道官方接受,现在可以在 https://github.com/laravel-notification-channels/microsoft-teams 找到。请不要再使用此仓库,因为我将很快将其存档。
此包简化了使用 Microsoft Teams 发送通知的过程,适用于 Laravel 5.5+、6.x 和 7.x
return MicrosoftTeamsMessage::create() ->to(config('services.teams.sales_url')) ->type('success') ->title('Subscription Created') ->content('Yey, you got a **new subscription**. Maybe you want to contact him if he needs any support?') ->button('Check User', 'https://foo.bar/users/123');
内容
安装
您可以通过 composer 安装此包
composer require tob0t/laravel-notification-channel-teams
设置连接器
有关设置和添加 webhook 连接器到您的团队通道,请参阅 此。基本 Markdown 受支持,请参阅 消息卡参考文章,了解更多关于“该做什么和不该做什么”的详细信息。
设置 MicrosoftTeams 服务
然后,配置您的 webhook url
将以下代码添加到您的 config/services.php
// config/services.php ... 'teams' => [ 'webhook_url' => env('TEAMS_WEBHOOK_URL'), ], ...
如果您有多个团队或通道,也可以添加多个 webhook,这取决于您。
// config/services.php ... 'teams' => [ 'sales_url' => env('TEAMS_SALES_WEBHOOK_URL'), 'dev_url' => env('TEAMS_DEV_WEBHOOK_URL'), ], ...
使用方法
现在您可以在通知中的 via() 方法中使用此通道
use Illuminate\Notifications\Notification; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsChannel; use NotificationChannels\MicrosoftTeams\MicrosoftTeamsMessage; class SubscriptionCreated extends Notification { public function via($notifiable) { return [MicrosoftTeamsChannel::class]; } public function toMicrosoftTeams($notifiable) { return MicrosoftTeamsMessage::create() ->to(config('services.teams.sales_url')) ->type('success') ->title('Subscription Created') ->content('Yey, you got a **new subscription**. Maybe you want to contact him if he needs any support?') ->button('Check User', 'https://foo.bar/users/123'); } }
除了为收件人添加 to($url) 方法外,您还可以在您的 Notifiable 模型中添加 routeNotificationForMicrosoftTeams 方法。此方法需要返回 webhook url。
public function routeNotificationForMicrosoftTeams(Notification $notification) { return config('services.teams.sales_url') }
可用消息方法
to(string $webhookUrl): 收件人的 webhook url。title(string $title): 消息的标题。summary(string $summary): 消息的摘要。type(string $type): 用于主题颜色的类型(任何有效的十六进制代码或以下之一:primary|secondary|accent|error|info|success|warning)。content(string $content): 消息的内容(支持 Markdown)。button(string $text, string $url = '', array $params = []): 按钮的文本和 URL。用于潜在操作。action(string $text, $type = 'OpenUri', array $params = []): 潜在操作的文本和类型。根据操作可以添加更多参数。有关不同类型的更多信息,请参阅 此链接。options(array $options, $sectionId = null): 向消息有效负载对象添加附加选项。
部分
可以在消息卡片内定义一个或多个部分。以下方法可以在部分中使用:
addStartGroupToSection($sectionId = 'standard_section'):添加一个startGroup属性,标记信息逻辑组的开始。activity(string $activityImage = '', string $activityTitle = '', string $activitySubtitle = '', string $activityText = '', $sectionId = 'standard_section'):向部分添加一个活动。fact(string $name, string $value, $sectionId = 'standard_section'):向部分添加一个事实(支持Markdown)。image(string $imageUri, string $title = '', $sectionId = 'standard_section'):向部分添加一张图片。heroImage(string $imageUri, string $title = '', $sectionId = 'standard_section'):向部分添加一张英雄图片。
此外,还可以通过可选的params值将标题、内容、按钮和操作添加到部分中
title(string $title, array $params = ['section' => 'my-section']):消息的标题,并添加到my-section中。content(string $content, array $params = ['section' => 'my-section']):消息的内容,并添加到my-section中(支持Markdown)。button(string $text, string $url = '', array $params = ['section' => 'my-section']):按钮的文本和URL,并添加到my-section中。action(string $text, $type = 'OpenUri', array $params = ['section' => 'my-section']):潜在操作的文本和类型,并添加到my-section中。
更改日志
请参阅更改日志获取更多信息。
测试
$ composer test
安全
如果您发现任何安全问题,请通过电子邮件tobias.madner@gmx.at联系,而不是使用问题跟踪器。
贡献
请参阅贡献指南获取详细信息。
致谢
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。