awssat / discord-notification-channel
Discord Notification Channel for laravel.
Installs: 86 370
Dependents: 0
Suggesters: 0
Security: 0
Stars: 94
Watchers: 3
Forks: 7
Open Issues: 0
Requires
- php: ^7.1.3|^8.0
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/notifications: ~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- laravel/slack-notification-channel: ^2.0|^3.2
Requires (Dev)
- mockery/mockery: ^1.4 || ^1.6
- phpunit/phpunit: ^7.0|^8.0|^9.0|^10.1
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/.......'; } }