awssat/discord-notification-channel
最新稳定版本:1.4.5
Composer 安装命令:
composer require awssat/discord-notification-channel
包简介
Discord Notification Channel for laravel.
README 文档
README
Introduction
Send Discord messages through webhook with Discord or Slack payload via Laravel Notifications channels
Features
- Support slack payload by using
new (new SlackMessage)or$this->toSlack($notifiable) - Support discord webhook payload
- Easy to use
Install
Via Composer
composer require awssat/discord-notification-channel
Usage
in your notification you should define the discord channel in the via method
public function via($notifiable) { return ['mail', 'discord']; }
you should have a toDiscord method
public function toDiscord($notifiable) { return (new DiscordMessage) ->from('Laravel') ->content('Content') ->embed(function ($embed) { $embed->title('Discord is cool')->description('Slack nah') ->field('Laravel', '9.0.0', true) ->field('PHP', '8.0.0', true); }); }
toDiscord method can receive DiscordMessage or SlackMessage
Example of slack message
public function toDiscord($notifiable) { return (new SlackMessage) ->content('One of your invoices has been paid!'); }
or if you want you can make it run from toSlack method
public function toSlack($notifiable) { return (new SlackMessage) ->content('One of your invoices has been paid!'); } public function toDiscord($notifiable) { return $this->toSlack($notifiable); }
https://laravel.com/docs/6.x/notifications#slack-notifications for further laravel slack messages examples
Routing Discord Notifications
To route Discord notifications to the proper location, define a routeNotificationForDiscord method on your notifiable entity. This should return the webhook URL to which the notification should be delivered. read Webhook Discord docs here https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks
<?php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use Notifiable; /** * Route notifications for the Discord channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForDiscord($notification) { return 'https://discordapp.com/api/webhooks/.......'; } }
统计信息
- 总下载量: 112.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 94
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-31