Skip to content

Commit

Permalink
Merge branch 'slack-go:master' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq authored Nov 17, 2024
2 parents d9b6e02 + e764011 commit 2780847
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 190 deletions.
103 changes: 0 additions & 103 deletions CHANGELOG.md

This file was deleted.

40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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

Expand Down
3 changes: 0 additions & 3 deletions TODO.txt

This file was deleted.

157 changes: 157 additions & 0 deletions assistant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package slack

import (
"context"
"encoding/json"
"net/url"
)

// AssistantThreadSetStatusParameters are the parameters for AssistantThreadSetStatus
type AssistantThreadsSetStatusParameters struct {
ChannelID string `json:"channel_id"`
Status string `json:"status"`
ThreadTS string `json:"thread_ts"`
}

// AssistantThreadSetTitleParameters are the parameters for AssistantThreadSetTitle
type AssistantThreadsSetTitleParameters struct {
ChannelID string `json:"channel_id"`
ThreadTS string `json:"thread_ts"`
Title string `json:"title"`
}

// AssistantThreadSetSuggestedPromptsParameters are the parameters for AssistantThreadSetSuggestedPrompts
type AssistantThreadsSetSuggestedPromptsParameters struct {
Title string `json:"title"`
ChannelID string `json:"channel_id"`
ThreadTS string `json:"thread_ts"`
Prompts []AssistantThreadsPrompt `json:"prompts"`
}

// AssistantThreadPrompt is a suggested prompt for a thread
type AssistantThreadsPrompt struct {
Title string `json:"title"`
Message string `json:"message"`
}

// AssistantThreadSetSuggestedPrompts sets the suggested prompts for a thread
func (p *AssistantThreadsSetSuggestedPromptsParameters) AddPrompt(title, message string) {
p.Prompts = append(p.Prompts, AssistantThreadsPrompt{
Title: title,
Message: message,
})
}

// SetAssistantThreadsSugesstedPrompts sets the suggested prompts for a thread
// @see https://api.slack.com/methods/assistant.threads.setSuggestedPrompts
func (api *Client) SetAssistantThreadsSuggestedPrompts(params AssistantThreadsSetSuggestedPromptsParameters) (err error) {
return api.SetAssistantThreadsSuggestedPromptsContext(context.Background(), params)
}

// SetAssistantThreadSuggestedPromptsContext sets the suggested prompts for a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setSuggestedPrompts
func (api *Client) SetAssistantThreadsSuggestedPromptsContext(ctx context.Context, params AssistantThreadsSetSuggestedPromptsParameters) (err error) {

values := url.Values{
"token": {api.token},
}

if params.ThreadTS != "" {
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 {
return err
}

values.Add("prompts", string(prompts))

response := struct {
SlackResponse
}{}

err = api.postMethod(ctx, "assistant.threads.setSuggestedPrompts", values, &response)
if err != nil {
return
}

return response.Err()
}

// SetAssistantThreadStatus sets the status of a thread
// @see https://api.slack.com/methods/assistant.threads.setStatus
func (api *Client) SetAssistantThreadsStatus(params AssistantThreadsSetStatusParameters) (err error) {
return api.SetAssistantThreadsStatusContext(context.Background(), params)
}

// SetAssistantThreadStatusContext sets the status of a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setStatus
func (api *Client) SetAssistantThreadsStatusContext(ctx context.Context, params AssistantThreadsSetStatusParameters) (err error) {

values := url.Values{
"token": {api.token},
}

if params.ThreadTS != "" {
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)

response := struct {
SlackResponse
}{}

err = api.postMethod(ctx, "assistant.threads.setStatus", values, &response)
if err != nil {
return
}

return response.Err()
}

// SetAssistantThreadsTitle sets the title of a thread
// @see https://api.slack.com/methods/assistant.threads.setTitle
func (api *Client) SetAssistantThreadsTitle(params AssistantThreadsSetTitleParameters) (err error) {
return api.SetAssistantThreadsTitleContext(context.Background(), params)
}

// SetAssistantThreadsTitleContext sets the title of a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setTitle
func (api *Client) SetAssistantThreadsTitleContext(ctx context.Context, params AssistantThreadsSetTitleParameters) (err error) {

values := url.Values{
"token": {api.token},
}

if params.ChannelID != "" {
values.Add("channel_id", params.ChannelID)
}

if params.ThreadTS != "" {
values.Add("thread_ts", params.ThreadTS)
}

if params.Title != "" {
values.Add("title", params.Title)
}

response := struct {
SlackResponse
}{}

err = api.postMethod(ctx, "assistant.threads.setTitle", values, &response)
if err != nil {
return
}

return response.Err()

}
Loading

0 comments on commit 2780847

Please sign in to comment.