Overview
This recipe shows how to make your agent reach out on a schedule — a daily reminder, a follow-up, a status nudge — by combining a scheduled job with the Channels API. The same pattern works from webhooks and tools.What It Does
- Runs every morning on a cron schedule
- Looks up who needs a reminder
- Sends each a WhatsApp message with
Channels.send - Falls back to an approved template when the recipient’s 24-hour window is closed
- Every send is recorded to the recipient’s conversation thread, so replies continue naturally
Complete Code
Key Concepts
Window-aware sending
Window-aware sending
Free-form WhatsApp is only allowed within 24 hours of the user’s last message. Setting
onClosedWindow: 'fail' makes Channels.send throw when the window is closed, so the catch block can send an approved template instead. (Omit the option to let it queue automatically — see Proactive Messaging.)No conversational context in jobs
No conversational context in jobs
A scheduled job runs outside any conversation, so you address recipients explicitly — here by
to.userId. You can also target a raw phoneNumber or email for cold outreach.messageContext keeps the agent coherent
messageContext keeps the agent coherent
When you send a template,
messageContext is the plain-text summary recorded to the thread. When the user replies, your agent sees “Reminded … about their appointment” and continues naturally — not a blank slate.Variation: confirm on a webhook event
The sameChannels.send call works from a webhook — for example, confirming a payment the moment your payment provider fires its event:
Next steps
Channels API
Full reference for send, sendTemplate, and email.send
Proactive Messaging
The model behind agent-initiated messages
LuaJob
Define scheduled tasks
Webhooks
React to external events

