When building product onboarding flows, how can we trigger multi-step automated email drip sequences directly from our app’s backend using custom user events (like workspace_created or project_launched) instead of hardcoding cron jobs and delays in our application code?
Decoupling Email Logic from Application Backend Code
Instead of hardcoding delays (setTimeout, BullMQ jobs, or database cron pollers) to send Day 1, Day 3, and Day 7 onboarding emails, you can dispatch custom behavioral events to AutoSend and let the automation workflow engine handle time delays, dynamic branching, and suppression checks automatically.
1. Dispatching Custom User Events (POST /v1/events/send)
When a user performs a key action in your product (e.g., creating a workspace or inviting teammates), send the event payload to AutoSend. Either email or contactId identifies the contact:
// When a user creates a workspace in your application:
await fetch("https://api.autosend.com/v1/events/send", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.AUTOSEND_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
eventName: "workspace_created",
email: "sarah@company.com",
eventProperties: {
planName: "Pro Tier",
seatsInvited: 4,
framework: "Next.js"
}
})
});
Note: Event delivery evaluates any active workflow automations whose entry criteria match this event name in a non-blocking, fire-and-forget manner.
2. Configuring the Visual Automation Workflow
Inside your AutoSend dashboard under Automations:
- Entry Trigger: Set the trigger condition to
Event Received→workspace_created. - Branching Logic:
- Branch A (
properties.seatsInvited > 1):- Action: Wait 2 Days → Send Team Collaboration & Permissions Guide
- Branch B (
properties.seatsInvited == 0):- Action: Wait 1 Day → Send How to Invite Your First Teammate
- Branch A (
- Exit Criteria: Define exit rules (e.g., if the user upgrades to Enterprise or deletes their workspace, immediately exit the sequence).
3. Programmatic Automation Creation via API (POST /v1/automations)
You can also provision and activate automation workflows programmatically:
await fetch("https://api.autosend.com/v1/automations", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.AUTOSEND_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
name: "Workspace Activation Sequence",
active: true,
entryCriteria: {
type: "event_received",
eventName: "workspace_created"
},
steps: [
{
type: "wait",
delay: { value: 24, unit: "hours" },
stepId: "step_wait_1",
nextStepId: "step_check_invites"
},
{
type: "email",
email: {
senderEmail: "team@yourdomain.com",
senderName: "Onboarding Team",
templateId: "tpl_welcome_guide"
},
stepId: "step_check_invites"
}
]
})
});