Skip to content

Commit 7062b8a

Browse files
committed
more updates
1 parent ed3f8c6 commit 7062b8a

File tree

1 file changed

+68
-40
lines changed

1 file changed

+68
-40
lines changed

docs/guides/frameworks/supabase-edge-functions-ffmpeg-deepgram.mdx

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ description: "This guide shows you how to trigger a task when a row is added to
66

77
import Prerequisites from "/snippets/framework-prerequisites.mdx";
88
import SupabasePrerequisites from "/snippets/supabase-prerequisites.mdx";
9-
import CliInitStep from "/snippets/step-cli-init.mdx";
109
import UsefulNextSteps from "/snippets/useful-next-steps.mdx";
1110
import TriggerTaskNextjs from "/snippets/trigger-tasks-nextjs.mdx";
1211
import NextjsTroubleshootingMissingApiKey from "/snippets/nextjs-missing-api-key.mdx";
@@ -16,20 +15,16 @@ import SupabaseDocsCards from "/snippets/supabase-docs-cards.mdx";
1615

1716
## Overview
1817

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:
2019

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:
2221

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`
3328

3429
## Prerequisites
3530

@@ -38,12 +33,45 @@ The Edge Function triggers a deployed Trigger.dev task which takes a payload fro
3833
- [Create a Trigger.dev account](https://cloud.trigger.dev)
3934
- [Create a new Trigger.dev project](/guides/dashboard/creating-a-project)
4035
- [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
4137

4238
## Initial setup
4339

4440
<Steps>
4541
<SupabasePrerequisites />
46-
<CliInitStep />
42+
<Step title="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+
4775
</Steps>
4876

4977
## 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
6896
supabase functions new video-processing-handler
6997
```
7098

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
75-
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
76-
77-
// Sets up a Deno server that listens for incoming JSON requests
78-
Deno.serve(async (req) => {
79-
const payload = await req.json();
80-
81-
return new Response("ok");
82-
});
83-
```
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>
84103

85104
### Deploy the Edge Function
86105

@@ -92,11 +111,7 @@ supabase functions deploy video-processing-handler
92111

93112
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.
94113

95-
There will be a link to the dashboard in your terminal output, or you can find it at this URL:
96-
97-
`https://supabase.com/dashboard/project/<your-project-id>/functions`
98-
99-
<Note>Replace `<your-project-id>` with your actual project ID.</Note>
114+
There will be a link to the dashboard in your terminal output.
100115

101116
### Create a new table in your Supabase dashboard
102117

@@ -151,7 +166,7 @@ Your Database Webhook is now ready to use.
151166

152167
### Creating and deploying the Trigger.dev task
153168

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`.
155170

156171
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.
157172

@@ -160,13 +175,21 @@ This task with take a video from a public video url, extract the audio using FFm
160175
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.
161176

162177
```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
164179
```
165180

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>
167182

168183
#### Create the transcription task
169184

185+
You will need to install some additional dependencies for this task:
186+
187+
```bash
188+
npm install @deepgram/sdk @supabase/supabase-js fluent-ffmpeg node-fetch
189+
```
190+
191+
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+
170193
```ts /trigger/videoProcessAndUpdate.ts
171194
// Install any missing dependencies below using npm or yarn
172195
import { createClient as createDeepgramClient } from "@deepgram/sdk";
@@ -276,13 +299,15 @@ export const videoProcessAndUpdate = task({
276299
Before you can deploy the task, you'll need to add the FFmpeg build extension to your `trigger.config.ts` file.
277300

278301
```ts trigger.config.ts
302+
// Add this import
279303
import { ffmpeg } from "@trigger.dev/build/extensions/core";
280304
import { defineConfig } from "@trigger.dev/sdk/v3";
281305

282306
export default defineConfig({
283307
project: "<project ref>", // Replace with your project ref
284308
// Your other config settings...
285309
build: {
310+
// Add the FFmpeg build extension
286311
extensions: [ffmpeg()],
287312
},
288313
});
@@ -301,7 +326,7 @@ export default defineConfig({
301326

302327
### Add your Deepgram and Supabase environment variables to your Trigger.dev project
303328

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.
305330

306331
![Adding environment variables](/images/environment-variables-page.jpg)
307332

@@ -333,7 +358,10 @@ Finally, we need to replace your `video-processing-handler` Edge Function code w
333358
// Setup type definitions for built-in Supabase Runtime APIs
334359
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
335360
// 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.
336-
import { tasks } from "npm:@trigger.dev/<your-sdk-version>/v3";
361+
import { tasks } from "npm:@trigger.dev/@sdk<your-sdk-version>/v3";
362+
// Import the videoProcessAndUpdate task from the trigger folder
363+
import type { videoProcessAndUpdate } from "../../../src/trigger/videoProcessAndUpdate.ts";
364+
// 👆 type only import
337365

338366
// Sets up a Deno server that listens for incoming JSON requests
339367
Deno.serve(async (req) => {
@@ -358,13 +386,13 @@ Deno.serve(async (req) => {
358386

359387
#### Redeploy the Edge Function
360388

361-
Now your Edge function has been update you will need to redeploy it to Supabase.
389+
Now your Edge function has been update you will need to redeploy it using the Supabase CLI.
362390

363391
```bash
364392
supabase functions deploy video-processing-handler
365393
```
366394

367-
## Triggering the task
395+
## Triggering the entire workflow
368396

369397
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.
370398

@@ -374,7 +402,7 @@ To do this, go back to your Supabase project dashboard, click on 'Table Editor'
374402

375403
Add a new item under `video_url`, with a public video url. <Icon icon="circle-1" iconType="solid" size={20} color="A8FF53" />.
376404

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`.
378406

379407
![How to insert a new row 2](/images/supabase-new-table-4.png)
380408

0 commit comments

Comments
 (0)