Skip to content

Commit 0b1d5a3

Browse files
committed
customer onboarding workflow example
1 parent 0213d98 commit 0b1d5a3

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

docs/migration-n8n.mdx

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ import { task, wait } from "@trigger.dev/sdk";
247247
export const approvalFlow = task({
248248
id: "approval-flow",
249249
run: async (payload: { requestId: string; approverEmail: string }) => {
250-
// create a token this generates a URL the external system can POST to
250+
// create a token, this generates a URL the external system can POST to
251251
const token = await wait.createToken({
252252
timeout: "48h",
253253
tags: [`request-${payload.requestId}`],
@@ -269,3 +269,72 @@ export const approvalFlow = task({
269269
```
270270

271271
---
272+
273+
## Full example: customer onboarding workflow
274+
275+
Here's how a typical back office onboarding workflow translates from n8n to Trigger.dev.
276+
277+
**The n8n setup:** Webhook Trigger → HTTP Request (provision account) → HTTP Request (send welcome email) → HTTP Request (notify Slack) → Wait node (3 days) → HTTP Request (check activation) → IF node → HTTP Request (send follow-up).
278+
279+
**In Trigger.dev**, the same workflow is plain TypeScript:
280+
281+
```ts trigger/onboard-customer.ts
282+
import { task, wait } from "@trigger.dev/sdk";
283+
import { provisionAccount } from "./provision-account";
284+
import { sendWelcomeEmail } from "./send-welcome-email";
285+
286+
export const onboardCustomer = task({
287+
id: "onboard-customer",
288+
retry: {
289+
maxAttempts: 3,
290+
},
291+
run: async (payload: {
292+
customerId: string;
293+
email: string;
294+
plan: "starter" | "pro" | "enterprise";
295+
}) => {
296+
// provision their account, throws if the subtask fails
297+
await provisionAccount
298+
.triggerAndWait({
299+
customerId: payload.customerId,
300+
plan: payload.plan,
301+
})
302+
.unwrap();
303+
304+
// send welcome email
305+
await sendWelcomeEmail
306+
.triggerAndWait({
307+
customerId: payload.customerId,
308+
email: payload.email,
309+
})
310+
.unwrap();
311+
312+
// notify the team
313+
await notifySlack(`New customer: ${payload.email} on ${payload.plan}`);
314+
315+
// wait 3 days, then check if they've activated
316+
await wait.for({ days: 3 });
317+
318+
const activated = await checkActivation(payload.customerId);
319+
if (!activated) {
320+
await sendActivationNudge(payload.email);
321+
}
322+
323+
return { customerId: payload.customerId, activated };
324+
},
325+
});
326+
```
327+
328+
Trigger the workflow from your app when a new customer signs up:
329+
330+
```ts
331+
import { onboardCustomer } from "@/trigger/onboard-customer";
332+
333+
await onboardCustomer.trigger({
334+
customerId: customer.id,
335+
email: customer.email,
336+
plan: customer.plan,
337+
});
338+
```
339+
340+
Every run is visible in the Trigger.dev dashboard with full logs, retry history, and the ability to replay any run.

0 commit comments

Comments
 (0)