117 lines
3.2 KiB
Plaintext
117 lines
3.2 KiB
Plaintext
---
|
|
title: "Resend"
|
|
sidebarTitle: "Resend"
|
|
description: "Here are some example workflows you could create using the Resend integration."
|
|
---
|
|
|
|
<Tip>
|
|
Resend.com is currently in private beta but you can request early access [here](https://resend.com/).
|
|
</Tip>
|
|
|
|
To use the Resend integration you must first install the required packages:
|
|
|
|
<Tabs>
|
|
<Tab title="npm">
|
|
|
|
```bash
|
|
npm install @trigger.dev/resend
|
|
```
|
|
|
|
</Tab>
|
|
<Tab title="pnpm">
|
|
|
|
```bash
|
|
pnpm install @trigger.dev/resend
|
|
```
|
|
|
|
</Tab>
|
|
<Tab title="yarn">
|
|
|
|
```bash
|
|
yarn add @trigger.dev/resend
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
## Welcome email drip campaign
|
|
|
|
This workflow will get triggered and a Slack notification and welcom email will be sent straight away.
|
|
1 day later we check if the user has completed onboarding, if they have, they get a 'tips' email, otherwise they get a re-engagement email.
|
|
|
|
Integrations required: Resend, Slack
|
|
|
|
```ts
|
|
import { customEvent, Trigger, sendEvent } from "@trigger.dev/sdk";
|
|
import * as resend from "@trigger.dev/resend";
|
|
import * as slack from "@trigger.dev/slack";
|
|
import React from "react";
|
|
import { z } from "zod";
|
|
import { getUser } from "../db";
|
|
import { InactiveEmail, TipsEmail, WelcomeEmail } from "./email-templates";
|
|
|
|
new Trigger({
|
|
id: "welcome-email-campaign",
|
|
name: "Welcome email drip campaign",
|
|
apiKey: "<my_api_key>",
|
|
on: customEvent({
|
|
name: "user.created",
|
|
schema: z.object({
|
|
userId: z.string(),
|
|
}),
|
|
}),
|
|
async run(event, context) {
|
|
//get the user data from the database
|
|
const user = await getUser(event.userId);
|
|
|
|
await slack.postMessage("send-to-slack", {
|
|
channelName: "new-users",
|
|
text: `New user signed up: ${user.name} (${user.email})`,
|
|
});
|
|
|
|
//Send the first email
|
|
const welcomeResponse = await resend.sendEmail("welcome-email", {
|
|
from: "Trigger.dev <james@email.trigger.dev>",
|
|
replyTo: "James <james@trigger.dev>",
|
|
to: user.email,
|
|
subject: "Welcome to Trigger.dev",
|
|
react: <WelcomeEmail name={user.name} />,
|
|
});
|
|
await context.logger.debug(
|
|
`Sent welcome email to ${welcomeResponse.to} with id ${welcomeResponse.id}`
|
|
);
|
|
|
|
//wait 1 day, check if the user has created a workflow and send the appropriate email
|
|
await context.waitFor("wait-a-while", { days: 1 });
|
|
const updatedUser = await getUser(event.userId);
|
|
|
|
if (updatedUser.hasOnboarded) {
|
|
await resend.sendEmail("onboarding-complete", {
|
|
from: "Trigger.dev <james@email.trigger.dev>",
|
|
replyTo: "James <james@trigger.dev>",
|
|
to: updatedUser.email,
|
|
subject: "Pro tips for workflows",
|
|
react: <TipsEmail name={updatedUser.name} />,
|
|
});
|
|
} else {
|
|
await resend.sendEmail("onboarding-incomplete", {
|
|
from: "Trigger.dev <james@email.trigger.dev>",
|
|
replyTo: "James <james@trigger.dev>",
|
|
to: updatedUser.email,
|
|
subject: "Help with your first workflow",
|
|
react: <InactiveEmail name={updatedUser.name} />,
|
|
});
|
|
}
|
|
},
|
|
}).listen();
|
|
```
|
|
|
|
<iframe
|
|
width="100%"
|
|
height="440"
|
|
src="https://www.youtube.com/embed/aFlwD0frvnQ?rel=0"
|
|
title="YouTube video player"
|
|
frameborder="0"
|
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
|
allowfullscreen
|
|
></iframe> |