承接 the-trybe/laravel-discord-alerts 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

the-trybe/laravel-discord-alerts

最新稳定版本:v1.0.0

Composer 安装命令:

composer require the-trybe/laravel-discord-alerts

包简介

Automatic Discord notifications for failed Laravel queue jobs via webhooks

README 文档

README

Latest Version on Packagist Total Downloads

Automatically send beautiful Discord notifications when your Laravel queue jobs fail. Zero configuration needed beyond the webhook URL!

Installation

Install via Composer:

composer require the-trybe/laravel-discord-alerts

Configuration

1. Create a Discord Webhook

  1. Open your Discord server
  2. Go to Server SettingsIntegrationsWebhooks
  3. Click New Webhook
  4. Name it (e.g., "Laravel Alerts" or whatever~)
  5. Select the channel where alerts should be posted
  6. Copy the Webhook URL

2. Add Webhook URL to Environment

Add to your .env file:

DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1234567890/abcdefghijklmnopqrstuvwxyz
DISCORD_ALERTS_ENABLED=true

3. Done!

That's it! The package will automatically send Discord alerts when any queue job fails.

Advanced Configuration

Publish the configuration file (optional):

php artisan vendor:publish --tag=discord-alerts-config

This creates config/discord-alerts.php with the following options:

return [
    // Enable/disable alerts
    'enabled' => env('DISCORD_ALERTS_ENABLED', true),

    // Your Discord webhook URL
    'webhook_url' => env('DISCORD_WEBHOOK_URL'),

    // Include full stack trace (useful for debugging)
    'include_stack_trace' => env('DISCORD_INCLUDE_STACK_TRACE', false),

    // Include job payload/properties
    'include_payload' => env('DISCORD_INCLUDE_PAYLOAD', true),

    // Maximum payload length (prevents message overflow)
    'max_payload_length' => env('DISCORD_MAX_PAYLOAD_LENGTH', 500),
];

Environment Variables

All available environment variables:

# Required
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...

# Optional
DISCORD_ALERTS_ENABLED=true                # Enable/disable alerts (default: true)
DISCORD_INCLUDE_STACK_TRACE=false          # Include stack trace (default: false)
DISCORD_INCLUDE_PAYLOAD=true               # Include job data (default: true)
DISCORD_MAX_PAYLOAD_LENGTH=500             # Max payload chars (default: 500)

Usage Examples

Basic Usage

No code changes needed! Just dispatch your jobs as usual:

use App\Jobs\ProcessPodcast;

// Dispatch job normally
ProcessPodcast::dispatch($podcast);

// If the job fails, you'll automatically get a Discord alert

What Information is Included?

Each Discord alert includes:

Always Included:

  • Job Class - Full class name of the failed job
  • Error Message - Exception message
  • Attempts - Number of times job was attempted
  • Environment - production/staging/local
  • Timestamp - When the failure occurred
  • Queue Name - Which queue the job was on
  • Connection - Queue connection (redis, database, etc.)
  • Server - Hostname or app URL
  • Exception Type - Class name of the exception
  • Location - File and line where error occurred

Optional (Configurable):

  • Job Payload - Job properties and data
  • Stack Trace - Full exception stack trace

Environment-Based Colors

Alerts are color-coded based on environment:

  • Production - Red (critical)
  • Staging - Orange (warning)
  • Local/Other - Yellow (info)

Troubleshooting

Not Receiving Alerts?

  1. Check webhook URL is set:

    php artisan config:clear
    php artisan tinker
    >>> config('discord-alerts.webhook_url')
  2. Check alerts are enabled:

    >>> config('discord-alerts.enabled')
  3. Check Laravel logs for any errors:

    tail -f storage/logs/laravel.log
  4. Test the webhook directly:

    curl -X POST "YOUR_WEBHOOK_URL" \
      -H "Content-Type: application/json" \
      -d '{"content": "Test message from Laravel"}'

License

The MIT License (MIT). Please see License File for more information.

Credits

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-15