Skip to content

Build a Slack bot

Time to complete: 10 minutes

This guide walks you through building a Slack bot that responds to mentions in channels.

If you just want to send simple Slack messages without interactivity, check out our Slack webhook guide.

  1. Remix this val to get started:
  1. Copy the HTTP endpoint URL (via the … menu for main.tsx) - this is where Slack will send events to your Val Town bot.
  1. Go to Slack API and create a new app From Scratch
  2. Name your app and select your workspace

Create Slack app

In your val’s sidebar, add these Environment Variables:

  • slackVerificationToken: From Settings → Basic Information → Verification Token
  • slackToken: Leave empty (you’ll fill this after installing)

Verification token

  1. Go to Features → Event Subscriptions
  2. Enable events and paste your val’s HTTP endpoint in Request URL
  3. Subscribe to app_mention under Subscribe to bot events

Event subscriptions

In OAuth & Permissions → Scopes, add:

  • app_mentions:read (should already be there)
  • chat:write

Bot scopes

Go to Settings → Install App and install to your workspace.

Install app

  1. Copy the Bot User OAuth Token from OAuth & Permissions
  2. Update your val’s slackToken environment variable

OAuth token

  1. Invite the bot to a channel Invite bot
  2. Mention the bot - it will reply! Bot reply

You can find more Slack examples on our Templates page.