The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Update functions.mdx (#18332)
Rodrigo Martins Mansueli46293ce5e7d7
diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.tsindex 59475233574..d92267b6b1d 100644--- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts+++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.constants.ts@@ -898,6 +898,10 @@ export const functions: NavMenuConstant = {name: 'Taking Screenshots with Puppeteer',url: '/guides/functions/examples/screenshots',},+ {+ name: 'Slack Bot responding to mentions',+ url: '/guides/functions/examples/slack-bot-mention',+ },],},],diff --git a/apps/docs/pages/guides/functions.mdx b/apps/docs/pages/guides/functions.mdxindex a970ce2c83c..fac7f46f90f 100644--- a/apps/docs/pages/guides/functions.mdx+++ b/apps/docs/pages/guides/functions.mdx@@ -168,6 +168,11 @@ export const examples = [description: `Rate Limiting Edge Functions with Upstash Redis.`,href: '/guides/functions/examples/rate-limiting',},+ {+ name: 'Slack Bot Mention Edge Function',+ description: `Slack Bot handling Slack mentions in Edge Function`,+ href: '/guides/functions/examples/slack-bot-mention',+ },]export const Page = ({ children }) => <Layout meta={meta} children={children} hideToc={true} />diff --git a/apps/docs/pages/guides/functions/examples/slack-bot-mention.mdx b/apps/docs/pages/guides/functions/examples/slack-bot-mention.mdxnew file mode 100644index 00000000000..cb1486f98b9--- /dev/null+++ b/apps/docs/pages/guides/functions/examples/slack-bot-mention.mdx@@ -0,0 +1,71 @@+import Layout from '~/layouts/DefaultGuideLayout'++export const meta = {+ id: 'slack-bot-mention',+ title: 'Slack Bot Mention Edge Function',+ description: 'Building a Slack Bot that Handles Mentions.',+}++The Slack Bot Mention Edge Function allows you to process mentions in Slack and respond accordingly.++## Configuring Slack Apps++For your bot to seamlessly interact with Slack, you'll need to configure Slack Apps:++1. Navigate to the Slack Apps page.+1. Under "Event Subscriptions," add the URL of the `slack-bot-mention` function and click to verify the URL.+1. The Edge function will respond, confirming that everything is set up correctly.+1. Add `app-mention` in the events the bot will subscribe to.++## Creating the Edge Function++Deploy the following code as an Edge function using the CLI:++```bash+supabase --project-ref nacho_slacker secrets \+set SLACK_TOKEN=<xoxb-0000000000-0000000000-01010101010nacho101010>+```++Here's the code of the Edge Function, you can change the response to handle the text received:++```ts index.ts+import { serve } from 'https://deno.land/[email protected]/http/server.ts'+import { WebClient } from 'https://deno.land/x/[email protected]/mod.js'++const slackBotToken = Deno.env.get('SLACK_TOKEN') ?? ''+const botClient = new WebClient(slackBotToken)++console.log(`Slack URL verification function up and running!`)+serve(async (req) => {+ try {+ const reqBody = await req.json()+ console.log(JSON.stringify(reqBody, null, 2))+ const { token, challenge, type, event } = reqBody++ if (type == 'url_verification') {+ return new Response(JSON.stringify({ challenge }), {+ headers: { 'Content-Type': 'application/json' },+ status: 200,+ })+ } else if (event.type == 'app_mention') {+ const { user, text, channel, ts } = event+ // Here you should process the text received and return a response:+ const response = await botClient.chat.postMessage({+ channel: channel,+ text: `Hello <@${user}>!`,+ thread_ts: ts,+ })+ return new Response('ok', { status: 200 })+ }+ } catch (error) {+ return new Response(JSON.stringify({ error: error.message }), {+ headers: { 'Content-Type': 'application/json' },+ status: 500,+ })+ }+})+```++export const Page = ({ children }) => <Layout meta={meta} children={children} />++export default Page