You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,20 +15,16 @@ import SupabaseDocsCards from "/snippets/supabase-docs-cards.mdx";
16
15
17
16
## Overview
18
17
19
-
This workflow generates a transcription from a video URL and updates a table in a database, using [Supabase](https://supabase.com), [FFmpeg](https://www.ffmpeg.org/) and [Deepgram](https://deepgram.com) and Trigger.dev.
18
+
Supabase and Trigger.dev can be used together to create powerful workflows triggered by real-time changes in your database tables:
20
19
21
-
You will learn how to set up and deploy a Supabase Edge Function that is triggered by an `insert` row action in a table via a Database Webhook.
20
+
The steps in this guide are as follows:
22
21
23
-
The Edge Function triggers a deployed Trigger.dev task which takes a payload from the new inserted data from the table. This is then processed using FFmpeg and Deepgram. The resulting string is then `updated` back into the original table row in Supabase.
24
-
25
-
### Key features
26
-
27
-
- Configuring a Supabase Database Webhook which triggers an Edge Function on an `insert` action on a table
28
-
- A Supabase Edge Function that triggers a Trigger.dev task, which uses the data from the `video_url` column as the payload.
29
-
- A multi-step Trigger.dev task example which:
30
-
- Uses FFmpeg to extract the audio track from a public video URL
31
-
- Uses Deepgram to transcribe the audio
32
-
- Adds the transcription back to your Supabase table in the correct row, using `update`
22
+
- A Supabase Database Webhook triggers an Edge Function when a row including a video URL is inserted into a table
23
+
- The Edge Function triggers a Trigger.dev task, passing the `video_url` column data from the new table row as the payload
24
+
- The Trigger.dev task then:
25
+
- Uses [FFmpeg](https://www.ffmpeg.org/) to extract the audio track from a video URL
26
+
- Uses [Deepgram](https://deepgram.com) to transcribe the extracted audio
27
+
- Updates the original table row in Supabase with the transcription using `update`
33
28
34
29
## Prerequisites
35
30
@@ -38,12 +33,45 @@ The Edge Function triggers a deployed Trigger.dev task which takes a payload fro
38
33
-[Create a Trigger.dev account](https://cloud.trigger.dev)
39
34
-[Create a new Trigger.dev project](/guides/dashboard/creating-a-project)
40
35
-[Create a new Deepgram account](https://deepgram.com/) and get your API key from the dashboard
36
+
-[Docker](https://docs.docker.com/get-docker/) installed and runningon your machine
41
37
42
38
## Initial setup
43
39
44
40
<Steps>
45
41
<SupabasePrerequisites />
46
-
<CliInitStep />
42
+
<Steptitle="Run the CLI `init` command">
43
+
44
+
The easiest way to get started is to use the CLI. It will add Trigger.dev to your existing project, create a `/trigger` folder and give you an example task.
45
+
46
+
Run this command in the root of your project to get started:
47
+
48
+
<CodeGroup>
49
+
50
+
```bash npm
51
+
npx trigger.dev@latest init
52
+
```
53
+
54
+
```bash pnpm
55
+
pnpm dlx trigger.dev@latest init
56
+
```
57
+
58
+
```bash yarn
59
+
yarn dlx trigger.dev@latest init
60
+
```
61
+
62
+
</CodeGroup>
63
+
64
+
It will do a few things:
65
+
66
+
1. Log you into the CLI if you're not already logged in.
67
+
2. Create a `trigger.config.ts` file in the root of your project.
68
+
3. Ask where you'd like to create the `/trigger` directory.
69
+
4. Create the `/trigger` directory with an example task, `/trigger/example.[ts/js]`.
70
+
71
+
Choose "None" when prompted to install an example task. We will create a new task for this guide.
72
+
73
+
</Step>
74
+
47
75
</Steps>
48
76
49
77
## Create and deploy a Supabase Edge Function and configure the Database Webhook
@@ -68,19 +96,10 @@ Now create an Edge Function using the Supabase CLI. Call it `video-processing-ha
68
96
supabase functions new video-processing-handler
69
97
```
70
98
71
-
Replace the `video-processing-handler` placeholder code with the following code:
72
-
73
-
```ts functions/video-processing-handler/index.ts
74
-
// Setup type definitions for built-in Supabase Runtime APIs
Follow the CLI instructions, selecting the same project you added your `prod` secret key to, and once complete you should see your new Edge Function deployment in your Supabase Edge Functions dashboard.
94
113
95
-
There will be a link to the dashboard in your terminal output, or you can find it at this URL:
<Note>Replace `<your-project-id>` with your actual project ID.</Note>
114
+
There will be a link to the dashboard in your terminal output.
100
115
101
116
### Create a new table in your Supabase dashboard
102
117
@@ -151,7 +166,7 @@ Your Database Webhook is now ready to use.
151
166
152
167
### Creating and deploying the Trigger.dev task
153
168
154
-
Create a new task file in your `/trigger` folder (the same place your 'Hello World' task was created). Call it `videoProcessAndUpdate.ts`.
169
+
Create a new task file in your `/trigger` folder. Call it `videoProcessAndUpdate.ts`.
155
170
156
171
This task with take a video from a public video url, extract the audio using FFmpeg and transcribe the audio using Deepgram. The transcription summary will then be added back to the original row in the `video_transcriptions` table in Supabase.
157
172
@@ -160,13 +175,21 @@ This task with take a video from a public video url, extract the audio using FFm
160
175
First, you need to [generate the type definitions](https://supabase.com/docs/guides/api/rest/generating-types) for your Supabase table using the Supabase CLI. This will allow you to use TypeScript to interact with your table.
161
176
162
177
```bash
163
-
npx supabase generate types --project-url <your-project-url> --project-key <your-anon-key> --schema public
178
+
npx supabase gen types --lang=typescript --project-id "vuzgnncyyceddococcgj" --schema public> database.types.ts
164
179
```
165
180
166
-
<Note> Replace `<your-project-url>` with your Supabase project URL and `<your-anon-key>` with your `anon``public` API key. </Note>
181
+
<Note> Replace `<project-ref>` with your Supabase project reference ID. This can be found in your Supabase project settings under 'General'. </Note>
167
182
168
183
#### Create the transcription task
169
184
185
+
You will need to install some additional dependencies for this task:
These dependencies will allow you to interact with the Deepgram and Supabase APIs, extract audio from a video using FFmpeg, and fetch the video from a URL.
192
+
170
193
```ts /trigger/videoProcessAndUpdate.ts
171
194
// Install any missing dependencies below using npm or yarn
project: "<project ref>", // Replace with your project ref
284
308
// Your other config settings...
285
309
build: {
310
+
// Add the FFmpeg build extension
286
311
extensions: [ffmpeg()],
287
312
},
288
313
});
@@ -301,7 +326,7 @@ export default defineConfig({
301
326
302
327
### Add your Deepgram and Supabase environment variables to your Trigger.dev project
303
328
304
-
You will need to add your `DEEPGRAM_SECRET_KEY`, `SUPABASE_PROJECT_URL` and `SUPABASE_SERVICE_ROLE_KEY` as environment variables in your Trigger.dev project. This can be found in the 'Environment Variables' page in your Trigger.dev project dashboard.
329
+
You will need to add your `DEEPGRAM_SECRET_KEY`, `SUPABASE_PROJECT_URL` and `SUPABASE_SERVICE_ROLE_KEY` as environment variables in your Trigger.dev project. This can be done in the 'Environment Variables' page in your Trigger.dev project dashboard.
// Import the Trigger.dev SDK - replace "<your-sdk-version>" with the version of the SDK you are using, e.g. "3.0.0". You can find this in your package.json file.
Your `video-processing-handler` Edge Function is now set up to trigger the `videoProcessAndUpdate` task every time a new row is inserted into your `video_transcriptions` table.
370
398
@@ -374,7 +402,7 @@ To do this, go back to your Supabase project dashboard, click on 'Table Editor'
374
402
375
403
Add a new item under `video_url`, with a public video url. <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />.
376
404
377
-
You can use the following public video URL for testing: `https://dpgr.am/spacewalk.wav`.
405
+
You can use the following public video URL for testing: `https://content.trigger.dev/Supabase%20Edge%20Functions%20Quickstart.mp4`.
378
406
379
407

0 commit comments