Skip to content

Commit 2626d18

Browse files
committed
First draft of the Getting started guide
1 parent b35591b commit 2626d18

2 files changed

Lines changed: 198 additions & 6 deletions

File tree

apps/docs/getting-started.mdx

Lines changed: 198 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,206 @@
11
---
22
title: "Getting started with Trigger.dev"
3-
sidebarTitle: "Quick-start"
4-
description: "Trigger.dev quick-start guide"
3+
sidebarTitle: "Quick start"
4+
description: "Get your first workflow running in just a few minutes"
55
---
66

7+
Trigger.dev workflows are written in your codebase and run in your existing infrastructure. This means:
8+
9+
- They are version controlled with the rest of your code.
10+
- They run locally and don't require you to use tunnels
11+
12+
<Note>
13+
Currently we require you to have a long-running Node.js server, e.g. Express.
14+
Support for serverless is coming soon.
15+
</Note>
16+
17+
## 1. Installing @trigger.dev packages
18+
19+
In your existing project install the packages:
20+
21+
<Tabs>
22+
<Tab title="npm">
23+
24+
```bash
25+
npm install @trigger.dev/sdk @trigger.dev/integrations
26+
```
27+
28+
</Tab>
29+
<Tab title="pnpm">
30+
31+
```bash
32+
pnpm install @trigger.dev/sdk @trigger.dev/integrations
33+
```
34+
35+
</Tab>
36+
<Tab title="yarn">
37+
38+
```bash
39+
yarn add @trigger.dev/sdk @trigger.dev/integrations
40+
```
41+
42+
</Tab>
43+
</Tabs>
44+
45+
What do the packages do?
46+
47+
- `@trigger.dev/sdk` is required to use Trigger.dev, it allows you to run workflows
48+
- `@trigger.dev/integrations` allows you to easily subscribe to webhooks and use API calls from popular services
49+
50+
## 2. Sign in to your Trigger.dev dashboard
51+
52+
Go to [trigger.dev](https://app.trigger.dev) and sign up or login to your account.
53+
54+
## 3. Get your API keys
55+
56+
In the bottom-left corner of an Organization page you can find your API keys.
57+
![API Keys](/images/api-keys.png)
58+
59+
## 4. Creating your first workflow
60+
61+
Workflows are triggered by events. In this example, we have defined a custom event called `user.created`. We support many different types of events including webhooks, scheduled, and more coming soon.
62+
63+
```ts first-workflow.ts
64+
import { Trigger, customEvent } from "@trigger.dev/sdk";
65+
import { slack } from "@trigger.dev/integrations";
66+
67+
const postMessage = new Trigger({
68+
id: "new-user",
69+
name: "New user slack message",
70+
apiKey: "<your_api_key>",
71+
logLevel: "info",
72+
on: customEvent({
73+
name: "user.created",
74+
schema: z.object({
75+
name: z.string(),
76+
email: z.string(),
77+
paidPlan: z.boolean(),
78+
}),
79+
}),
80+
run: async (event, ctx) => {
81+
await ctx.logger.info("This log will appear on the Trigger.dev run page");
82+
83+
//send a message to the #new-users Slack channel with user details
84+
const response = await slack.postMessage("send-to-slack", {
85+
channel: "new-users",
86+
text: `New user: ${event.name} (${event.email}) signed up. ${
87+
paidPlan ? "They are paying" : "They are on the free plan"
88+
}.`,
89+
});
90+
91+
return response.message;
92+
},
93+
});
94+
95+
//this workflow will now connect and start listening for events
96+
postMessage.listen();
97+
```
98+
99+
You'll notice that when we subscribe to the custom event we have to say the name of the event and provide a schema. Schemas are created using Zod. In this case events must send an object that has name, email, and paidPlan. If the event is triggered with an object that doesn't match this schema, the workflow won't run.
100+
7101
<Note>
8-
Welcome to the Trigger.dev. Follow this quick-start guide to get up and
9-
running.
102+
Above we set the API key inside the Trigger object. We recommend instead that
103+
you add an environment variable called `TRIGGER_API_KEY`. That way you can use
104+
your development API key locally and the production one when you deploy.
10105
</Note>
11106

12-
## Creating your first workflow
107+
## 6. Run your web server
108+
109+
Run your server how you normally would, e.g. `npm run dev`. This will connect your workflow to Trigger.dev, so we can start sending you events. You should see some log messages in your server console (tip: you can turn these off by removing the `logLevel: "info"` from the code above).
110+
111+
## 5. Testing your workflow from the dashboard
112+
113+
Now that the workflow is connected to Trigger.dev we need to trigger it. You can easily test your workflow from [your Trigger.dev dashboard](https://app.trigger.dev).
114+
115+
On the organization page you should see that the Workflow has now appeared (you may need to refresh the page from last time).
116+
117+
//TODO: Image of Org page with a single workflow called "New user slack message"
118+
119+
Move to the "New user slack message" and you will see the workflow page. There have been no runs yet.
120+
121+
Move to the "Test" page and input a valid test event, remember the workflow expects a name, email and paidPlan. You can copy this:
122+
123+
```json
124+
{
125+
"name": "Rick Astley",
126+
"email": "nevergonn@giveyou.up",
127+
"paidPlan": true
128+
}
129+
```
130+
131+
Hit the "Test" button and it will take us to our first run 🚀!
132+
133+
## 6. The run page
134+
135+
All of the steps in a workflow, including the initial event, can be viewed in detail. You will need to refresh the page if it's running to see it move between steps.
136+
137+
But there's a problem, we've used Slack in our code and we haven't authenticated.
138+
139+
## 7. Authenticating with Slack
140+
141+
When a workflow step uses an API integration that you haven't already authenticated with, it will pause until you've authenticated.
142+
143+
Simply click the "Connect with Slack" button and sign-in with your desired Slack workspace. As soon as you do, the workflow will pick up where it left off.
144+
145+
Test complete!
146+
147+
## 8. Triggering this workflow from code
148+
149+
As this workflow uses a custom event, we need to manually trigger it from our code. Anywhere in your code you can do this:
150+
151+
```ts
152+
import { sendEvent } from "@trigger.dev/sdk";
153+
154+
/*
155+
...your other code
156+
*/
157+
158+
await sendEvent({
159+
apiKey: "<my_api_key>",
160+
event: {
161+
name: "Eleven",
162+
email: "jane@hawksmoorhigh.edu",
163+
paidPlan: true,
164+
},
165+
});
166+
```
167+
168+
When you run your server and this code executes, it will trigger the workflow. You will see this in the run list on your workflow page.
169+
170+
## Next steps
171+
172+
There are many things we didn't cover here, including Webhook and Scheduled triggers.
173+
174+
### Triggers
175+
176+
Triggers are what cause your workflows to run.
177+
178+
<CardGroup>
179+
<Card title="Webhooks" icon="rectangle-terminal" href="/triggers/webhooks">
180+
Easily subscribe to the APIs you're using
181+
</Card>
182+
<Card title="Scheduled" icon="sliders" href="/triggers/scheduled">
183+
Trigger your workflows on a repeating schedule
184+
</Card>
185+
<Card title="Custom events" icon="heading" href="/triggers/custom">
186+
More details on custom events
187+
</Card>
188+
<Card title="More coming soon" icon="heading">
189+
On received email, HTTP endpoint and AWS Event Bridge
190+
</Card>
191+
</CardGroup>
192+
193+
### Functions
13194

14-
Coming soon...
195+
<CardGroup>
196+
<Card title="API integrations" icon="rectangle-terminal" href="/integrations">
197+
We are making it easy to use lots of APIs by adding integrations.
198+
</Card>
199+
<Card title="Delays" icon="sliders" href="/functions/delays">
200+
Add delays to your workflows. They're resilient so it doesn't matter if your
201+
server goes down.
202+
</Card>
203+
<Card title="Send event" icon="heading" href="/functions/send">
204+
Send a custom event from a function, to trigger another function 🤯
205+
</Card>
206+
</CardGroup>

apps/docs/images/api-keys.png

2.23 MB
Loading

0 commit comments

Comments
 (0)