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>
119 lines
3.9 KiB
Go
119 lines
3.9 KiB
Go
package slack
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
)
|
|
|
|
type Reminder struct {
|
|
ID string `json:"id"`
|
|
Creator string `json:"creator"`
|
|
User string `json:"user"`
|
|
Text string `json:"text"`
|
|
Recurring bool `json:"recurring"`
|
|
Time int `json:"time"`
|
|
CompleteTS int `json:"complete_ts"`
|
|
}
|
|
|
|
type reminderResp struct {
|
|
SlackResponse
|
|
Reminder Reminder `json:"reminder"`
|
|
}
|
|
|
|
type remindersResp struct {
|
|
SlackResponse
|
|
Reminders []*Reminder `json:"reminders"`
|
|
}
|
|
|
|
func (api *Client) doReminder(ctx context.Context, path string, values url.Values) (*Reminder, error) {
|
|
response := &reminderResp{}
|
|
if err := api.postMethod(ctx, path, values, response); err != nil {
|
|
return nil, err
|
|
}
|
|
return &response.Reminder, response.Err()
|
|
}
|
|
|
|
func (api *Client) doReminders(ctx context.Context, path string, values url.Values) ([]*Reminder, error) {
|
|
response := &remindersResp{}
|
|
if err := api.postMethod(ctx, path, values, response); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// create an array of pointers to reminders
|
|
var reminders = make([]*Reminder, 0, len(response.Reminders))
|
|
reminders = append(reminders, response.Reminders...)
|
|
return reminders, response.Err()
|
|
}
|
|
|
|
// ListReminders lists all the reminders created by or for the authenticated user
|
|
// For more details, see ListRemindersContext documentation.
|
|
func (api *Client) ListReminders() ([]*Reminder, error) {
|
|
return api.ListRemindersContext(context.Background())
|
|
}
|
|
|
|
// ListRemindersContext lists all the reminders created by or for the authenticated user with a custom context.
|
|
// Slack API docs: https://api.slack.com/methods/reminders.list
|
|
func (api *Client) ListRemindersContext(ctx context.Context) ([]*Reminder, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
}
|
|
return api.doReminders(ctx, "reminders.list", values)
|
|
}
|
|
|
|
// AddChannelReminder adds a reminder for a channel.
|
|
// For more details, see AddChannelReminderContext documentation.
|
|
func (api *Client) AddChannelReminder(channelID, text, time string) (*Reminder, error) {
|
|
return api.AddChannelReminderContext(context.Background(), channelID, text, time)
|
|
}
|
|
|
|
// AddChannelReminderContext adds a reminder for a channel with a custom context
|
|
// NOTE: the ability to set reminders on a channel is currently undocumented but has been tested to work.
|
|
// Slack API docs: https://api.slack.com/methods/reminders.add
|
|
func (api *Client) AddChannelReminderContext(ctx context.Context, channelID, text, time string) (*Reminder, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"text": {text},
|
|
"time": {time},
|
|
"channel": {channelID},
|
|
}
|
|
return api.doReminder(ctx, "reminders.add", values)
|
|
}
|
|
|
|
// AddUserReminder adds a reminder for a user.
|
|
// For more details, see AddUserReminderContext documentation.
|
|
func (api *Client) AddUserReminder(userID, text, time string) (*Reminder, error) {
|
|
return api.AddUserReminderContext(context.Background(), userID, text, time)
|
|
}
|
|
|
|
// AddUserReminderContext adds a reminder for a user with a custom context
|
|
// Slack API docs: https://api.slack.com/methods/reminders.add
|
|
func (api *Client) AddUserReminderContext(ctx context.Context, userID, text, time string) (*Reminder, error) {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"text": {text},
|
|
"time": {time},
|
|
"user": {userID},
|
|
}
|
|
return api.doReminder(ctx, "reminders.add", values)
|
|
}
|
|
|
|
// DeleteReminder deletes an existing reminder.
|
|
// For more details, see DeleteReminderContext documentation.
|
|
func (api *Client) DeleteReminder(id string) error {
|
|
return api.DeleteReminderContext(context.Background(), id)
|
|
}
|
|
|
|
// DeleteReminderContext deletes an existing reminder with a custom context
|
|
// Slack API docs: https://api.slack.com/methods/reminders.delete
|
|
func (api *Client) DeleteReminderContext(ctx context.Context, id string) error {
|
|
values := url.Values{
|
|
"token": {api.token},
|
|
"reminder": {id},
|
|
}
|
|
response := &SlackResponse{}
|
|
if err := api.postMethod(ctx, "reminders.delete", values, response); err != nil {
|
|
return err
|
|
}
|
|
return response.Err()
|
|
}
|