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:
_34import { WebClient } from 'https://deno.land/x/slack_web_api@6.7.2/mod.js'
_34const slackBotToken = Deno.env.get('SLACK_TOKEN') ?? ''
_34const botClient = new WebClient(slackBotToken)
_34console.log(`Slack URL verification function up and running!`)
_34Deno.serve(async (req) => {
_34 const reqBody = await req.json()
_34 console.log(JSON.stringify(reqBody, null, 2))
_34 const { token, challenge, type, event } = reqBody
_34 if (type == 'url_verification') {
_34 return new Response(JSON.stringify({ challenge }), {
_34 headers: { 'Content-Type': 'application/json' },
_34 } else if (event.type == 'app_mention') {
_34 const { user, text, channel, ts } = event
_34 // Here you should process the text received and return a response:
_34 const response = await botClient.chat.postMessage({
_34 text: `Hello <@${user}>!`,
_34 return new Response('ok', { status: 200 })
_34 return new Response(JSON.stringify({ error: error.message }), {
_34 headers: { 'Content-Type': 'application/json' },