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
@@ -17,23 +17,21 @@ import SupabaseDocsCards from "/snippets/supabase-docs-cards.mdx";
17
17
18
18
Supabase and Trigger.dev can be used together to create powerful workflows triggered by real-time changes in your database tables:
19
19
20
-
The steps in this guide are as follows:
21
-
22
20
- A Supabase Database Webhook triggers an Edge Function when a row including a video URL is inserted into a table
23
21
- The Edge Function triggers a Trigger.dev task, passing the `video_url` column data from the new table row as the payload
24
22
- The Trigger.dev task then:
25
23
- Uses [FFmpeg](https://www.ffmpeg.org/) to extract the audio track from a video URL
26
24
- Uses [Deepgram](https://deepgram.com) to transcribe the extracted audio
27
-
- Updates the original table row in Supabase with the transcription using `update`
25
+
- Updates the original table row using the `record.id`in Supabase with the new transcription using `update`
28
26
29
27
## Prerequisites
30
28
31
29
- Ensure you have the [Supabase CLI](https://supabase.com/docs/guides/cli/getting-started) installed
30
+
- Since Supabase CLI version 1.123.4, you must have [Docker Desktop installed](https://supabase.com/docs/guides/functions/deploy#deploy-your-edge-functions) to deploy Edge Functions
32
31
- Ensure TypeScript is installed
33
32
-[Create a Trigger.dev account](https://cloud.trigger.dev)
34
33
-[Create a new Trigger.dev project](/guides/dashboard/creating-a-project)
35
34
-[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
37
35
38
36
## Initial setup
39
37
@@ -74,124 +72,60 @@ Choose "None" when prompted to install an example task. We will create a new tas
74
72
75
73
</Steps>
76
74
77
-
## Create and deploy a Supabase Edge Function and configure the Database Webhook
78
-
79
-
### Add your Trigger.dev prod secret key to the Supabase dashboard
80
-
81
-
First, go to your Trigger.dev [project dashboard](https://cloud.trigger.dev) and copy the `prod` secret key from the API keys page.
75
+
## Create a new table in your Supabase database
82
76
83
-

77
+
First, in the Supabase project dashboard, you'll need to create a new table to store the video URL and transcription.
84
78
85
-
Then, in [Supabase](https://supabase.com/dashboard/projects), select the project you want to use, navigate to 'Project settings' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />, click 'Edge Functions' <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" /> in the configurations menu, and then click the 'Add new secret' <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" /> button.
79
+
To do this, click on 'Table Editor' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />in the left-hand menu and create a new table. <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />
86
80
87
-
Add `TRIGGER_SECRET_KEY` <Iconicon="circle-4"iconType="solid"size={20}color="A8FF53" /> with the pasted value of your Trigger.dev `prod` secret key.
88
-
89
-

90
-
91
-
### Create a new Edge Function using the Supabase CLI
92
-
93
-
Now create an Edge Function using the Supabase CLI. Call it `video-processing-handler`. This function will be triggered by the Database Webhook.
94
-
95
-
```bash
96
-
supabase functions new video-processing-handler
97
-
```
98
-
99
-
<Note>
100
-
We will replace the code in this function later in the guide, but for now you can leave the
101
-
default code in place.
102
-
</Note>
103
-
104
-
### Deploy the Edge Function
105
-
106
-
Now deploy your new Edge Function with the following command:
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.
113
-
114
-
There will be a link to the dashboard in your terminal output.
115
-
116
-
### Create a new table in your Supabase dashboard
117
-
118
-
Next, in your Supabase dashboard, click on 'Table Editor' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" /> in the left-hand menu and create a new table. <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />
119
-
120
-

81
+

121
82
122
83
Call your table `video_transcriptions`. <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />
123
84
124
85
Add two new columns, one called `video_url` with the type `text` <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />, and another called `transcription`, also with the type `text` <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" />.
125
86
126
-
### Create a new Database Webhook
127
-
128
-
In your Supabase project dashboard, click 'Project settings' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />, then the 'API' tab <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />, and copy the `anon``public` API key from the table <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" />.
87
+

129
88
130
-

89
+
## Create and deploy the Trigger.dev task
131
90
132
-
Then, go to 'Database' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" /> click on 'Webhooks' <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />, and then click 'Create a new hook' <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" />.
91
+
### Generate the Database type definitions
133
92
134
-

93
+
To allow you to use TypeScript to interact with your table, you need to [generate the type definitions](https://supabase.com/docs/guides/api/rest/generating-types) for your Supabase table using the Supabase CLI.
135
94
136
-
<Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" /> Call the hook `edge-function-hook`.
137
-
138
-
<Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" /> Select the new table you have created:
139
-
`public``video_transcriptions`.
140
-
141
-
<Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" /> Choose the `insert` event.
142
-
143
-

144
-
145
-
<Iconicon="circle-4"iconType="solid"size={20}color="A8FF53" /> Under 'Webhook configuration', select
146
-
'Supabase Edge Functions'{""}
147
-
148
-
<Iconicon="circle-5"iconType="solid"size={20}color="A8FF53" /> Under 'Edge Function', choose `POST`
149
-
and select the Edge Function you have created: `video-processing-handler`.{""}
150
-
151
-
<Iconicon="circle-6"iconType="solid"size={20}color="A8FF53" /> Under 'HTTP Headers', add a new header with the key `Authorization` and the value `Bearer <your-api-key>` (replace `<your-api-key>` with the `anon``public` API key you copied earlier).
152
-
153
-
<Info>
154
-
Supabase Edge Functions require a JSON Web Token [JWT](https://supabase.com/docs/guides/auth/jwts)
155
-
in the authorization header. This is to ensure that only authorized users can access your edge

162
-
163
-
Your Database Webhook is now ready to use.
95
+
```bash
96
+
supabase gen types --lang=typescript --project-id <project-ref> --schema public > database.types.ts
97
+
```
164
98
165
-
## Creating and deploying the Trigger.dev task and updating the edge function
99
+
<Note> Replace `<project-ref>` with your Supabase project reference ID. This can be found in your Supabase project settings under 'General'. </Note>
166
100
167
-
### Creating and deploying the Trigger.dev task
101
+
### Create the transcription task
168
102
169
103
Create a new task file in your `/trigger` folder. Call it `videoProcessAndUpdate.ts`.
170
104
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.
105
+
This task takes a video from a public video url, extracts the audio using FFmpeg and transcribes the audio using Deepgram. The transcription summary will then be updated back to the original row in the `video_transcriptions` table in Supabase.
172
106
173
-
#### Generate the Database type definitions for your Supabase table
107
+
You will need to install some additional dependencies for this task:
174
108
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.
109
+
<CodeGroup>
176
110
177
-
```bash
178
-
npx supabase gen types --lang=typescript --project-id "vuzgnncyyceddococcgj" --schema public > database.types.ts
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.
123
+
</CodeGroup>
124
+
125
+
These dependencies will allow you to interact with the Deepgram and Supabase APIs and extract audio from a video using FFmpeg.
192
126
193
127
```ts /trigger/videoProcessAndUpdate.ts
194
-
// Install any missing dependencies below using npm or yarn
### Add your Deepgram and Supabase environment variables to your Trigger.dev project
331
259
332
-
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.
260
+
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 project dashboard.
### Add your Trigger.dev prod secret key to the Supabase dashboard
357
287
358
-
Finally, we need to replace your `video-processing-handler` Edge Function code with the below to trigger the `videoProcessAndUpdate` task when it is called.
288
+
Go to your Trigger.dev [project dashboard](https://cloud.trigger.dev) and copy the `prod` secret key from the API keys page.
289
+
290
+

291
+
292
+
Then, in [Supabase](https://supabase.com/dashboard/projects), select the project you want to use, navigate to 'Project settings' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />, click 'Edge Functions' <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" /> in the configurations menu, and then click the 'Add new secret' <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" /> button.
293
+
294
+
Add `TRIGGER_SECRET_KEY` <Iconicon="circle-4"iconType="solid"size={20}color="A8FF53" /> with the pasted value of your Trigger.dev `prod` secret key.
295
+
296
+

297
+
298
+
### Create a new Edge Function using the Supabase CLI
299
+
300
+
Now create an Edge Function using the Supabase CLI. Call it `video-processing-handler`. This function will be triggered by the Database Webhook.
301
+
302
+
```bash
303
+
supabase functions new video-processing-handler
304
+
```
359
305
360
306
```ts functions/video-processing-handler/index.ts
361
307
// Setup type definitions for built-in Supabase Runtime APIs
@@ -369,11 +315,12 @@ import type { videoProcessAndUpdate } from "../../../src/trigger/videoProcessAnd
369
315
Deno.serve(async (req) => {
370
316
const payload =awaitreq.json();
371
317
372
-
// This payload will contain the video url from the new row in the table
318
+
// This payload will contain the video url and id from the new row in the table
373
319
const videoUrl =payload.record.video_url;
320
+
const id =payload.record.id;
374
321
375
322
// Trigger the videoProcessAndUpdate task with the videoUrl payload
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.
345
+
346
+
There will be a link to the dashboard in your terminal output.
347
+
348
+
## Create the Database Webhook
349
+
350
+
In your Supabase project dashboard, click 'Project settings' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" />, then the 'API' tab <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />, and copy the `anon``public` API key from the table <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" />.
351
+
352
+

353
+
354
+
Then, go to 'Database' <Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" /> click on 'Webhooks' <Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" />, and then click 'Create a new hook' <Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" />.
355
+
356
+

357
+
358
+
<Iconicon="circle-1"iconType="solid"size={20}color="A8FF53" /> Call the hook `edge-function-hook`.
359
+
360
+
<Iconicon="circle-2"iconType="solid"size={20}color="A8FF53" /> Select the new table you have created:
361
+
`public``video_transcriptions`.
362
+
363
+
<Iconicon="circle-3"iconType="solid"size={20}color="A8FF53" /> Choose the `insert` event.
364
+
365
+

366
+
367
+
<Iconicon="circle-4"iconType="solid"size={20}color="A8FF53" /> Under 'Webhook configuration', select
368
+
'Supabase Edge Functions'{""}
369
+
370
+
<Iconicon="circle-5"iconType="solid"size={20}color="A8FF53" /> Under 'Edge Function', choose `POST`
371
+
and select the Edge Function you have created: `video-processing-handler`.{""}
372
+
373
+
<Iconicon="circle-6"iconType="solid"size={20}color="A8FF53" /> Under 'HTTP Headers', add a new header with the key `Authorization` and the value `Bearer <your-api-key>` (replace `<your-api-key>` with the `anon``public` API key you copied earlier).
374
+
375
+
<Info>
376
+
Supabase Edge Functions require a JSON Web Token [JWT](https://supabase.com/docs/guides/auth/jwts)
377
+
in the authorization header. This is to ensure that only authorized users can access your edge

384
+
385
+
Your Database Webhook is now ready to use.
386
+
397
387
## Triggering the entire workflow
398
388
399
389
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.
0 commit comments