siemen6 / discord-webhook
为 Laravel 5.3 提供的 Discord Webhook 通知通道
dev-master
2018-04-16 09:09 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.3
- illuminate/notifications: ^5.3
- illuminate/support: ^5.1|^5.2|^5.3
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2019-10-08 04:33:06 UTC
README
此包简化了使用 Discord Webhook 在 Laravel 5.3 中发送通知的过程。
内容
安装
您可以通过 composer 安装此包
composer require laravel-notification-channels/discord-webhook
设置您的 Discord Webhook
按照官方指南 使用 Webhook 来设置您的 Discord Webhook。
使用
现在您可以在通知中的 via() 方法中使用此通道
use Illuminate\Notifications\Notification; use NotificationChannels\DiscordWebhook\DiscordWebhookChannel; use NotificationChannels\DiscordWebhook\DiscordWebhookMessage; class Application extends Notification { public function via($notifiable) { return [DiscordWebhookChannel::class]; } public function toDiscordWebhook($notifiable) { return (new DiscordWebhookMessage()) ->content('Your guild received a new membership application!'); } }
路由消息
为了使通知知道您要针对哪个 Webhook (Discord 通道),将 routeNotificationForDiscordWebhook 方法添加到您的 Notifiable 模型中
public function routeNotificationForDiscordWebhook() { return 'https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}'; }
将 ?wait=true 添加到您的 Webhook URL,以接收发送的消息
return 'https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}?wait=true';
发送带有嵌入的消息
Discord Webhook 允许您向消息添加嵌入式丰富内容
public function toDiscordWebhook($notifiable) { return (new DiscordWebhookMessage()) ->from('Raid Calendar') ->content('**Next Raids**') ->embed(function ($embed) { $embed->title('Dragon Dungeon')->description('*on Monday*') ->field('Raid Leader', 'TheTank', true) ->field('Co-Leader', 'HealMePls', true); }); }
发送带有文件上传的消息
Discord Webhook 允许您与消息一起上传文件
public function toDiscordWebhook($notifiable) { return (new DiscordWebhookMessage()) ->content('__Member of the Day:__') ->file(\Storage::get('motd_avatar.png'), 'member_of_the_day.png'); }
可用的消息方法
content($text): 消息内容(最多 2000 个字符)。from($username[, $avatar_url]): 覆盖 Webhook 的默认用户名和头像(可选)。-(目前对 Webhook 不起作用)tts(): 以 TTS 消息发送。file($content, $filename): 正在发送的文件的内容。 注意:与嵌入式丰富内容不兼容embed($callback): 为消息定义(最多 10 个)嵌入式丰富内容。 (请参阅 示例 和 嵌入)
可用的嵌入方法
title($title[, $url]): 设置嵌入的标题。description($text): 设置嵌入的描述。color($color_int): 设置嵌入的颜色代码。footer($text[, $icon_url]): 设置页脚信息。image($img_url): 设置图片信息。thumbnail($img_url): 设置缩略图信息。author($name[, $url, $icon_url]): 设置作者信息。field($name, $value[, $inline_bool]): 设置(内联)字段信息。
变更日志
请参阅变更日志获取更多关于最近更改的信息。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请发送电子邮件至drdrjojo2k@gmail.com,而不是使用问题跟踪器。
贡献
请参阅贡献指南获取详细信息。
致谢
许可协议
MIT 许可协议 (MIT)。请参阅许可文件获取更多信息。