Example project on how to integrate Slack's Bolt Java SDK with http4s
.
Disclaimer: I am no expert, but I hope this helps you out.
The scope:
- Handling slack slash command to open new views (
view.open
). - Handle view submissions, including parsing the view's state and answering back:
- Positively if the values in the form are valid.
- Negatively if the values in the form are invalid and feedback to the user is sent using a DM.
- Send IM messages containing actions.
- Handle block actions events and respond accordingly.
Local install:
sbt
- JDK 17
- ngrok
Install a Slack App (https://api.slack.com/start/quickstart):
- Create an App and enter its settings.
- Setup a Bot Token Scopes under "OAuth & Permissions":
chat:write
commands
to support slash/
commands
- Create a slash command, for example,
/interactive-form
. Leave the link empty for now. - Go to "Interactivity & Shortcuts" and enable it. Leave the link empty for now.
- Go to
Install App
and install to a workspace of your choice. If you are not the administrator, you might need wait for an approval. - Invite the app to a channel (use the
@<Name>
followed by clicking on the prompt to invite). - Create a local file named
local.dev.env
with the credentials official-docs with:-
Bot token by copying from "Bot User OAuth Access Token" under the "OAuth & Permissions"
-
Signing secret by copying from "Basic Information", "App Credentials", then "Signing Secret".
-
Create a
local.dev.env
SLACK_BOT_TOKEN= SLACK_SIGNING_SECRET=
-
- Run ngrok:
ngrok http 8080
and copy thehttps
returned. - Run the app:
./run.sh
- Review the slash command and the interactivity webhooks in the Slack application:
- Slash Command: ngrok's URL followed by
/slash/events
. - interact Command: ngrok's URL followed by
/slash/events
.
- Slash Command: ngrok's URL followed by
- Enter the Slack's slash command and test it!
sbt scalafmtAll
to format all files (except SBT).