Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Symfony Webhook Receiver

Security covered Maintenance fixes only

This module integrates Symfony's webhook receiver functionality into Drupal. It allows developers to define custom webhook types, parse incoming webhook requests, and process them using dedicated consumers. Secrets can be configured to secure these webhook communications.

Registers Symfony Webhook component's webhook receiver features in Drupal.

Before you start

Read Symfony's official Webhook component documentation and
read the additions to that in this pull request if it is still open to understand the fundamental concepts.

Define your own webhook type

To define a custom webhook type, register the required services in your [MY_MODULE].services.yml file:

services:
  _defaults:
    autowire: true
    public: false

  my_module.webhook.request_parser.my_type:
    parent: symfony_webhook_receiver.request_parser # Or use your own \Symfony\Component\Webhook\Client\RequestParserInterface implementation.
    tags:
      - { name: webhook.request_parser, type: my_type }

  my_module.webhook.remote_event.consumer.my_type:
    class: Drupal\my_module\MyTypeConsumer
    # Remote Event Consumers have to be public otherwise service locator
    # does not find them.
    public: true
    tags:
      - { name: remote_event.consumer, type: my_type }

In this example:

  • my_type represents your custom webhook type.
  • Replace my_module with your module name.
  • The MyTypeConsumer class must implement the \Symfony\Component\RemoteEvent\Consumer\ConsumerInterface.

Remote Event Consumer auto-discovery

A Remote Event Consumer class residing in the src/RemoteEventConsumer
directory of a module is auto-discoverable. It has to have a
#[AsRemoteEventConsumer] attribute on the class and it must implement the
\Symfony\Component\RemoteEvent\Consumer\ConsumerInterface interface.

See ExampleAutoDiscoverConsumer as example.

The rest of the necessary configuration with defining a parser and secret for
the webhook type remains the same.

Configure secret for webhook type

Secrets are essential for securing webhook communications. To configure the secret for your custom webhook type, follow these steps:

  1. Ensure your service configuration is included:

    In web/sites/default/settings.local.php, make sure to include services.local.yml (or a dedicated service file) in the container YAML files:

    $settings['container_yamls'][] = __DIR__ . '/services.local.yml';
    
  2. Define the secret for your webhook type:

    In the services.local.yml file, define the secret for your webhook type as a parameter:

    parameters:
      symfony_webhook_receiver.request_parser.my_type.secret: 'my_super_secret'
    

    Make sure to replace 'my_super_secret' with your actual secret.

Extending functionality

You can enhance and extend the behavior of your webhook receivers in the following ways:

  • Fetch secrets from environment variables:

    If you'd prefer to retrieve secrets from environment variables, you will need to create a custom ServiceProvider and implement a CompilerPass. This will allow you to capture the value from an environment variable and set it as the corresponding container parameter.

    Since Drupal currently lacks native support for environment variables as container parameters, this approach can be particularly useful.

  • Create a custom WebhookController:

    Another option is to build a custom WebhookController that fetches secrets from an alternative location, such as a secure storage service. Even with a custom controller, you can still leverage the reusable components provided by the Symfony Webhook package.

Drupal 10–11

Ask your assistant about Symfony Webhook Receiver

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Oct 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.0.0 Stable 10–11 Oct 7, 2024
1.x-dev Dev 10–11 Oct 7, 2024