Zum Inhalt springen

Slack notifications

Two notifications go to Slack through incoming webhooks. Both are production only. A missing secret turns the notification off; it never blocks a user.

ChannelContentWorkerSecret
#nowyourlink-signupsOne message per new accountapiSLACK_WEBHOOK_SIGNUPS
#nowyourlink-statsOne message per day at 07:05 UTCcronSLACK_WEBHOOK_STATS, CF_ANALYTICS_API_TOKEN

The helper accepts only https://hooks.slack.com/ URLs. An empty value or a REPLACE_WITH* placeholder is “not configured”.

POST /register calls the hook after it inserts a new pending user. The hook does not fire for a DOI resend, a verified user or the loser of an insert race.

The message contains:

  • the UTC time and the environment,
  • the email domain (never the local part),
  • the country and the locale,
  • whether a VAT ID was given (never the VAT ID itself).

The message never contains the company name, the full email or the client IP. The Slack call runs in waitUntil with a 3-second timeout. A Slack failure logs register.slack_notify_failed and does not change the response.

The cron lane 5 7 * * * reports yesterday (UTC) against the day before. Each source is independent. A failed or unconfigured source shows “unavailable”, never 0.

LineSourceNeeds
RegistrationsD1 users.created_at (index users_created_at_idx)DB binding
Cloudflare edge: requests, page views, unique visitorsZone GraphQL httpRequests1dGroups, all traffic incl. botsCF_ANALYTICS_API_TOKEN, CF_ZONE_ID
First-party page views and top 5 pagesAnalytics Engine dataset of the cookieless /api/collect collectorCF_ANALYTICS_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, ANALYTICS_ENGINE_DATASET
Notable changesAny metric with a change of 50 % or more on a base of 10 or more—

The sources count different things. The message labels each line and never adds them together. Top pages hide paths with fewer than 2 views.

CF_ZONE_ID is a plain wrangler var (the zone id of nowyourlink.com). CLOUDFLARE_ACCOUNT_ID is a wrangler var that render-wrangler.sh fills from the terraform output cf_account_id.

  1. In Slack, create the channels #nowyourlink-signups and #nowyourlink-stats.
  2. In a Slack app with Incoming Webhooks, add one webhook per channel.
  3. In Cloudflare, create a custom API token with Account Analytics: Read and Zone Analytics: Read for nowyourlink.com.
  4. Put the three values in .env.production.local.
  5. Push them: pnpm secrets:put --env production --from .env.production.local --only SLACK_WEBHOOK_SIGNUPS --only SLACK_WEBHOOK_STATS --only CF_ANALYTICS_API_TOKEN --worker api --worker cron --apply.
  6. Deploy through the existing production workflow. Migration 0052 runs in the deploy.
  • Sign-up alert: register a test account on production, then look in #nowyourlink-signups.
  • Daily stats: the next 07:05 UTC run posts to #nowyourlink-stats. The worker log shows cron.daily_stats.posted, or cron.daily_stats.unconfigured when a secret is missing.