Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: slack-go/slack
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.13.1
Choose a base ref
...
head repository: slack-go/slack
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.14.0
Choose a head ref
  • 8 commits
  • 23 files changed
  • 10 contributors

Commits on Jul 20, 2024

  1. slackevents: support metadata in MessageEvent (#1307)

    Support for receiving metadata when reading conversation history was
    first added in PR #1083. This commit extends metadata support to message
    events when connected to the Slack WebSocket API.
    
    Signed-off-by: Robert Fratto <robertfratto@gmail.com>
    rfratto authored Jul 20, 2024
    Copy the full SHA
    b9d4317 View commit details

Commits on Aug 15, 2024

  1. chore: replace ioutil with io or os package (#1310)

    nakamasato authored Aug 15, 2024
    Copy the full SHA
    25fefc8 View commit details
  2. add file access field to file struct for slackevents (#1312)

    zFlabmonsta authored Aug 15, 2024
    Copy the full SHA
    75103a9 View commit details
  3. Add slack_file to image block (#1311)

    Co-authored-by: Rhys M <rhysm@protonmail.com>
    rhysm and rhysm authored Aug 15, 2024
    Copy the full SHA
    99b3ebe View commit details
  4. feat: Events api reconcilation (#1306)

    * events added with test
    
    * added events with tests
    
    * added all events and changes done
    Aryakoste authored Aug 15, 2024
    Copy the full SHA
    e947079 View commit details
  5. feat: Add support for parsing AppRateLimited events (#1308)

    The code changes in this commit add support for parsing AppRateLimited events in the `ParseEvent` function. This allows the application to handle rate-limited events from the Slack API.
    nemuvski authored Aug 15, 2024
    Copy the full SHA
    50e7414 View commit details
  6. feat: Add Properties.Canvas to Channel (#1228)

    * Add Properties.Canvas to Channel
    
    * Trigger GitHub Actions
    
    ---------
    
    Co-authored-by: Lorenzo Aiello <lorenzo.aiello@slack-corp.com>
    ku and lorenzoaiello authored Aug 15, 2024
    Copy the full SHA
    5345c06 View commit details
  7. fix: create multipart form when multipart request (#1117)

    * fix: create multipart form when multipart request
    
    * call createFormFields in go func()
    
    del coment
    
    * Trigger GitHub Actions
    
    ---------
    
    Co-authored-by: Lorenzo Aiello <lorenzo.aiello@slack-corp.com>
    EkeMinusYou and lorenzoaiello authored Aug 15, 2024
    Copy the full SHA
    242df46 View commit details
20 changes: 15 additions & 5 deletions block_image.go
Original file line number Diff line number Diff line change
@@ -4,11 +4,21 @@ package slack
//
// More Information: https://api.slack.com/reference/messaging/blocks#image
type ImageBlock struct {
Type MessageBlockType `json:"type"`
ImageURL string `json:"image_url"`
AltText string `json:"alt_text"`
BlockID string `json:"block_id,omitempty"`
Title *TextBlockObject `json:"title,omitempty"`
Type MessageBlockType `json:"type"`
ImageURL string `json:"image_url,omitempty"`
AltText string `json:"alt_text"`
BlockID string `json:"block_id,omitempty"`
Title *TextBlockObject `json:"title,omitempty"`
SlackFile *SlackFileObject `json:"slack_file,omitempty"`
}

// SlackFileObject Defines an object containing Slack file information to be used in an
// image block or image element.
//
// More Information: https://api.slack.com/reference/block-kit/composition-objects#slack_file
type SlackFileObject struct {
ID string `json:"id,omitempty"`
URL string `json:"url,omitempty"`
}

// BlockType returns the type of the block
9 changes: 5 additions & 4 deletions channels.go
Original file line number Diff line number Diff line change
@@ -19,10 +19,11 @@ type channelResponseFull struct {
// Channel contains information about the channel
type Channel struct {
GroupConversation
IsChannel bool `json:"is_channel"`
IsGeneral bool `json:"is_general"`
IsMember bool `json:"is_member"`
Locale string `json:"locale"`
IsChannel bool `json:"is_channel"`
IsGeneral bool `json:"is_general"`
IsMember bool `json:"is_member"`
Locale string `json:"locale"`
Properties *Properties `json:"properties"`
}

func (api *Client) channelRequest(ctx context.Context, path string, values url.Values) (*channelResponseFull, error) {
6 changes: 3 additions & 3 deletions chat.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
@@ -226,11 +226,11 @@ func (api *Client) SendMessageContext(ctx context.Context, channelID string, opt
}

if api.Debug() {
reqBody, err := ioutil.ReadAll(req.Body)
reqBody, err := io.ReadAll(req.Body)
if err != nil {
return "", "", "", err
}
req.Body = ioutil.NopCloser(bytes.NewBuffer(reqBody))
req.Body = io.NopCloser(bytes.NewBuffer(reqBody))
api.Debugf("Sending request: %s", redactToken(reqBody))
}

10 changes: 5 additions & 5 deletions chat_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package slack
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@@ -216,7 +216,7 @@ func TestPostMessage(t *testing.T) {
t.Run(name, func(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
http.HandleFunc(test.endpoint, func(rw http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
@@ -242,7 +242,7 @@ func TestPostMessageWithBlocksWhenMsgOptionResponseURLApplied(t *testing.T) {

http.DefaultServeMux = new(http.ServeMux)
http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
@@ -270,7 +270,7 @@ func TestPostMessageWithBlocksWhenMsgOptionResponseURLApplied(t *testing.T) {
func TestPostMessageWhenMsgOptionReplaceOriginalApplied(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
@@ -297,7 +297,7 @@ func TestPostMessageWhenMsgOptionReplaceOriginalApplied(t *testing.T) {
func TestPostMessageWhenMsgOptionDeleteOriginalApplied(t *testing.T) {
http.DefaultServeMux = new(http.ServeMux)
http.HandleFunc("/response-url", func(rw http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("unexpected error: %v", err)
return
11 changes: 11 additions & 0 deletions conversation.go
Original file line number Diff line number Diff line change
@@ -65,6 +65,17 @@ type Purpose struct {
LastSet JSONTime `json:"last_set"`
}

// Properties contains the Canvas associated to the channel.
type Properties struct {
Canvas Canvas `json:"canvas"`
}

type Canvas struct {
FileId string `json:"file_id"`
IsEmpty bool `json:"is_empty"`
QuipThreadId string `json:"quip_thread_id"`
}

type GetUsersInConversationParameters struct {
ChannelID string
Cursor string
79 changes: 79 additions & 0 deletions conversation_test.go
Original file line number Diff line number Diff line change
@@ -149,6 +149,85 @@ func TestCreateSimpleGroup(t *testing.T) {
assertSimpleGroup(t, group)
}

// Channel with Canvas
var channelWithCanvas = `{
"id": "C024BE91L",
"name": "fun",
"is_channel": true,
"created": 1360782804,
"creator": "U024BE7LH",
"is_archived": false,
"is_general": false,
"members": [
"U024BE7LH"
],
"topic": {
"value": "Fun times",
"creator": "U024BE7LV",
"last_set": 1369677212
},
"purpose": {
"value": "This channel is for fun",
"creator": "U024BE7LH",
"last_set": 1360782804
},
"is_member": true,
"last_read": "1401383885.000061",
"unread_count": 0,
"unread_count_display": 0,
"properties": {
"canvas": {
"file_id": "F05RQ01LJU0",
"is_empty": true,
"quip_thread_id": "XFB9AAlvIyJ"
}
}
}`

func unmarshalChannelWithCanvas(j string) (*Channel, error) {
channel := &Channel{}
if err := json.Unmarshal([]byte(j), &channel); err != nil {
return nil, err
}
return channel, nil
}

func TestChannelWithCanvas(t *testing.T) {
channel, err := unmarshalChannelWithCanvas(channelWithCanvas)
assert.Nil(t, err)
assertChannelWithCanvas(t, channel)
}

func assertChannelWithCanvas(t *testing.T, channel *Channel) {
assertSimpleChannel(t, channel)
assert.Equal(t, "F05RQ01LJU0", channel.Properties.Canvas.FileId)
assert.Equal(t, true, channel.Properties.Canvas.IsEmpty)
assert.Equal(t, "XFB9AAlvIyJ", channel.Properties.Canvas.QuipThreadId)
}

func TestCreateChannelWithCanvas(t *testing.T) {
channel := &Channel{}
channel.ID = "C024BE91L"
channel.Name = "fun"
channel.IsChannel = true
channel.Created = JSONTime(1360782804)
channel.Creator = "U024BE7LH"
channel.IsArchived = false
channel.IsGeneral = false
channel.IsMember = true
channel.LastRead = "1401383885.000061"
channel.UnreadCount = 0
channel.UnreadCountDisplay = 0
channel.Properties = &Properties{
Canvas: Canvas{
FileId: "F05RQ01LJU0",
IsEmpty: true,
QuipThreadId: "XFB9AAlvIyJ",
},
}
assertChannelWithCanvas(t, channel)
}

// IM
var simpleIM = `{
"id": "D024BFF1M",
4 changes: 2 additions & 2 deletions examples/dialog/dialog.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package main

import (
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@@ -26,7 +26,7 @@ func handler(w http.ResponseWriter, r *http.Request) {

// Read request body
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
log.Printf("[ERROR] Fail to read request body: %v", err)
4 changes: 2 additions & 2 deletions examples/eventsapi/events.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"

@@ -18,7 +18,7 @@ func main() {
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")

http.HandleFunc("/events-endpoint", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
6 changes: 3 additions & 3 deletions examples/modal/modal.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/slack-go/slack"
@@ -95,13 +95,13 @@ func verifySigningSecret(r *http.Request) error {
return err
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
fmt.Println(err.Error())
return err
}
// Need to use r.Body again when unmarshalling SlashCommand and InteractionCallback
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

verifier.Write(body)
if err = verifier.Ensure(); err != nil {
3 changes: 1 addition & 2 deletions examples/slash/slash.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/slack-go/slack"
@@ -27,7 +26,7 @@ func main() {
return
}

r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &verifier))
r.Body = io.NopCloser(io.TeeReader(r.Body, &verifier))
s, err := slack.SlashCommandParse(r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
6 changes: 3 additions & 3 deletions examples/workflow_step/handler.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@@ -25,7 +25,7 @@ func handleMyWorkflowStep(w http.ResponseWriter, r *http.Request) {
}

// see: https://github.com/slack-go/slack/blob/master/examples/eventsapi/events.go
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
@@ -88,7 +88,7 @@ func handleInteraction(w http.ResponseWriter, r *http.Request) {
return
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
6 changes: 3 additions & 3 deletions examples/workflow_step/middleware.go
Original file line number Diff line number Diff line change
@@ -2,20 +2,20 @@ package main

import (
"bytes"
"io/ioutil"
"io"
"net/http"

"github.com/slack-go/slack"
)

func (v *SecretsVerifierMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

sv, err := slack.NewSecretsVerifier(r.Header, appCtx.config.signingSecret)
if err != nil {
4 changes: 2 additions & 2 deletions files_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package slack
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@@ -44,7 +44,7 @@ func (h *fileCommentHandler) handler(w http.ResponseWriter, r *http.Request) {
type mockHTTPClient struct{}

func (m *mockHTTPClient) Do(*http.Request) (*http.Response, error) {
return &http.Response{StatusCode: 200, Body: ioutil.NopCloser(bytes.NewBufferString(`OK`))}, nil
return &http.Response{StatusCode: 200, Body: io.NopCloser(bytes.NewBufferString(`OK`))}, nil
}

func TestSlack_GetFile(t *testing.T) {
Loading