Skip to content

Commit

Permalink
Merge branch 'master' into feature/remote-file
Browse files Browse the repository at this point in the history
  • Loading branch information
dleviminzi committed Apr 21, 2022
2 parents 3eb3ab3 + 03f86be commit ee3c0cc
Show file tree
Hide file tree
Showing 127 changed files with 9,402 additions and 2,563 deletions.
6 changes: 5 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -3,12 +3,16 @@ name: Bug Report
about: Create a report to help us improve
---

### What happend
### What happened

### Expected behavior

### Steps to reproduce

#### reproducible code

#### manifest.yaml

### Versions
- Go:
- slack-go/slack:
31 changes: 15 additions & 16 deletions .github/workflows/test.yml
Expand Up @@ -7,31 +7,30 @@ on:
pull_request:

jobs:
ci:
runs-on: ubuntu-latest
name: lint
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.32
test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
go:
- '1.12'
- '1.13'
- '1.14'
- '1.15'
- '1.16'
- '1.17'
- '1.18'
name: test go-${{ matrix.go }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: run test
run: go test -v -race ./...
env:
GO111MODULE: on
lint:
runs-on: ubuntu-20.04
name: lint
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
18 changes: 13 additions & 5 deletions README.md
@@ -1,8 +1,9 @@
Slack API in Go [![GoDoc](https://godoc.org/github.com/slack-go/slack?status.svg)](https://godoc.org/github.com/slack-go/slack) [![Build Status](https://travis-ci.org/slack-go/slack.svg)](https://travis-ci.org/slack-go/slack)
Slack API in Go [![Go Reference](https://pkg.go.dev/badge/github.com/slack-go/slack.svg)](https://pkg.go.dev/github.com/slack-go/slack)
===============
This is the original Slack library for Go created by Norberto Lopez, transferred to a Github organization.

[![Join the chat at https://gitter.im/go-slack/Lobby](https://badges.gitter.im/go-slack/Lobby.svg)](https://gitter.im/go-slack/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This is the original Slack library for Go created by Norberto Lopes, transferred to a GitHub organization.

You can also chat with us on the #slack-go, #slack-go-ja Slack channel on the Gophers Slack.

![logo](logo.png "icon")

Expand All @@ -14,7 +15,7 @@ a fully managed way.
There is currently no major version released.
Therefore, minor version releases may include backward incompatible changes.

See [CHANGELOG.md](https://github.com/slack-go/slack/blob/master/CHANGELOG.md) for more information about the changes.
See [CHANGELOG.md](https://github.com/slack-go/slack/blob/master/CHANGELOG.md) or [Releases](https://github.com/slack-go/slack/releases) for more information about the changes.

## Installing

Expand All @@ -38,7 +39,7 @@ func main() {
// If you set debugging, it will log all requests to the console
// Useful when encountering issues
// slack.New("YOUR_TOKEN_HERE", slack.OptionDebug(true))
groups, err := api.GetGroups(false)
groups, err := api.GetUserGroups(false)
if err != nil {
fmt.Printf("%s\n", err)
return
Expand Down Expand Up @@ -69,8 +70,15 @@ func main() {
}
```

## Minimal Socket Mode usage:

See https://github.com/slack-go/slack/blob/master/examples/socketmode/socketmode.go


## Minimal RTM usage:

As mentioned in https://api.slack.com/rtm - for most applications, Socket Mode is a better way to communicate with Slack.

See https://github.com/slack-go/slack/blob/master/examples/websocket/websocket.go


Expand Down
21 changes: 21 additions & 0 deletions apps.go
Expand Up @@ -3,6 +3,7 @@ package slack
import (
"context"
"encoding/json"
"net/url"
)

type listEventAuthorizationsResponse struct {
Expand Down Expand Up @@ -41,3 +42,23 @@ func (api *Client) ListEventAuthorizationsContext(ctx context.Context, eventCont

return resp.Authorizations, nil
}

func (api *Client) UninstallApp(clientID, clientSecret string) error {
return api.UninstallAppContext(context.Background(), clientID, clientSecret)
}

func (api *Client) UninstallAppContext(ctx context.Context, clientID, clientSecret string) error {
values := url.Values{
"client_id": {clientID},
"client_secret": {clientSecret},
}

response := SlackResponse{}

err := api.getMethod(ctx, "apps.uninstall", api.token, values, &response)
if err != nil {
return err
}

return response.Err()
}
19 changes: 19 additions & 0 deletions apps_test.go
Expand Up @@ -36,3 +36,22 @@ func testListEventAuthorizationsHandler(w http.ResponseWriter, r *http.Request)
})
w.Write(response)
}

func TestUninstallApp(t *testing.T) {
http.HandleFunc("/apps.uninstall", testUninstallAppHandler)
once.Do(startServer)

api := New("test-token", OptionAPIURL("http://"+serverAddr+"/"))

err := api.UninstallApp("", "")

if err != nil {
t.Errorf("Failed, but should have succeeded")
}
}

func testUninstallAppHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
response, _ := json.Marshal(SlackResponse{Ok: true})
w.Write(response)
}
9 changes: 7 additions & 2 deletions attachments.go
Expand Up @@ -17,7 +17,7 @@ type AttachmentAction struct {
Name string `json:"name"` // Required.
Text string `json:"text"` // Required.
Style string `json:"style,omitempty"` // Optional. Allowed values: "default", "primary", "danger".
Type actionType `json:"type"` // Required. Must be set to "button" or "select".
Type ActionType `json:"type"` // Required. Must be set to "button" or "select".
Value string `json:"value,omitempty"` // Optional.
DataSource string `json:"data_source,omitempty"` // Optional.
MinQueryLength int `json:"min_query_length,omitempty"` // Optional. Default value is 1.
Expand All @@ -29,7 +29,7 @@ type AttachmentAction struct {
}

// actionType returns the type of the action
func (a AttachmentAction) actionType() actionType {
func (a AttachmentAction) actionType() ActionType {
return a.Type
}

Expand Down Expand Up @@ -80,6 +80,11 @@ type Attachment struct {
ImageURL string `json:"image_url,omitempty"`
ThumbURL string `json:"thumb_url,omitempty"`

ServiceName string `json:"service_name,omitempty"`
ServiceIcon string `json:"service_icon,omitempty"`
FromURL string `json:"from_url,omitempty"`
OriginalURL string `json:"original_url,omitempty"`

Fields []AttachmentField `json:"fields,omitempty"`
Actions []AttachmentAction `json:"actions,omitempty"`
MarkdownIn []string `json:"mrkdwn_in,omitempty"`
Expand Down
142 changes: 142 additions & 0 deletions audit.go
@@ -0,0 +1,142 @@
package slack

import (
"context"
"net/url"
"strconv"
)

type AuditLogResponse struct {
Entries []AuditEntry `json:"entries"`
SlackResponse
}

type AuditEntry struct {
ID string `json:"id"`
DateCreate int `json:"date_create"`
Action string `json:"action"`
Actor struct {
Type string `json:"type"`
User AuditUser `json:"user"`
} `json:"actor"`
Entity struct {
Type string `json:"type"`
// Only one of the below will be completed, based on the value of Type a user, a channel, a file, an app, a workspace, or an enterprise
User AuditUser `json:"user"`
Channel AuditChannel `json:"channel"`
File AuditFile `json:"file"`
App AuditApp `json:"app"`
Workspace AuditWorkspace `json:"workspace"`
Enterprise AuditEnterprise `json:"enterprise"`
} `json:"entity"`
Context struct {
Location struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
} `json:"location"`
UA string `json:"ua"`
IPAddress string `json:"ip_address"`
} `json:"context"`
}

type AuditUser struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Team string `json:"team"`
}

type AuditChannel struct {
ID string `json:"id"`
Name string `json:"name"`
Privacy string `json:"privacy"`
IsShared bool `json:"is_shared"`
IsOrgShared bool `json:"is_org_shared"`
}

type AuditFile struct {
ID string `json:"id"`
Name string `json:"name"`
Filetype string `json:"filetype"`
Title string `json:"title"`
}

type AuditApp struct {
ID string `json:"id"`
Name string `json:"name"`
IsDistributed bool `json:"is_distributed"`
IsDirectoryApproved bool `json:"is_directory_approved"`
IsWorkflowApp bool `json:"is_workflow_app"`
Scopes []string `json:"scopes"`
}

type AuditWorkspace struct {
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
}

type AuditEnterprise struct {
ID string `json:"id"`
Name string `json:"name"`
Domain string `json:"domain"`
}

// AuditLogParameters contains all the parameters necessary (including the optional ones) for a GetAuditLogs() request
type AuditLogParameters struct {
Limit int
Cursor string
Latest int
Oldest int
Action string
Actor string
Entity string
}

func (api *Client) auditLogsRequest(ctx context.Context, path string, values url.Values) (*AuditLogResponse, error) {
response := &AuditLogResponse{}
err := api.getMethod(ctx, path, api.token, values, response)
if err != nil {
return nil, err
}
return response, response.Err()
}

// GetAuditLogs retrieves a page of audit entires according to the parameters given
func (api *Client) GetAuditLogs(params AuditLogParameters) (entries []AuditEntry, nextCursor string, err error) {
return api.GetAuditLogsContext(context.Background(), params)
}

// GetAuditLogsContext retrieves a page of audit entries according to the parameters given with a custom context
func (api *Client) GetAuditLogsContext(ctx context.Context, params AuditLogParameters) (entries []AuditEntry, nextCursor string, err error) {
values := url.Values{}
if params.Limit != 0 {
values.Add("limit", strconv.Itoa(params.Limit))
}
if params.Oldest != 0 {
values.Add("oldest", strconv.Itoa(params.Oldest))
}
if params.Latest != 0 {
values.Add("latest", strconv.Itoa(params.Latest))
}
if params.Cursor != "" {
values.Add("cursor", params.Cursor)
}
if params.Action != "" {
values.Add("action", params.Action)
}
if params.Actor != "" {
values.Add("actor", params.Actor)
}
if params.Entity != "" {
values.Add("entity", params.Entity)
}

response, err := api.auditLogsRequest(ctx, "audit/v1/logs", values)
if err != nil {
return nil, "", err
}
return response.Entries, response.ResponseMetadata.Cursor, response.Err()
}

0 comments on commit ee3c0cc

Please sign in to comment.