This library implements the Slack API Web and Real Time Messaging parts.
A simple example utilizing most of the functionality can be seen under examples/scli which implements a full featured CLI client for Slack - either interactive or for batch usage.
Implemented Methods
| Method | Description | Support | 
|---|---|---|
| api.test | Checks API calling code | false | 
| auth.test | Checks authentication & identity | true | 
| channels.archive | Archives a channel | true | 
| channels.create | Creates a channel | true | 
| channels.history | Fetches history of messages and events from a channel | true | 
| channels.info | Gets information about a channel | true | 
| channels.invite | Invites a user to a channel | true | 
| channels.join | Joins a channel, creating it if needed | true | 
| channels.kick | Removes a user from a channel | true | 
| channels.leave | Leaves a channel | true | 
| channels.list | Lists all channels in a Slack team | true | 
| channels.mark | Sets the read cursor in a channel | true | 
| channels.rename | Renames a channel | true | 
| channels.setPurpose | Sets the purpose for a channel | true | 
| channels.setTopic | Sets the topic for a channel | true | 
| channels.unarchive | Unarchives a channel | true | 
| chat.delete | Deletes a message | true | 
| chat.postMessage | Sends a message to a channel | true | 
| chat.update | Updates a message | false | 
| emoji.list | Lists custom emoji for a team | true | 
| files.delete | Deletes a file | true | 
| files.info | Gets information about a team file | true | 
| files.list | Lists & filters team files | true | 
| files.upload | Uploads or creates a file | true | 
| groups.archive | Archives a private group | true | 
| groups.close | Closes a private group | true | 
| groups.create | Creates a private group | true | 
| groups.createChild | Clones and archives a private group | true | 
| groups.history | Fetches history of messages and events from a private group | true | 
| groups.info | Gets information about a private group | true | 
| groups.invite | Invites a user to a private group | true | 
| groups.kick | Removes a user from a private group | true | 
| groups.leave | Leaves a private group | true | 
| groups.list | Lists private groups that the calling user has access to | true | 
| groups.mark | Sets the read cursor in a private group | true | 
| groups.open | Opens a private group | true | 
| groups.rename | Renames a private group | true | 
| groups.setPurpose | Sets the purpose for a private group | true | 
| groups.setTopic | Sets the topic for a private group | true | 
| groups.unarchive | Unarchives a private group | true | 
| im.close | Close a direct message channel | true | 
| im.history | Fetches history of messages and events from direct message channel | true | 
| im.list | Lists direct message channels for the calling user | true | 
| im.mark | Sets the read cursor in a direct message channel | true | 
| im.open | Opens a direct message channel | true | 
| rtm.start | Starts a Real Time Messaging session | true | 
| search.all | Searches for messages and files matching a query | false | 
| search.files | Searches for files matching a query | false | 
| search.messages | Searches for messages matching a query | false | 
| stars.list | Lists stars for a user | false | 
| team.accessLogs | Gets the access logs for the current team | false | 
| team.info | Gets information about the current team | true | 
| users.getPresence | Gets user presence information | false | 
| users.info | Gets information about a user | true | 
| users.list | Lists all users in a Slack team | true | 
| users.setActive | Marks a user as active | false | 
| users.setPresence | Manually sets user presence | false | 
- All of the above with a 
falsein thesupportcolumn. - Testing
 
If you have a go workplace setup and working you can simply do:
go get -u -t -v github.com/demisto/slack
There are 2 ways to initiate the library, both using the various configuration functions slack.Set*:
- Either using a test token retrieved from Slack and then setting the token
 
s, err = slack.New(slack.SetToken("test token retrieved from Slack"))- Using OAuth - see a simple example using uuid for random state. For this to work, you need to register your application with Slack.
 
// Start the OAuth process
// First, generate a random state
uuid, err := random.New()
if err != nil {
  panic(err)
}
conf := &oauth2.Config{
  ClientID:     "Your client ID",
  ClientSecret: "Your client secret",
  Scopes:       []string{"client"}, // the widest scope - can be others depending on requirement
  Endpoint: oauth2.Endpoint{
    AuthURL:  "https://slack.com/oauth/authorize",
    TokenURL: "https://slack.com/api/oauth.access",
  },
}
// Store state somewhere you can use later with timestamp
// ...
url := conf.AuthCodeURL(uuid.String())
// Redirect user to the OAuth Slack page
http.Redirect(w, r, url, http.StatusFound)// Now, handle the redirected URL after the successful authentication
state := r.FormValue("state")
code := r.FormValue("code")
errStr := r.FormValue("error")
if errStr != "" {
  WriteError(w, &Error{"oauth_err", 401, "Slack OAuth Error", errStr})
  return
}
if state == "" || code == "" {
  WriteError(w, ErrBadContentRequest)
  return
}
// Retrieve the state you saved in the first step and make sure it is not too old
// ...
token, err := slack.OAuthAccess("Your client ID", "Your client secret", code, "")
if err != nil {
  WriteError(w, &Error{"oauth_err", 401, "Slack OAuth Error", err.Error()})
  return
}
// Done - you have the token - you can save it for later use
s, err := slack.New(slack.SetToken(token.AccessToken))
if err != nil {
  panic(err)
}
// Get our own user id
test, err := s.AuthTest()
if err != nil {
  panic(err)
}The library was written by slavikm as a side project to play with Slack API for demisto.