Create a slack channel in your workspace where the notifications will be displayed (ex. “notifications”)
Visit the Slack API webpage and “Create New App”. Give the app a name and select the Slack workspace you’re working with.
Select “Incoming Webhooks” and flip the “Active Incoming Webhooks” switch on.
Add New Webhook to Workspace and select the “notifications” channel you created before.
Copy the new Webhook URL:
https://hooks.slack.com/services/T063WTUDTK9/B06FGB5RVGX/TBno97298ba9RobFq4jZD2
Instructions can be found at Edge Functions -> Deploy a new function
supabase functions new notify_signup
This creates a function in the supabase/functions/
folder.
In the supabase
folder, add a .env
file with your Slack webhook URL:
SLACK_WEBHOOK_URL="{YOUR WEBHOOK URL}"
Add the following code to the new index.ts
:
Deno.serve(async (req) => {
const { record } = await req.json();
console.log("user", record)
var slackWebhookUrl = Deno.env.get("SLACK_WEBHOOK_URL");
const slackMessage = {
text: `New user signed up: ${record.email}`,
}
const slackResponse = await fetch(slackWebhookUrl, {
method: "POST",
body: JSON.stringify(slackMessage),
})
return new Response(
JSON.stringify(record),
{ headers: { "Content-Type": "application/json" } },
)
})
To deploy the function, run Docker Desktop and then execute this command
supabase functions deploy notify_signup --project-ref kpdchozrvelpbtklvgua
You should now see your function in the Edge Functions section of the Supabase dashboard:
Create Supabase webhook under database -> webhooks
Select Supabase Edge Functions as the Type
and select the edge function you just created in the “Edge Function” section:
Also add an authorization header to the webhook using the dropdown under “HTTP Headers”. If you do not do this and your edge function requires JWT authentication (the default), the function will not be called.