Build a guestbook · Exercise 04
Get notified
Get an email or a chat message whenever someone signs your guestbook.
Paste this into your agent
Copied! Now paste it into your agent. No agent yet? Here's how to get one.
Get notified
A guestbook isn’t much fun if you never find out someone signed it. In this exercise your Worker tells you about each new entry, whether Clef approved it or held it back.
What you’ll build
A notification for every new entry, the way you chose in the interview:
- An email from your own domain, sent with Email Service. Sending to your own verified address is free on every plan. This needs a domain on Cloudflare.
- A post in a Discord or Slack channel, sent to an incoming webhook. No domain needed.
Don’t make the visitor wait
Sending an email or calling a webhook takes a moment, and sometimes fails. The person signing your guestbook shouldn’t wait for it, or see an error because of it. So your Worker saves the entry, replies right away, and sends the notification afterward with waitUntil(), which keeps the Worker running until the notification has gone out:
import { waitUntil } from "cloudflare:workers";
waitUntil(notify(entry));
return Response.json({ status }, { status: 201 });
That’s plenty for a guestbook. When background work has to survive failures, with retries, or there’s a lot of it, the next step is a Queue: your Worker puts a message on it, and a consumer handles it separately, retrying if it fails.
Prerequisites
- You’ve completed Moderate messages and still have that project on disk.
- For email, a domain on Cloudflare. Otherwise, a Discord server or Slack workspace where you can add a webhook.