tomatophp/filament-discord

使用原生 FilamentPHP 通知外观类向 discord 频道发送通知

v1.0.1 2024-07-09 14:30 UTC

This package is auto-updated.

Last update: 2024-09-11 14:50:09 UTC


README

Screenshot

Filament Discord 通知

Latest Stable Version License Downloads

使用原生 FilamentPHP 通知外观类向 discord 频道发送通知

截图

Notification Error Log Error Log Link

安装

composer require tomatophp/filament-discord

在安装后,在你的 .env 文件中设置

DISCORD_WEBHOOK=
DISCORD_ERROR_WEBHOOK=
DISCORD_ERROR_WEBHOOK_ACTIVE=

其中 DISCORD_WEBHOOK 是主要通知频道的 webhook,DISCORD_ERROR_WEBHOOK 是错误记录频道 webhook,DISCORD_ERROR_WEBHOOK_ACTIVE 设置为 true 或 false 来激活或停止记录

使用方法

您可以使用多方式向 discord 发送通知,其中第一种是使用原生的 FilamentPHP Notification::class

use \Filament\Notifications\Notification;

Notification::make()
    ->title('Hi')
    ->body('Welcome On The Moon!')
    ->sendToDiscord()

您可以在消息中附加图片,如下所示

use \Filament\Notifications\Notification;

Notification::make()
    ->title('Hi')
    ->body('Welcome On The Moon!')
    ->sendToDiscord(image: "https://raw.githubusercontent.com/tomatophp/filament-discord/master/arts/3x1io-tomato-discord.jpg")

发送到指定用户

您可以通过在用户表上添加名为 webhook 的列,然后将其添加到 User 模型中来向指定用户 webhook 发送通知

use TomatoPHP\FilamentDiscord\Traits\InteractsWithDiscord;

class User {
    use InteractsWithDiscord;
}

现在您可以像这样向用户发送通知

use \Filament\Notifications\Notification;

Notification::make()
    ->title('Hi')
    ->body('Welcome On The Moon!')
    ->sendToDiscord($user)

允许 Discord 错误记录器

您可以将 Discord 频道用作错误记录器,以非常简单的方式记录并跟踪错误,在您的 bootstrap/app.php 中添加此类,如下所示

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use ProtoneMedia\Splade\Http\SpladeMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        channels: __DIR__.'/../routes/channels.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
    })
    ->withExceptions(function (Exceptions $exceptions) {
        \TomatoPHP\FilamentDiscord\Helpers\DiscordErrorReporter::make($exceptions);
    })->create();

发布资源

您可以使用此命令发布配置文件

php artisan vendor:publish --tag="filament-discord-config"

其他 Filament 包

查看我们的 Awesome TomatoPHP