Send a reminder
Schedule a notification for later. The handler checks current state when it fires.
Use this to
- Send a new user a welcome email 24 hours after they sign up
- Nudge a user to finish onboarding 3 days after they created their account
- Email a shopper about their cart 1 hour after checkout starts
- Send a follow-up email 48 hours after the first, unless the recipient clicks the link
- Escalate a support ticket if no agent replies within 48 hours
Code
Schedule the reminder
await dk.schedule("send-reminder", { key: "user_123", delay: "24h", });
Cancel from a webhook. The job is the state.
// in your email webhook (Resend, Postmark, etc.) // no "email_clicked" column needed in your own db. // the scheduled job is what tracks "still pending" const event = await req.json(); if (event.type === "email.clicked") { await dk.unschedule("send-reminder", event.data.user_id); }
When the time comes, handle the reminder
dk.handle("send-reminder", async ({ key }) => { const user = await db.users.find(key); if (user.onboarded) return; // already acted, skip await sendEmail(user.email, "Finish setting up"); });
npm install delaykit
bun add delaykit