You are here

public function WebhookController::receive in Webhooks 8

Webhooks receiver.

Parameters

string $incoming_webhook_name: The machine name of a webhook.

Return value

\GuzzleHttp\Psr7\Response Return a response with code 200 for OK or code 500 in case of error.

1 string reference to 'WebhookController::receive'
webhooks.routing.yml in ./webhooks.routing.yml
webhooks.routing.yml

File

src/Controller/WebhookController.php, line 99

Class

WebhookController
Class Webhook.

Namespace

Drupal\webhooks\Controller

Code

public function receive($incoming_webhook_name) {
  try {
    $this->webhooksService
      ->receive($incoming_webhook_name);
  } catch (WebhookIncomingEndpointNotFoundException $e) {
    $this->logger
      ->error($e
      ->getMessage());
    return new Response(404, [], $e
      ->getMessage());
  } catch (WebhookMismatchSignatureException $e) {
    $this->logger
      ->error('Unauthorized. Signature mismatch for Webhook Subscriber %name: @message', [
      '%name' => $incoming_webhook_name,
      '@message' => $e
        ->getMessage(),
      'link' => Link::createFromRoute($this
        ->t('Edit Webhook'), 'entity.webhook_config.edit_form', [
        'webhook_config' => $incoming_webhook_name,
      ])
        ->toString(),
    ]);
    return new Response(401, [], $e
      ->getMessage());
  }
  $this->logger
    ->info('Received a Webhook: %name', [
    '%name' => $incoming_webhook_name,
    'link' => Link::createFromRoute($this
      ->t('Edit Webhook'), 'entity.webhook_config.edit_form', [
      'webhook_config' => $incoming_webhook_name,
    ])
      ->toString(),
  ]);
  return new Response(200, [], 'OK');
}