From a99606f766e7d8c85067d311b606e6456a371b4b Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Tue, 12 Nov 2024 14:30:09 -0500 Subject: [PATCH 1/4] fix: Assistant Prompts and Status, send channel_id with request (#1344) This is a fix for [PR 1331](https://github.com/slack-go/slack/pull/1331), which I mistakenly removed the channel_id parameter from the API request during feedback. Without channel_id provided, the call always returns `invalid_arguments`. --- assistant.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assistant.go b/assistant.go index ef1425ff..8432f89b 100644 --- a/assistant.go +++ b/assistant.go @@ -60,6 +60,8 @@ func (api *Client) SetAssistantThreadsSuggestedPromptsContext(ctx context.Contex values.Add("thread_ts", params.ThreadTS) } + values.Add("channel_id", params.ChannelID) + // Send Prompts as JSON prompts, err := json.Marshal(params.Prompts) if err != nil { @@ -98,6 +100,8 @@ func (api *Client) SetAssistantThreadsStatusContext(ctx context.Context, params values.Add("thread_ts", params.ThreadTS) } + values.Add("channel_id", params.ChannelID) + // Always send the status parameter, if empty, it will clear any existing status values.Add("status", params.Status) From 52fcd3dfb438132318fa07d697cafac23d1dbfd1 Mon Sep 17 00:00:00 2001 From: Caleb McKay <11079725+calebmckay@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:31:20 -0500 Subject: [PATCH 2/4] fix: Don't require `skin_tone` for rich text emoji element (#1341) In a rich text `emoji` element, the `skin_tone` value is optional, and when not provided will use the default skin tone. When unmarshalling from JSON, this parameter defaults to an invalid value of 0 (`skin_tone` values range from 2 to 6), resulting in an "invalid_blocks" error when sending a message. This PR allows the `skin_tone` element to be omitted when unmarshalling from JSON. --- block_rich_text.go | 2 +- block_rich_text_test.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/block_rich_text.go b/block_rich_text.go index c6eb0b1b..22020beb 100644 --- a/block_rich_text.go +++ b/block_rich_text.go @@ -340,7 +340,7 @@ func NewRichTextSectionUserElement(userID string, style *RichTextSectionTextStyl type RichTextSectionEmojiElement struct { Type RichTextSectionElementType `json:"type"` Name string `json:"name"` - SkinTone int `json:"skin_tone"` + SkinTone int `json:"skin_tone,omitempty"` Unicode string `json:"unicode,omitempty"` Style *RichTextSectionTextStyle `json:"style,omitempty"` } diff --git a/block_rich_text_test.go b/block_rich_text_test.go index dc4a0cf5..903f1438 100644 --- a/block_rich_text_test.go +++ b/block_rich_text_test.go @@ -187,6 +187,16 @@ func TestRichTextSection_UnmarshalJSON(t *testing.T) { }, nil, }, + { + []byte(`{"type": "rich_text_section","elements":[{"type": "emoji","name": "+1"}]}`), + RichTextSection{ + Type: RTESection, + Elements: []RichTextSectionElement{ + &RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1"}, + }, + }, + nil, + }, { []byte(`{"type": "rich_text_section","elements":[{"type": "emoji","name": "+1","unicode": "1f44d-1f3fb","skin_tone": 2}]}`), RichTextSection{ @@ -299,7 +309,7 @@ func TestRichTextList_UnmarshalJSON(t *testing.T) { func TestRichTextQuote_Marshal(t *testing.T) { t.Run("rich_text_section", func(t *testing.T) { - const rawRSE = "{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Some Text\"}]}" + const rawRSE = "{\"type\":\"rich_text_section\",\"elements\":[{\"type\":\"text\",\"text\":\"Some Text\"},{\"type\":\"emoji\",\"name\":\"+1\"},{\"type\":\"emoji\",\"name\":\"+1\",\"skin_tone\":2}]}" var got RichTextSection if err := json.Unmarshal([]byte(rawRSE), &got); err != nil { @@ -309,6 +319,8 @@ func TestRichTextQuote_Marshal(t *testing.T) { Type: RTESection, Elements: []RichTextSectionElement{ &RichTextSectionTextElement{Type: RTSEText, Text: "Some Text"}, + &RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1"}, + &RichTextSectionEmojiElement{Type: RTSEEmoji, Name: "+1", SkinTone: 2}, }, } From dbb76ddd28b1c5612cbfbc1786c0ae75687a951a Mon Sep 17 00:00:00 2001 From: Hussachai Puripunpinyo Date: Thu, 14 Nov 2024 10:26:17 -0800 Subject: [PATCH 3/4] fix: ScheduleMessage not returning scheduled_message_id (#1153) I'd like to introduce the fix for `ScheduledMessage` API. Currently, it doesn't return scheduled_message_id where this ID is needed for cancelling the scheduled message. My change is the least intrusive I could think of. It doesn't introduce any new field or adding new API. Basically, this change should be backward compatible. It is based on the fact that the API [chat.postMessage](https://api.slack.com/methods/chat.postMessage#examples) doesn't return `scheduled_message_id` and the API [chat.scheduledMessage](https://api.slack.com/methods/chat.scheduleMessage#examples) doesn't return either `message.ts` or `ts`. We just need to check the presence of this field and determine the caller API based on that. Existing code shouldn't break because the `timestamp` is always an empty string for `ScheduledMessage` API. Now it will return `scheduled_message_id` in place of `timestamp`. `SendMessage` should remain the same. ##### Pull Request Guidelines These are recommendations for pull requests. They are strictly guidelines to help manage expectations. ##### PR preparation Run `make pr-prep` from the root of the repository to run formatting, linting and tests. ##### Should this be an issue instead - [ ] is it a convenience method? (no new functionality, streamlines some use case) - [ ] exposes a previously private type, const, method, etc. - [ ] is it application specific (caching, retry logic, rate limiting, etc) - [ ] is it performance related. ##### API changes Since API changes have to be maintained they undergo a more detailed review and are more likely to require changes. - no tests, if you're adding to the API include at least a single test of the happy case. - If you can accomplish your goal without changing the API, then do so. - dependency changes. updates are okay. adding/removing need justification. ###### Examples of API changes that do not meet guidelines: - in library cache for users. caches are use case specific. - Convenience methods for Sending Messages, update, post, ephemeral, etc. consider opening an issue instead. --- chat.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/chat.go b/chat.go index 96843d68..385836a0 100644 --- a/chat.go +++ b/chat.go @@ -116,13 +116,13 @@ func (api *Client) ScheduleMessage(channelID, postAt string, options ...MsgOptio // ScheduleMessageContext sends a message to a channel with a custom context. // Slack API docs: https://api.slack.com/methods/chat.scheduleMessage func (api *Client) ScheduleMessageContext(ctx context.Context, channelID, postAt string, options ...MsgOption) (string, string, error) { - respChannel, respTimestamp, _, err := api.SendMessageContext( + respChannel, scheduledMessageId, _, err := api.SendMessageContext( ctx, channelID, MsgOptionSchedule(postAt), MsgOptionCompose(options...), ) - return respChannel, respTimestamp, err + return respChannel, scheduledMessageId, err } // PostMessage sends a message to a channel. @@ -214,7 +214,7 @@ func (api *Client) SendMessage(channel string, options ...MsgOption) (string, st // SendMessageContext more flexible method for configuring messages with a custom context. // Slack API docs: https://api.slack.com/methods/chat.postMessage -func (api *Client) SendMessageContext(ctx context.Context, channelID string, options ...MsgOption) (_channel string, _timestamp string, _text string, err error) { +func (api *Client) SendMessageContext(ctx context.Context, channelID string, options ...MsgOption) (_channel string, _timestampOrScheduledMessageId string, _text string, err error) { var ( req *http.Request parser func(*chatResponseFull) responseParser @@ -238,7 +238,11 @@ func (api *Client) SendMessageContext(ctx context.Context, channelID string, opt return "", "", "", err } - return response.Channel, response.getMessageTimestamp(), response.Text, response.Err() + if response.ScheduledMessageID != "" { + return response.Channel, response.ScheduledMessageID, response.Text, response.Err() + } else { + return response.Channel, response.getMessageTimestamp(), response.Text, response.Err() + } } func redactToken(b []byte) []byte { From e76401112d28edda69b2c25b99999962f95c7a7f Mon Sep 17 00:00:00 2001 From: Lorenzo Aiello Date: Thu, 14 Nov 2024 13:26:43 -0500 Subject: [PATCH 4/4] chore: Contributing Guide - Codification of Project Norms (#1340) This pull request introduces a Contributing Guide to start codifying best practices and norms in the project. It also eliminates two old files that can be safely removed and just retained in the git history. The notable items in the contributing guide are: - Go Comment Formatting (already largely in place) - Codifying a preference for Input/Output structs on functions to allow more non-breaking changes to function calls as parameters change/expand over time (things have already been trending in this direction, but it helps to commit to the direction) I'll leave this up for a bit in case anyone has any thoughts or feedback. --- CHANGELOG.md | 103 ------------------------------------------------ CONTRIBUTING.md | 40 +++++++++++++++++++ README.md | 2 +- TODO.txt | 3 -- 4 files changed, 41 insertions(+), 107 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md delete mode 100644 TODO.txt diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 32da687b..00000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,103 +0,0 @@ -### v0.7.0 - October 2, 2020 -full differences can be viewed using `git log --oneline --decorate --color v0.6.6..v0.7.0` -Thank you for many contributions! - -#### Breaking Changes -- Add ScheduledMessage type ([#753]) -- Add description field to option block object ([#783]) -- Fix wrong conditional branch ([#782]) - - The behavior of the user's application may change.(The current behavior is incorrect) - -#### Highlights -- example: fix to start up a server ([#773]) -- example: Add explanation how the message could be sent in a proper way ([#787]) -- example: fix typo in error log ([#779]) -- refactor: Make GetConversationsParameters.ExcludeArchived optional ([#791]) -- refactor: Unify variables to "config" ([#800]) -- refactor: Rename wrong file name ([#810]) -- feature: Add SetUserRealName for change user's realName([#755]) -- feature: Add response metadata to slack response ([#772]) -- feature: Add response metadata to slack response ([#778]) -- feature: Add select block element conversations filter field ([#790]) -- feature: Add Root field to MessageEvent to support thread_broadcast subtype ([#793]) -- feature: Add bot_profile to messages ([#794]) -- doc: Add logo to README ([#813]) -- doc: Update current project status and Add changelog for v0.7.0 ([#814]) - -[#753]: https://github.com/slack-go/slack/pull/753 -[#755]: https://github.com/slack-go/slack/pull/755 -[#772]: https://github.com/slack-go/slack/pull/772 -[#773]: https://github.com/slack-go/slack/pull/773 -[#778]: https://github.com/slack-go/slack/pull/778 -[#779]: https://github.com/slack-go/slack/pull/779 -[#782]: https://github.com/slack-go/slack/pull/782 -[#783]: https://github.com/slack-go/slack/pull/783 -[#787]: https://github.com/slack-go/slack/pull/787 -[#790]: https://github.com/slack-go/slack/pull/790 -[#791]: https://github.com/slack-go/slack/pull/791 -[#793]: https://github.com/slack-go/slack/pull/793 -[#794]: https://github.com/slack-go/slack/pull/794 -[#800]: https://github.com/slack-go/slack/pull/800 -[#810]: https://github.com/slack-go/slack/pull/810 -[#813]: https://github.com/slack-go/slack/pull/813 -[#814]: https://github.com/slack-go/slack/pull/814 - -### v0.6.0 - August 31, 2019 -full differences can be viewed using `git log --oneline --decorate --color v0.5.0..v0.6.0` -thanks to everyone who has contributed since January! - - -#### Breaking Changes: -- Info struct has had fields removed related to deprecated functionality by slack. -- minor adjustments to some structs. -- some internal default values have changed, usually to be more inline with slack defaults or to correct inability to set a particular value. (Message Parse for example.) - -##### Highlights: -- new slacktest package easy mocking for slack client. use, enjoy, please submit PRs for improvements and default behaviours! shamelessly taken from the [slack-test repo](https://github.com/lusis/slack-test) thank you lusis for letting us use it and bring it into the slack repo. -- blocks, blocks, blocks. -- RTM ManagedConnection has undergone a significant cleanup. -in particular handles backoffs gracefully, removed many deadlocks, -and Disconnect is now much more responsive. - -### v0.5.0 - January 20, 2019 -full differences can be viewed using `git log --oneline --decorate --color v0.4.0..v0.5.0` -- Breaking changes: various old struct fields have been removed or updated to match slack's api. -- deadlock fix in RTM disconnect. - -### v0.4.0 - October 06, 2018 -full differences can be viewed using `git log --oneline --decorate --color v0.3.0..v0.4.0` -- Breaking Change: renamed ApplyMessageOption, to mark it as unsafe, -this means it may break without warning in the future. -- Breaking: Msg structure files field changed to an array. -- General: implementation for new security headers. -- RTM: deadlock fix between connect/disconnect. -- Events: various new fields added. -- Web: various fixes, new fields exposed, new methods added. -- Interactions: minor additions expect breaking changes in next release for dialogs/button clicks. -- Utils: new methods added. - -### v0.3.0 - July 30, 2018 -full differences can be viewed using `git log --oneline --decorate --color v0.2.0..v0.3.0` -- slack events initial support added. (still considered experimental and undergoing changes, stability not promised) -- vendored depedencies using dep, ensure using up to date tooling before filing issues. -- RTM has improved its ability to identify dead connections and reconnect automatically (worth calling out in case it has unintended side effects). -- bug fixes (various timestamp handling, error handling, RTM locking, etc). - -### v0.2.0 - Feb 10, 2018 - -Release adds a bunch of functionality and improvements, mainly to give people a recent version to vendor against. - -Please check [0.2.0](https://github.com/nlopes/slack/releases/tag/v0.2.0) - -### v0.1.0 - May 28, 2017 - -This is released before adding context support. -As the used context package is the one from Go 1.7 this will be the last -compatible with Go < 1.7. - -Please check [0.1.0](https://github.com/nlopes/slack/releases/tag/v0.1.0) - -### v0.0.1 - Jul 26, 2015 - -If you just updated from master and it broke your implementation, please -check [0.0.1](https://github.com/nlopes/slack/releases/tag/v0.0.1) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..8b92d353 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing Guide + +Welcome! We are glad that you want to contribute to our project! 💖 + +There are a just a few small guidelines you ask everyone to follow to make things a bit smoother and more consistent. + +## Opening Pull Requests + +1. It's generally best to start by opening a new issue describing the bug or feature you're intending to fix. Even if you think it's relatively minor, it's helpful to know what people are working on. Mention in the initial issue that you are planning to work on that bug or feature so that it can be assigned to you. + +2. Follow the normal process of [forking](https://help.github.com/articles/fork-a-repo) the project, and set up a new branch to work in. It's important that each group of changes be done in separate branches in order to ensure that a pull request only includes the commits related to that bug or feature. + +3. Any significant changes should almost always be accompanied by tests. The project already has some test coverage, so look at some of the existing tests if you're unsure how to go about it. + +4. Run `make pr-prep` to format your code and check that it passes all tests and linters. + +5. Do your best to have [well-formed commit messages](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) for each change. This provides consistency throughout the project, and ensures that commit messages are able to be formatted properly by various git tools. _Pull Request Titles_ should generally follow the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format to ease the release note process when cutting releases. + +6. Finally, push the commits to your fork and submit a [pull request](https://help.github.com/articles/creating-a-pull-request). NOTE: Please do not use force-push on PRs in this repo, as it makes it more difficult for reviewers to see what has changed since the last code review. We always perform "squash and merge" actions on PRs in this repo, so it doesn't matter how many commits your PR has, as they will end up being a single commit after merging. This is done to make a much cleaner `git log` history and helps to find regressions in the code using existing tools such as `git bisect`. + +## Code Comments + +Every exported method needs to have code comments that follow [Go Doc Comments](https://go.dev/doc/comment). A typical method's comments will look like this: + +```go +// PostMessage sends a message to a channel. +// +// Slack API docs: https://api.dev.slack.com/methods/chat.postMessage +func (api *Client) PostMessage(ctx context.Context, input PostMesssageInput) (PostMesssageOutput, error) { +... +} +``` + +The first line is the name of the method followed by a short description. This could also be a longer description if needed, but there is no need to repeat any details that are documented in Slack's documentation because users are expected to follow the documentation links to learn more. + +After the description comes a link to the Slack API documentation. + +## Other notes on code organization + +Currently, everything is defined in the main `slack` package, with API methods group separate files by the [Slack API Method Groupings](https://api.dev.slack.com/methods). diff --git a/README.md b/README.md index 9618aebc..7d9733e1 100644 --- a/README.md +++ b/README.md @@ -15,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) or [Releases](https://github.com/slack-go/slack/releases) for more information about the changes. +See [Releases](https://github.com/slack-go/slack/releases) for more information about the changes. ## Installing diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 8607960b..00000000 --- a/TODO.txt +++ /dev/null @@ -1,3 +0,0 @@ -- Add more tests!!! -- Add support to have markdown hints - - See section Message Formatting at https://api.slack.com/docs/formatting