Slack Bot Mention Edge Function
The Slack Bot Mention Edge Function allows you to process mentions in Slack and respond accordingly.
For your bot to seamlessly interact with Slack, you'll need to configure Slack Apps:
- Navigate to the Slack Apps page.
- Under "Event Subscriptions," add the URL of the
slack-bot-mention
function and click to verify the URL.
- The Edge function will respond, confirming that everything is set up correctly.
- Add
app-mention
in the events the bot will subscribe to.
Deploy the following code as an Edge function using the CLI:
_10supabase --project-ref nacho_slacker secrets \
_10set SLACK_TOKEN=<xoxb-0000000000-0000000000-01010101010nacho101010>
Here's the code of the Edge Function, you can change the response to handle the text received:
_35import { serve } from 'https://deno.land/std@0.197.0/http/server.ts'
_35import { WebClient } from 'https://deno.land/x/slack_web_api@6.7.2/mod.js'
_35const slackBotToken = Deno.env.get('SLACK_TOKEN') ?? ''
_35const botClient = new WebClient(slackBotToken)
_35console.log(`Slack URL verification function up and running!`)
_35serve(async (req) => {
_35 const reqBody = await req.json()
_35 console.log(JSON.stringify(reqBody, null, 2))
_35 const { token, challenge, type, event } = reqBody
_35 if (type == 'url_verification') {
_35 return new Response(JSON.stringify({ challenge }), {
_35 headers: { 'Content-Type': 'application/json' },
_35 } else if (event.type == 'app_mention') {
_35 const { user, text, channel, ts } = event
_35 // Here you should process the text received and return a response:
_35 const response = await botClient.chat.postMessage({
_35 text: `Hello <@${user}>!`,
_35 return new Response('ok', { status: 200 })
_35 return new Response(JSON.stringify({ error: error.message }), {
_35 headers: { 'Content-Type': 'application/json' },