Slack slash command service written in Golang
git clone https://github.com/anubhavmishra/slack-slash-command.git
brew install ngrok/ngrok/ngrok
or
sudo unzip ~/Downloads/ngrok-stable-darwin-amd64.zip -d /usr/local/bin
Build the project
cd slack-slash-command
make build-service
- Go to Slack API webpage
- Click "Create an app"
- Select "From scratch" option from the "Create an app" modal
- Enter application name and select a workspace for your application
- Click "Create App" button to create your application. This should create your application and take you to the "Basic Information" page of your application.
- Copy the "Verification Token" from the "App Credentials" section. You can find the "App Credentials" section by scrolling down towards the bottom of the "Basic Information" page.
The video below showcases how to create a Slack app and find the verification token.
create-app-and-copy-verification-token.mov
Set Slack token
cd slack-slash-command
export SLACK_VERIFICATION_TOKEN="SLACK TOKEN HERE"
cd slack-slash-command
./build/slack-slash-command
Expected output
2022/03/12 18:53:59 PORT environment variable not found defaulting to port 8080
2022/03/12 18:53:59 Server listening on port 8080
The slash command application is now listening on port 8080
In a new terminal window, run the command below
ngrok http 8080
Expected output
ngrok by @inconshreveable (Ctrl+C to quit)
Session Status online
Session Expires 1 hour, 59 minutes
Version 2.3.40
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://8dec-49-207-209-126.ngrok.io -> http://localhost:8080
Forwarding https://8dec-49-207-209-126.ngrok.io -> http://localhost:8080
Connections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Copy the https
address from the output. In this case, it's https://8dec-49-207-209-126.ngrok.io
- From your application homepage, select "Slash Commands" from the side navigation bar.
- From the "Slash Commands" section, select "Create New Command"
- Enter details for your slash command. First, in the "Command" input box enter
/hello
- In the "Request URL" input box paste the ngrok
https
address and add/receive
at the end of it. For this example, thehttps
URL will look like thishttps://8dec-49-207-209-126.ngrok.io/receive
- Enter a short description in the "Short Description" input box
- Click the "Save" button in the lower right corner of the webpage.
The video below showcases how to create a slash command.
create-a-slash-command.mov
- Go to the "Basic Information" page of your application
- In the "Install your app" section click on "Install to Workspace" button
- Click "Allow" to give permission to the app. Application should now be installed.
The video below showcases how to install a Slack app.
install-slack-app.mov
- Go to the Slack channel you want to install the slash command.
- Click on the View all members of this channel" button on the top right corner of the Slack channel
- Select the "Integrations" tab in the modal.
- In the "Apps" section click "Add apps" button.
- Scroll to find the "Slack Slash Command" app and click the "Add" button beside its name. Slack application should now be installed in the channel.
- In the message box of the channel type
/hello
to invoke the slash command. You should see a message "Hello World!" back from the "Slack Slash Command" application.
The video below showcases how to install Slack application in a channel and invoke /hello
slash command to get a response back from the "Slack Slash Command" application.
install-slack-app-and-invoke-slash-command.mov
Thank you to Emily Goldfein for the Creating Slack Slash Commands using Go blog post as this project uses a lot of the code in the blog post. This project just removes the Open Weather Map API usage in the application and gives users a more generic example to create a Slack slash command application.