labymod/discord-webhook-bundle

Discord Webhook Bundle, based on labymod/discord-webhook

Installs: 1 211

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 1

Open Issues: 3

Type:symfony-bundle

1.0.2 2022-01-26 17:10 UTC

This package is auto-updated.

Last update: 2024-05-04 15:20:44 UTC


README

Latest Stable Version Total Downloads License

Symfony Bundle for labymod/discord-webhook. Configure webhooks easily within your Symfony application

Versions & Compatibility

Release Supported PHP Versions Supported Symfony Versions Release Date Maintained Branch
1.x ^8.0 ^4.4, ^5.0, ^6.0 24.01.2022 Yes master

Installation

Composer installation

composer require labymod/discord-webhook-bundle

Symfony configuration & usage

  1. Enable your bundle in config/bundles.php:
    return [
        // ...
        \DiscordWebhookBundle\DiscordWebhookBundle::class => ['all' => true],
    ]
  2. Add a global and/or environment-based configuration file: config/[env]/discord_webhook.yaml

Configuration reference

# Default configuration
discord_webhook:
    default_url:          ~ # required, The Webhook URL for the default service.
    clients:
        # Prototype
        name: # choose a name (service-id) for your preconfigured client
            webhook_url:          ~ # required, The Discord Webhook URL for this client.
            username:             null # optional, The username for the Discord bot.
            avatar_url:           null # optional, URL which is used for the Bot avatar.

Usage

Default Client

With discord_webhook.default_url configured, the basic service (DiscordWebhookBundle\DiscordWebhook) is configured and publicly available in the service container:

Additional named clients

If you have configured one or more named clients like below, you can access them in two ways by their name.

discord_webhook
    # ...
    clients:
        announcements.client:
            webhook_url: 'https://discord.com/my/webhook/url'

Now this client is available as service too:

use DiscordWebhookBundle\DiscordWebhook;

class MyController
{
   public function myAction(DiscordWebhook $announcementsClient) // <-- Thanks to an ArgumentValueResolver, name the parameter after your client, and it will be resolved automatically
   {
      // OR, resolve it from the container:
      $webhook = $this->container->get('announcements.client');
   }
}

Documentation

For detailed documentation how to use the Webhooks, please refer to the underlying library:
https://github.com/LabyMod/discord-webhook/blob/master/README.md

For further documentation have a look here: