Small example of slack API using bot with GAE/Go
TODO: GAE, GOPATH etc
go get github.com/gorilla/mux
go get github.com/tidwall/gjson- Sign in to slack workspace as a admin
- Create App
- Go to https://api.slack.com/apps
- Click
Create New App - Input App name and select workspace
- Click save button
- Set up App (If you started here, go to https://api.slack.com/apps and select your App)
- Open
OAuth & Permissionsfrom left menu - Select scopes below and save
channels:readchannels:writechat:write:bot
- Open
- Install App
- Open
Basic Informationfrom left menu - Click
Install your app to your workspace - Authorize your App
- Open
- Get access token
- Open
OAuth & Permissionsfrom left menu - Copy
OAuth Access Token
- Open
note: When you create channel via API, channel creator will not be the App bot, but the user who authorized the App.
Edit app.yaml and replace <PUT YOUR ACCESS TOKEN HERE> with token above.
Boot local server
goapp serve .Call API
curl http://localhost:8080/slack/channels
curl -X POST http://localhost:8080/slack/channels -d "name=test_channel"
curl -X POST http://localhost:8080/slack/channels/general/messages -d "text=MY_MESSAGE"- Deploy this app.
Or you can boot the app localy and use ngrok.
Event API needs public URL for this app. - Open your app settings
- Go to https://api.slack.com/apps
- Select your app
- Set up your app
- Open
Event Subscriptionsfrom left menu - Enable Events
- Input
Request URL. It might be like<YOUR APP ROOT>/slack/event.- Slack will send verification request to your app.
- Add events you need to subscribe.
- e.g.
message.channels - You may have to add required scope.
- e.g.
- Add
App Unfurl Domainsif you need. - Click
Save Changes.
- Open
- Prepare signature verification
- Open
Basic Informationfrom left menu - Copy
Signing Secret - Edit
app.yamland replace<PUT YOUR SIGNING SECRET HERE>with signing secret above.
- Open
- Open your app settings
- Go to https://api.slack.com/apps
- Select your app
- Get Client ID and Client Secret
- Open
Basic Informationfrom left menu - Copy
Client IDandClient Secret - Edit
app.yamland resplace<PUT YOUR CLIENT ID HERE>and<PUT YOUR CLIENT SECRET HERE>with above.
Make sure to set them as STRING. They may have to be in quotes, or they might be treated as numbers.
- Open
- Set Redirect URL
- Open
OAuth & Permissionsfrom left menu - Input
Redirect URLs. It might be likehttp://localhost:8080/slack/oauth/token. - Click
Save URLs - Edit
app.yamland replace<PUT YOUR REDIRECT URL HERE>with same URL as above.
- Open
- Optional: Set Workspace ID
- Edit
app.yamland replace<PUT YOUR WORKSPACE ID HERE>with your slack workspace ID.
If you do this, you will not need to select the Workspace through authorization flow.
- Edit
Now you can start authorization flow by accessing to http://localhost:8080/slack/oauth/auth with your web browser.
At end of the flow, you will see granted access token in the web browser.