Bumps the go-modules-updates group in /backend with 9 updates: | Package | From | To | | --- | --- | --- | | [github.com/PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery) | `1.9.2` | `1.10.0` | | [github.com/alecthomas/chroma/v2](https://github.com/alecthomas/chroma) | `2.13.0` | `2.14.0` | | [github.com/go-pkgz/notify](https://github.com/go-pkgz/notify) | `1.1.1` | `1.2.0` | | [github.com/go-pkgz/repeater](https://github.com/go-pkgz/repeater) | `1.1.3` | `1.2.0` | | [github.com/rs/xid](https://github.com/rs/xid) | `1.5.0` | `1.6.0` | | [go.etcd.io/bbolt](https://github.com/etcd-io/bbolt) | `1.3.10` | `1.3.11` | | [golang.org/x/crypto](https://github.com/golang/crypto) | `0.25.0` | `0.27.0` | | [golang.org/x/image](https://github.com/golang/image) | `0.18.0` | `0.22.0` | | [golang.org/x/net](https://github.com/golang/net) | `0.27.0` | `0.29.0` | Updates `github.com/PuerkitoBio/goquery` from 1.9.2 to 1.10.0 - [Release notes](https://github.com/PuerkitoBio/goquery/releases) - [Commits](https://github.com/PuerkitoBio/goquery/compare/v1.9.2...v1.10.0) Updates `github.com/alecthomas/chroma/v2` from 2.13.0 to 2.14.0 - [Release notes](https://github.com/alecthomas/chroma/releases) - [Changelog](https://github.com/alecthomas/chroma/blob/master/.goreleaser.yml) - [Commits](https://github.com/alecthomas/chroma/compare/v2.13.0...v2.14.0) Updates `github.com/go-pkgz/notify` from 1.1.1 to 1.2.0 - [Release notes](https://github.com/go-pkgz/notify/releases) - [Commits](https://github.com/go-pkgz/notify/compare/v1.1.1...v1.2.0) Updates `github.com/go-pkgz/repeater` from 1.1.3 to 1.2.0 - [Release notes](https://github.com/go-pkgz/repeater/releases) - [Commits](https://github.com/go-pkgz/repeater/compare/v1.1.3...v1.2.0) Updates `github.com/rs/xid` from 1.5.0 to 1.6.0 - [Release notes](https://github.com/rs/xid/releases) - [Commits](https://github.com/rs/xid/compare/v1.5.0...v1.6.0) Updates `go.etcd.io/bbolt` from 1.3.10 to 1.3.11 - [Release notes](https://github.com/etcd-io/bbolt/releases) - [Commits](https://github.com/etcd-io/bbolt/compare/v1.3.10...v1.3.11) Updates `golang.org/x/crypto` from 0.25.0 to 0.27.0 - [Commits](https://github.com/golang/crypto/compare/v0.25.0...v0.27.0) Updates `golang.org/x/image` from 0.18.0 to 0.22.0 - [Commits](https://github.com/golang/image/compare/v0.18.0...v0.22.0) Updates `golang.org/x/net` from 0.27.0 to 0.29.0 - [Commits](https://github.com/golang/net/compare/v0.27.0...v0.29.0) --- updated-dependencies: - dependency-name: github.com/PuerkitoBio/goquery dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/alecthomas/chroma/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/notify dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/repeater dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/rs/xid dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: go.etcd.io/bbolt dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: golang.org/x/image dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates ... Signed-off-by: dependabot[bot] <support@github.com>
283 lines
7.3 KiB
Go
283 lines
7.3 KiB
Go
package slack
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strconv"
|
|
)
|
|
|
|
// ItemReaction is the reactions that have happened on an item.
|
|
type ItemReaction struct {
|
|
Name string `json:"name"`
|
|
Count int `json:"count"`
|
|
Users []string `json:"users"`
|
|
}
|
|
|
|
// ReactedItem is an item that was reacted to, and the details of the
|
|
// reactions.
|
|
type ReactedItem struct {
|
|
Item
|
|
Reactions []ItemReaction
|
|
}
|
|
|
|
// GetReactionsParameters is the inputs to get reactions to an item.
|
|
type GetReactionsParameters struct {
|
|
Full bool
|
|
}
|
|
|
|
// NewGetReactionsParameters initializes the inputs to get reactions to an item.
|
|
func NewGetReactionsParameters() GetReactionsParameters {
|
|
return GetReactionsParameters{
|
|
Full: false,
|
|
}
|
|
}
|
|
|
|
type getReactionsResponseFull struct {
|
|
Type string
|
|
M struct {
|
|
Reactions []ItemReaction
|
|
} `json:"message"`
|
|
F struct {
|
|
Reactions []ItemReaction
|
|
} `json:"file"`
|
|
FC struct {
|
|
Reactions []ItemReaction
|
|
} `json:"comment"`
|
|
SlackResponse
|
|
}
|
|
|
|
func (res getReactionsResponseFull) extractReactions() []ItemReaction {
|
|
switch res.Type {
|
|
case "message":
|
|
return res.M.Reactions
|
|
case "file":
|
|
return res.F.Reactions
|
|
case "file_comment":
|
|
return res.FC.Reactions
|
|
}
|
|
return []ItemReaction{}
|
|
}
|
|
|
|
const (
|
|
DEFAULT_REACTIONS_USER = ""
|
|
DEFAULT_REACTIONS_COUNT = 100
|
|
DEFAULT_REACTIONS_PAGE = 1
|
|
DEFAULT_REACTIONS_FULL = false
|
|
)
|
|
|
|
// ListReactionsParameters is the inputs to find all reactions by a user.
|
|
type ListReactionsParameters struct {
|
|
User string
|
|
TeamID string
|
|
Count int
|
|
Page int
|
|
Full bool
|
|
}
|
|
|
|
// NewListReactionsParameters initializes the inputs to find all reactions
|
|
// performed by a user.
|
|
func NewListReactionsParameters() ListReactionsParameters {
|
|
return ListReactionsParameters{
|
|
User: DEFAULT_REACTIONS_USER,
|
|
Count: DEFAULT_REACTIONS_COUNT,
|
|
Page: DEFAULT_REACTIONS_PAGE,
|
|
Full: DEFAULT_REACTIONS_FULL,
|
|
}
|
|
}
|
|
|
|
type listReactionsResponseFull struct {
|
|
Items []struct {
|
|
Type string
|
|
Channel string
|
|
M struct {
|
|
*Message
|
|
} `json:"message"`
|
|
F struct {
|
|
*File
|
|
Reactions []ItemReaction
|
|
} `json:"file"`
|
|
FC struct {
|
|
*Comment
|
|
Reactions []ItemReaction
|
|
} `json:"comment"`
|
|
}
|
|
Paging `json:"paging"`
|
|
SlackResponse
|
|
}
|
|
|
|
func (res listReactionsResponseFull) extractReactedItems() []ReactedItem {
|
|
items := make([]ReactedItem, len(res.Items))
|
|
for i, input := range res.Items {
|
|
item := ReactedItem{}
|
|
item.Type = input.Type
|
|
switch input.Type {
|
|
case "message":
|
|
item.Channel = input.Channel
|
|
item.Message = input.M.Message
|
|
item.Reactions = input.M.Reactions
|
|
case "file":
|
|
item.File = input.F.File
|
|
item.Reactions = input.F.Reactions
|
|
case "file_comment":
|
|
item.File = input.F.File
|
|
item.Comment = input.FC.Comment
|
|
item.Reactions = input.FC.Reactions
|
|
}
|
|
items[i] = item
|
|
}
|
|
return items
|
|
}
|
|
|
|
// AddReaction adds a reaction emoji to a message, file or file comment.
|
|
// For more details, see AddReactionContext documentation.
|
|
func (api *Client) AddReaction(name string, item ItemRef) error {
|
|
return api.AddReactionContext(context.Background(), name, item)
|
|
}
|
|
|
|
// AddReactionContext adds a reaction emoji to a message, file or file comment with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/reactions.add
|
|
func (api *Client) AddReactionContext(ctx context.Context, name string, item ItemRef) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
if name != "" {
|
|
values.Set("name", name)
|
|
}
|
|
if item.Channel != "" {
|
|
values.Set("channel", item.Channel)
|
|
}
|
|
if item.Timestamp != "" {
|
|
values.Set("timestamp", item.Timestamp)
|
|
}
|
|
if item.File != "" {
|
|
values.Set("file", item.File)
|
|
}
|
|
if item.Comment != "" {
|
|
values.Set("file_comment", item.Comment)
|
|
}
|
|
|
|
response := &SlackResponse{}
|
|
if err := api.postMethod(ctx, "reactions.add", values, response); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// RemoveReaction removes a reaction emoji from a message, file or file comment.
|
|
// For more details, see RemoveReactionContext documentation.
|
|
func (api *Client) RemoveReaction(name string, item ItemRef) error {
|
|
return api.RemoveReactionContext(context.Background(), name, item)
|
|
}
|
|
|
|
// RemoveReactionContext removes a reaction emoji from a message, file or file comment with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/reactions.remove
|
|
func (api *Client) RemoveReactionContext(ctx context.Context, name string, item ItemRef) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
if name != "" {
|
|
values.Set("name", name)
|
|
}
|
|
if item.Channel != "" {
|
|
values.Set("channel", item.Channel)
|
|
}
|
|
if item.Timestamp != "" {
|
|
values.Set("timestamp", item.Timestamp)
|
|
}
|
|
if item.File != "" {
|
|
values.Set("file", item.File)
|
|
}
|
|
if item.Comment != "" {
|
|
values.Set("file_comment", item.Comment)
|
|
}
|
|
|
|
response := &SlackResponse{}
|
|
if err := api.postMethod(ctx, "reactions.remove", values, response); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Err()
|
|
}
|
|
|
|
// GetReactions returns details about the reactions on an item.
|
|
// For more details, see GetReactionsContext documentation.
|
|
func (api *Client) GetReactions(item ItemRef, params GetReactionsParameters) ([]ItemReaction, error) {
|
|
return api.GetReactionsContext(context.Background(), item, params)
|
|
}
|
|
|
|
// GetReactionsContext returns details about the reactions on an item with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/reactions.get
|
|
func (api *Client) GetReactionsContext(ctx context.Context, item ItemRef, params GetReactionsParameters) ([]ItemReaction, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
if item.Channel != "" {
|
|
values.Set("channel", item.Channel)
|
|
}
|
|
if item.Timestamp != "" {
|
|
values.Set("timestamp", item.Timestamp)
|
|
}
|
|
if item.File != "" {
|
|
values.Set("file", item.File)
|
|
}
|
|
if item.Comment != "" {
|
|
values.Set("file_comment", item.Comment)
|
|
}
|
|
if params.Full != DEFAULT_REACTIONS_FULL {
|
|
values.Set("full", strconv.FormatBool(params.Full))
|
|
}
|
|
|
|
response := &getReactionsResponseFull{}
|
|
if err := api.postMethod(ctx, "reactions.get", values, response); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := response.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return response.extractReactions(), nil
|
|
}
|
|
|
|
// ListReactions returns information about the items a user reacted to.
|
|
// For more details, see ListReactionsContext documentation.
|
|
func (api *Client) ListReactions(params ListReactionsParameters) ([]ReactedItem, *Paging, error) {
|
|
return api.ListReactionsContext(context.Background(), params)
|
|
}
|
|
|
|
// ListReactionsContext returns information about the items a user reacted to with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/reactions.list
|
|
func (api *Client) ListReactionsContext(ctx context.Context, params ListReactionsParameters) ([]ReactedItem, *Paging, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
if params.User != DEFAULT_REACTIONS_USER {
|
|
values.Add("user", params.User)
|
|
}
|
|
if params.TeamID != "" {
|
|
values.Add("team_id", params.TeamID)
|
|
}
|
|
if params.Count != DEFAULT_REACTIONS_COUNT {
|
|
values.Add("count", strconv.Itoa(params.Count))
|
|
}
|
|
if params.Page != DEFAULT_REACTIONS_PAGE {
|
|
values.Add("page", strconv.Itoa(params.Page))
|
|
}
|
|
if params.Full != DEFAULT_REACTIONS_FULL {
|
|
values.Add("full", strconv.FormatBool(params.Full))
|
|
}
|
|
|
|
response := &listReactionsResponseFull{}
|
|
err := api.postMethod(ctx, "reactions.list", values, response)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
if err := response.Err(); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return response.extractReactedItems(), &response.Paging, nil
|
|
}
|