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
  • 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",
});
Optionally cancel it when they act
await dk.unschedule("send-reminder", "user_123");
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