# Cloudflare

> Get a push for Cloudflare Pages deployments, Workers Builds, and any other Cloudflare notification like origin errors or DDoS alerts.

Cloudflare sends its notifications to a webhook destination. Point that destination at Opush and you get pushes for Pages deployments and for any other Cloudflare notification: origin errors, DDoS attacks, health checks, Workers alerts and more. Workers Builds need one extra step, described below.

## Set it up [#set-it-up]

<Steps>
<Step>

### Create the integration in Opush [#create-the-integration-in-opush]

In the app or the web console, add a service integration and pick **Cloudflare**. Give it a name if you like. Copy the **Payload URL** and the **Secret**.

</Step>
<Step>

### Add a webhook destination [#add-a-webhook-destination]

In the Cloudflare dashboard, open **Notifications › Destinations** and create a webhook.

- **URL**: the payload URL from Opush.
- **Secret**: the secret from Opush.

Click **Save and Test**. Cloudflare sends a test message, and you get a "Webhook connected" push.

</Step>
<Step>

### Add notifications [#add-notifications]

Open **Notifications › Add**. Pick **Pages › Project updates**, or any other notification, and choose this webhook as the destination. Add as many notifications as you like to the same destination.

</Step>
</Steps>

Cloudflare puts the secret in the `cf-webhook-auth` header. Opush rejects requests where it doesn't match.

## What gets pushed [#what-gets-pushed]

| Cloudflare event | Subtitle | Message |
|---|---|---|
| Destination test message | `Webhook connected` | `Cloudflare can reach Opush.` |
| Pages deployment succeeded | `Deployed` | `production · abcdef1 · rocket` |
| Pages deployment failed | `Deploy failed` | `production · abcdef1 · rocket` |
| Workers Builds failed | `api · Failed` | `Bump deps · main · api-repo` |
| Any other notification | The notification's name | Its description |

- **Pages**: the message has the environment, the first 7 characters of the commit and the project. Tapping the push opens the deployment's URL. Deployments that start only open a live progress card. Cancelled deployments aren't pushed.
- **Workers Builds**: the subtitle is the Worker's name and the result. The message has the commit message, the branch and the repository. Cancelled builds aren't pushed.
- **Other notifications**: for example an origin error alert shows `Origin errors` with `5xx rate is above 5%`. When Cloudflare says the alert has ended, "Resolved" is added to the subtitle.

Failed Pages deployments and failed Workers builds arrive as time-sensitive notifications.

## Workers Builds [#workers-builds]

Workers Builds don't send webhooks. They only publish events to a [Cloudflare Queue](https://developers.cloudflare.com/queues/) through an event subscription. To get them in Opush, forward the queue to your payload URL with a small Worker.

1. Create a queue, and add an event subscription that sends Workers Builds events for your Worker to it.
2. Create a Worker that consumes the queue and posts each message to Opush as is:

```js
export default {
  async queue(batch, env) {
    for (const msg of batch.messages) {
      await fetch(env.OPUSH_URL, {
        method: "POST",
        headers: { "content-type": "application/json", "cf-webhook-auth": env.OPUSH_SECRET },
        body: JSON.stringify(msg.body),
      });
      msg.ack();
    }
  },
};
```

3. Set `OPUSH_URL` to the payload URL and `OPUSH_SECRET` to the secret from Opush. Keep the secret as a Worker secret, for example with `wrangler secret put OPUSH_SECRET`.

You can use the same integration for Pages, Workers Builds and other notifications.

## Options [#options]

- **Only push failures**: skip pushes for Pages deployments and Workers builds that succeed.
- **Show progress as a Live Activity** (iPhone and Android apps): when a Pages deployment or a Workers build starts, a live progress card shows how long it has been running. It ends when it succeeds, fails or is cancelled. Cloudflare doesn't send build steps, so the card has no progress bar.

See [Live progress](/docs/push/live-progress) for how cards look on iPhone and Android.
