Symfony Bundle for labymod/discord-webhook. Configure webhooks easily within your Symfony application
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 |
Composer installation
composer require labymod/discord-webhook-bundle
- Enable your bundle in
config/bundles.php
:return [ // ... \DiscordWebhookBundle\DiscordWebhookBundle::class => ['all' => true], ]
- Add a global and/or environment-based configuration file:
config/[env]/discord_webhook.yaml
# 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.
With discord_webhook.default_url
configured, the basic service (DiscordWebhookBundle\DiscordWebhook
) is configured and publicly available in the service container:
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');
}
}
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: