Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GAE Slack API Example

Small example of slack API using bot with GAE/Go

Environment

TODO: GAE, GOPATH etc

go get github.com/gorilla/mux
go get github.com/tidwall/gjson

Set up your slack App

  1. Sign in to slack workspace as a admin
  2. Create App
    1. Go to https://api.slack.com/apps
    2. Click Create New App
    3. Input App name and select workspace
    4. Click save button
  3. Set up App (If you started here, go to https://api.slack.com/apps and select your App)
    1. Open OAuth & Permissions from left menu
    2. Select scopes below and save
      • channels:read
      • channels:write
      • chat:write:bot
  4. Install App
    1. Open Basic Information from left menu
    2. Click Install your app to your workspace
    3. Authorize your App
  5. Get access token
    1. Open OAuth & Permissions from left menu
    2. Copy OAuth Access Token

note: When you create channel via API, channel creator will not be the App bot, but the user who authorized the App.

Test local server

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"

Set up Event API

  1. Deploy this app.
    Or you can boot the app localy and use ngrok.
    Event API needs public URL for this app.
  2. Open your app settings
    1. Go to https://api.slack.com/apps
    2. Select your app
  3. Set up your app
    1. Open Event Subscriptions from left menu
    2. Enable Events
    3. Input Request URL. It might be like <YOUR APP ROOT>/slack/event.
      • Slack will send verification request to your app.
    4. Add events you need to subscribe.
      • e.g. message.channels
      • You may have to add required scope.
    5. Add App Unfurl Domains if you need.
    6. Click Save Changes.
  4. Prepare signature verification
    1. Open Basic Information from left menu
    2. Copy Signing Secret
    3. Edit app.yaml and replace <PUT YOUR SIGNING SECRET HERE> with signing secret above.

Set up Slack OAuth

  1. Open your app settings
    1. Go to https://api.slack.com/apps
    2. Select your app
  2. Get Client ID and Client Secret
    1. Open Basic Information from left menu
    2. Copy Client ID and Client Secret
    3. Edit app.yaml and 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.
  3. Set Redirect URL
    1. Open OAuth & Permissions from left menu
    2. Input Redirect URLs. It might be like http://localhost:8080/slack/oauth/token.
    3. Click Save URLs
    4. Edit app.yaml and replace <PUT YOUR REDIRECT URL HERE> with same URL as above.
  4. Optional: Set Workspace ID
    1. Edit app.yaml and 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.

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.

About

Sample of Slack API with GAE/Go

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages