4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-03 18:57:45 +00:00

Update vendor (#1384)

This commit is contained in:
Wim
2021-02-01 21:29:04 +01:00
committed by GitHub
parent 1624f10773
commit 0452be0cb3
37 changed files with 1539 additions and 244 deletions

View File

@ -1,14 +0,0 @@
{
"DisableAll": true,
"Enable": [
"structcheck",
"vet",
"misspell",
"unconvert",
"interfacer",
"goimports"
],
"Vendor": true,
"Exclude": ["vendor"],
"Deadline": "300s"
}

View File

@ -3,6 +3,7 @@ package slack
import (
"context"
"encoding/json"
"net/url"
)
type listEventAuthorizationsResponse struct {
@ -41,3 +42,20 @@ func (api *Client) ListEventAuthorizationsContext(ctx context.Context, eventCont
return resp.Authorizations, nil
}
func (api *Client) UninstallApp(clientID, clientSecret string) error {
values := url.Values{
"token": {api.token},
"client_id": {clientID},
"client_secret": {clientSecret},
}
response := SlackResponse{}
err := api.getMethod(context.Background(), "apps.uninstall", values, &response)
if err != nil {
return err
}
return response.Err()
}

View File

@ -48,11 +48,13 @@ type BlockAction struct {
SelectedConversation string `json:"selected_conversation"`
SelectedConversations []string `json:"selected_conversations"`
SelectedDate string `json:"selected_date"`
SelectedTime string `json:"selected_time"`
InitialOption OptionBlockObject `json:"initial_option"`
InitialUser string `json:"initial_user"`
InitialChannel string `json:"initial_channel"`
InitialConversation string `json:"initial_conversation"`
InitialDate string `json:"initial_date"`
InitialTime string `json:"initial_time"`
}
// actionType returns the type of the action

View File

@ -59,6 +59,8 @@ func (b *Blocks) UnmarshalJSON(data []byte) error {
block = &DividerBlock{}
case "file":
block = &FileBlock{}
case "header":
block = &HeaderBlock{}
case "image":
block = &ImageBlock{}
case "input":
@ -105,6 +107,8 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
switch s.TypeVal {
case "datepicker":
e = &DatePickerBlockElement{}
case "timepicker":
e = &TimePickerBlockElement{}
case "plain_text_input":
e = &PlainTextInputBlockElement{}
case "static_select", "external_select", "users_select", "conversations_select", "channels_select":
@ -262,6 +266,12 @@ func (a *Accessory) UnmarshalJSON(data []byte) error {
return err
}
a.DatePickerElement = element.(*DatePickerBlockElement)
case "timepicker":
element, err := unmarshalBlockElement(r, &TimePickerBlockElement{})
if err != nil {
return err
}
a.TimePickerElement = element.(*TimePickerBlockElement)
case "plain_text_input":
element, err := unmarshalBlockElement(r, &PlainTextInputBlockElement{})
if err != nil {
@ -324,6 +334,9 @@ func toBlockElement(element *Accessory) BlockElement {
if element.DatePickerElement != nil {
return element.DatePickerElement
}
if element.TimePickerElement != nil {
return element.TimePickerElement
}
if element.PlainTextInputElement != nil {
return element.PlainTextInputElement
}

View File

@ -8,6 +8,7 @@ const (
METButton MessageElementType = "button"
METOverflow MessageElementType = "overflow"
METDatepicker MessageElementType = "datepicker"
METTimepicker MessageElementType = "timepicker"
METPlainTextInput MessageElementType = "plain_text_input"
METRadioButtons MessageElementType = "radio_buttons"
@ -44,6 +45,7 @@ type Accessory struct {
ButtonElement *ButtonBlockElement
OverflowElement *OverflowBlockElement
DatePickerElement *DatePickerBlockElement
TimePickerElement *TimePickerBlockElement
PlainTextInputElement *PlainTextInputBlockElement
RadioButtonsElement *RadioButtonsBlockElement
SelectElement *SelectBlockElement
@ -63,6 +65,8 @@ func NewAccessory(element BlockElement) *Accessory {
return &Accessory{OverflowElement: element.(*OverflowBlockElement)}
case *DatePickerBlockElement:
return &Accessory{DatePickerElement: element.(*DatePickerBlockElement)}
case *TimePickerBlockElement:
return &Accessory{TimePickerElement: element.(*TimePickerBlockElement)}
case *PlainTextInputBlockElement:
return &Accessory{PlainTextInputElement: element.(*PlainTextInputBlockElement)}
case *RadioButtonsBlockElement:
@ -127,10 +131,12 @@ func NewImageBlockElement(imageURL, altText string) *ImageBlockElement {
}
}
// Style is a style of Button element
// https://api.slack.com/reference/block-kit/block-elements#button__fields
type Style string
const (
StyleDefault Style = "default"
StyleDefault Style = ""
StylePrimary Style = "primary"
StyleDanger Style = "danger"
)
@ -155,7 +161,7 @@ func (s ButtonBlockElement) ElementType() MessageElementType {
return s.Type
}
// WithStyling adds styling to the button object and returns the modified ButtonBlockElement
// WithStyle adds styling to the button object and returns the modified ButtonBlockElement
func (s *ButtonBlockElement) WithStyle(style Style) *ButtonBlockElement {
s.Style = style
return s
@ -350,6 +356,32 @@ func NewDatePickerBlockElement(actionID string) *DatePickerBlockElement {
}
}
// TimePickerBlockElement defines an element which lets users easily select a
// time from nice UI. Time picker elements can be used inside of
// section and actions blocks.
//
// More Information: https://api.slack.com/reference/messaging/block-elements#timepicker
type TimePickerBlockElement struct {
Type MessageElementType `json:"type"`
ActionID string `json:"action_id,omitempty"`
Placeholder *TextBlockObject `json:"placeholder,omitempty"`
InitialTime string `json:"initial_time,omitempty"`
Confirm *ConfirmationBlockObject `json:"confirm,omitempty"`
}
// ElementType returns the type of the Element
func (s TimePickerBlockElement) ElementType() MessageElementType {
return s.Type
}
// NewTimePickerBlockElement returns an instance of a date picker element
func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement {
return &TimePickerBlockElement{
Type: METTimepicker,
ActionID: actionID,
}
}
// PlainTextInputBlockElement creates a field where a user can enter freeform
// data.
// Plain-text input elements are currently only available in modals.

View File

@ -171,7 +171,7 @@ func (s ConfirmationBlockObject) validateType() MessageObjectType {
return motConfirmation
}
// add styling to confirmation object
// WithStyle add styling to confirmation object
func (s *ConfirmationBlockObject) WithStyle(style Style) {
s.Style = style
}

View File

@ -191,6 +191,22 @@ func (api *Client) UnfurlMessage(channelID, timestamp string, unfurls map[string
return api.SendMessageContext(context.Background(), channelID, MsgOptionUnfurl(timestamp, unfurls), MsgOptionCompose(options...))
}
// UnfurlMessageWithAuthURL sends an unfurl request containing an
// authentication URL.
// For more details see:
// https://api.slack.com/reference/messaging/link-unfurling#authenticated_unfurls
func (api *Client) UnfurlMessageWithAuthURL(channelID, timestamp string, userAuthURL string, options ...MsgOption) (string, string, string, error) {
return api.UnfurlMessageWithAuthURLContext(context.Background(), channelID, timestamp, userAuthURL, options...)
}
// UnfurlMessageWithAuthURLContext sends an unfurl request containing an
// authentication URL.
// For more details see:
// https://api.slack.com/reference/messaging/link-unfurling#authenticated_unfurls
func (api *Client) UnfurlMessageWithAuthURLContext(ctx context.Context, channelID, timestamp string, userAuthURL string, options ...MsgOption) (string, string, string, error) {
return api.SendMessageContext(ctx, channelID, MsgOptionUnfurlAuthURL(timestamp, userAuthURL), MsgOptionCompose(options...))
}
// SendMessage more flexible method for configuring messages.
func (api *Client) SendMessage(channel string, options ...MsgOption) (string, string, string, error) {
return api.SendMessageContext(context.Background(), channel, options...)
@ -413,6 +429,38 @@ func MsgOptionUnfurl(timestamp string, unfurls map[string]Attachment) MsgOption
}
}
// MsgOptionUnfurlAuthURL unfurls a message using an auth url based on the timestamp.
func MsgOptionUnfurlAuthURL(timestamp string, userAuthURL string) MsgOption {
return func(config *sendConfig) error {
config.endpoint = config.apiurl + string(chatUnfurl)
config.values.Add("ts", timestamp)
config.values.Add("user_auth_url", userAuthURL)
return nil
}
}
// MsgOptionUnfurlAuthRequired requests that the user installs the
// Slack app for unfurling.
func MsgOptionUnfurlAuthRequired(timestamp string) MsgOption {
return func(config *sendConfig) error {
config.endpoint = config.apiurl + string(chatUnfurl)
config.values.Add("ts", timestamp)
config.values.Add("user_auth_required", "true")
return nil
}
}
// MsgOptionUnfurlAuthMessage attaches a message inviting the user to
// authenticate.
func MsgOptionUnfurlAuthMessage(timestamp string, msg string) MsgOption {
return func(config *sendConfig) error {
config.endpoint = config.apiurl + string(chatUnfurl)
config.values.Add("ts", timestamp)
config.values.Add("user_auth_message", msg)
return nil
}
}
// MsgOptionResponseURL supplies a url to use as the endpoint.
func MsgOptionResponseURL(url string, responseType string) MsgOption {
return func(config *sendConfig) error {

View File

@ -1,4 +1,4 @@
package slack
package backoff
import (
"math/rand"
@ -11,7 +11,7 @@ import (
// call to Duration() it is multiplied by Factor. It is capped at
// Max. It returns to Min on every call to Reset(). Used in
// conjunction with the time package.
type backoff struct {
type Backoff struct {
attempts int
// Initial value to scale out
Initial time.Duration
@ -23,7 +23,7 @@ type backoff struct {
// Returns the current value of the counter and then multiplies it
// Factor
func (b *backoff) Duration() (dur time.Duration) {
func (b *Backoff) Duration() (dur time.Duration) {
// Zero-values are nonsensical, so we use
// them to apply defaults
if b.Max == 0 {
@ -52,6 +52,11 @@ func (b *backoff) Duration() (dur time.Duration) {
}
//Resets the current value of the counter back to Min
func (b *backoff) Reset() {
func (b *Backoff) Reset() {
b.attempts = 0
}
// Attempts returns the number of attempts that we had done so far
func (b *Backoff) Attempts() int {
return b.attempts
}

28
vendor/github.com/slack-go/slack/internal/misc/misc.go generated vendored Normal file
View File

@ -0,0 +1,28 @@
package misc
import (
"fmt"
"net/http"
)
// StatusCodeError represents an http response error.
// type httpStatusCode interface { HTTPStatusCode() int } to handle it.
type StatusCodeError struct {
Code int
Status string
}
func (t StatusCodeError) Error() string {
return fmt.Sprintf("slack server error: %s", t.Status)
}
func (t StatusCodeError) HTTPStatusCode() int {
return t.Code
}
func (t StatusCodeError) Retryable() bool {
if t.Code >= 500 || t.Code == http.StatusTooManyRequests {
return true
}
return false
}

View File

@ -18,6 +18,8 @@ import (
"strconv"
"strings"
"time"
"github.com/slack-go/slack/internal/misc"
)
// SlackResponse handles parsing out errors from the web api.
@ -42,28 +44,6 @@ func (t SlackResponse) Err() error {
return errors.New(t.Error)
}
// StatusCodeError represents an http response error.
// type httpStatusCode interface { HTTPStatusCode() int } to handle it.
type statusCodeError struct {
Code int
Status string
}
func (t statusCodeError) Error() string {
return fmt.Sprintf("slack server error: %s", t.Status)
}
func (t statusCodeError) HTTPStatusCode() int {
return t.Code
}
func (t statusCodeError) Retryable() bool {
if t.Code >= 500 || t.Code == http.StatusTooManyRequests {
return true
}
return false
}
// RateLimitedError represents the rate limit respond from slack
type RateLimitedError struct {
RetryAfter time.Duration
@ -312,7 +292,7 @@ func checkStatusCode(resp *http.Response, d Debug) error {
// Slack seems to send an HTML body along with 5xx error codes. Don't parse it.
if resp.StatusCode != http.StatusOK {
logResponse(resp, d)
return statusCodeError{Code: resp.StatusCode, Status: resp.Status}
return misc.StatusCodeError{Code: resp.StatusCode, Status: resp.Status}
}
return nil

34
vendor/github.com/slack-go/slack/socket_mode.go generated vendored Normal file
View File

@ -0,0 +1,34 @@
package slack
import (
"context"
)
// SocketModeConnection contains various details about the SocketMode connection.
// It is returned by an "apps.connections.open" API call.
type SocketModeConnection struct {
URL string `json:"url,omitempty"`
Data map[string]interface{} `json:"-"`
}
type openResponseFull struct {
SlackResponse
SocketModeConnection
}
// StartSocketModeContext calls the "apps.connections.open" endpoint and returns the provided URL and the full Info block with a custom context.
//
// To have a fully managed Socket Mode connection, use `socketmode.New()`, and call `Run()` on it.
func (api *Client) StartSocketModeContext(ctx context.Context) (info *SocketModeConnection, websocketURL string, err error) {
response := &openResponseFull{}
err = postJSON(ctx, api.httpclient, api.endpoint+"apps.connections.open", api.appLevelToken, nil, response, api)
if err != nil {
return nil, "", err
}
if response.Err() == nil {
api.Debugln("Using URL:", response.SocketModeConnection.URL)
}
return &response.SocketModeConnection, response.SocketModeConnection.URL, response.Err()
}

View File

@ -31,6 +31,7 @@ type UserProfile struct {
Image48 string `json:"image_48"`
Image72 string `json:"image_72"`
Image192 string `json:"image_192"`
Image512 string `json:"image_512"`
ImageOriginal string `json:"image_original"`
Title string `json:"title"`
BotID string `json:"bot_id,omitempty"`

View File

@ -9,6 +9,9 @@ import (
"reflect"
"time"
"github.com/slack-go/slack/internal/backoff"
"github.com/slack-go/slack/internal/misc"
"github.com/gorilla/websocket"
"github.com/slack-go/slack/internal/errorsx"
"github.com/slack-go/slack/internal/timex"
@ -92,7 +95,7 @@ func (rtm *RTM) connect(connectionCount int, useRTMStart bool) (*Info, *websocke
// used to provide exponential backoff wait time with jitter before trying
// to connect to slack again
boff := &backoff{
boff := &backoff.Backoff{
Max: 5 * time.Minute,
}
@ -103,7 +106,7 @@ func (rtm *RTM) connect(connectionCount int, useRTMStart bool) (*Info, *websocke
// send connecting event
rtm.IncomingEvents <- RTMEvent{"connecting", &ConnectingEvent{
Attempt: boff.attempts + 1,
Attempt: boff.Attempts() + 1,
ConnectionCount: connectionCount,
}}
@ -123,7 +126,7 @@ func (rtm *RTM) connect(connectionCount int, useRTMStart bool) (*Info, *websocke
}
switch actual := err.(type) {
case statusCodeError:
case misc.StatusCodeError:
if actual.Code == http.StatusNotFound {
rtm.Debugf("invalid auth when connecting with RTM: %s", err)
rtm.IncomingEvents <- RTMEvent{"invalid_auth", &InvalidAuthEvent{}}
@ -138,13 +141,13 @@ func (rtm *RTM) connect(connectionCount int, useRTMStart bool) (*Info, *websocke
// any other errors are treated as recoverable and we try again after
// sending the event along the IncomingEvents channel
rtm.IncomingEvents <- RTMEvent{"connection_error", &ConnectionErrorEvent{
Attempt: boff.attempts,
Attempt: boff.Attempts(),
Backoff: backoff,
ErrorObj: err,
}}
// get time we should wait before attempting to connect again
rtm.Debugf("reconnection %d failed: %s reconnecting in %v\n", boff.attempts, err, backoff)
rtm.Debugf("reconnection %d failed: %s reconnecting in %v\n", boff.Attempts(), err, backoff)
// wait for one of the following to occur,
// backoff duration has elapsed, killChannel is signalled, or