You can build a Slack bot using vals.

Vals can receive events from Slack’s Events API via the Express API. In this guide, you’ll build a bot that replies whenever it’s mentioned.

Screenshot 2023-06-28 at 09.21.24.png

1. Create a Slack app

Visit https://api.slack.com/apps?new_app=1, create a new app From Scratch, and choose your App Name and your workspace.

Screenshot 2023-06-27 at 07.05.40.png

2. Save your app’s verification token

When your handler val receives requests, you can verify that they were sent by Slack by looking for the verification token.

To find your app’s verification token, go to SettingsBasic Information in the side bar. Scroll down to App Credentials.

Screenshot 2023-06-27 at 13.29.51.png

Save the Verification Token as a Val Town secret as slackVerificationToken.

3. Create a val that will respond to the challenge and reply when it’s mentioned

When you add a Request URL, Slack will immediately send a challenge to verify the endpoint is correct.

Fork this val that responds to the challenge, and replies to app_mention events.

https://www.val.town/embed/neverstew.slackReplyToMessage

4. Set up event subscriptions

On your forked val, copy the Web endpoint via the menu at Endpoints > Copy web endpoint.

Back on Slack, navigate to the Event Subscription page. It’s under Features in the side bar.

Toggle on Enable Events, and paste your endpoint in the Request URL field.

Screenshot 2023-06-28 at 11.15.06.png