Accepting web hooks from Prismic

… and busting the content cache accordingly

First of all, this might be obvious, but your app must be reachable by the outside world in order to accept web hooks from Prismic. How you set that up is beyond the scope of these docs.

Available Options

There are 3 configuration options available: The URL in your app where hooks are sent, a flag to turn them on and off and an optional shared secret that you expect to find in the payload given to you by Prismic.

Configuration can be placed anywhere that it will be aggregated in a standard Mezzio application, typically, that would be in a php file under ./config/autoload/ or in a config provider also loaded by Laminas config aggregator.

<?php
// ... ./config/autoload/primo.global.php

return [
  'primo' => [
    'webhook' => [
      'secret' => 'Some very secret and random string',
      'enabled' => true,
      'url' => '/send/my/prismic/webhooks/here',
    ],
  ],
];

Assuming you app is reachable at https://myapp.com, by default, the web hook url you would provide to Prismic would be https://myapp.com/prismic-webhook. Substitute the url path for whatever you have configured and provide that, along with the secret to Prismic.io's web hook configuration settings.

If you are happy with the default url, it can be omitted from your configuration.

Web hooks are disabled by default, so you must add 'enabled' => true.

The Webhook Event

The web hook functionality is provided by the Primo library/module, which upon receipt of a web hook payload triggers a specific event containing the payload using whatever PSR-14 Event Dispatcher has been configured. Out-of-the-box, the skeleton uses phly/phly-event-dispatcher.

Inside the ./src/App/src/Listener directory, you can inspect the behaviour of the default listener. It performs some rudimentary inspection of the payload, sends some information to the logs and clears the caches.

I frequently use this event to also prime the cache again, and/or rebuild an SEO site-map for example.

For more details on what these web hook payloads look like, you can consult the official docs here.