slack

package
v0.0.0-...-f58e54c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddToSlackButton contains the HTML to create the appropriate "Add To Slack" button for this application.
	AddToSlackButton = `` /* 251-byte string literal not displayed */

)

Variables

View Source
var (
	// ClientID is the ID issued to this app by Slack.
	ClientID = flag.String("slack-client-id", "13639549360.893676519079", "ID issued to this app by Slack")
	// ClientSecret is the secret issued to this app by Slack.
	ClientSecret = flag.String("slack-client-secret", "", "Client secret issued to this app by Slack")
	// SigningSecret is the signing secret issued to this app by Slack.
	SigningSecret = flag.String("slack-signing-secret", "", "Signing secret issued to this app by Slack")
)
View Source
var ErrStopTeam = errors.New("stop this team")

ErrStopTeam is returned by HandleEvent when the app has been uninstalled from that team.

View Source
var ErrVerifyFailed = errors.New("verify error")

ErrVerifyFailed is the error returned when a request can not be verified as coming from the chat system.

Functions

func AssembleSlackAuthURL

func AssembleSlackAuthURL(redirectURL string) string

AssembleSlackAuthURL assembles a slack auth URL with the necessary client ID, scopes, user scopes, and redirect URI.

func GetOAuthV2Token

func GetOAuthV2Token(ctx context.Context, clientID, clientSecret, code, redirectURI string) (resp *slack.OAuthV2Response, err error)

GetOAuthV2Token issues a call to Slack to get a OAuth V2 token.

func HandleNoTeamEvent

func HandleNoTeamEvent(ctx context.Context, event ChatEvent) (responseBytes []byte)

HandleNoTeamEvent is called when a Slack event is received that is not associated with a specific team.

Types

type BadEvent

type BadEvent struct {
	// contains filtered or unexported fields
}

BadEvent is an error type returned when a request from the chat system can not be parsed.

func (*BadEvent) Error

func (e *BadEvent) Error() string

Error returns the text of the error.

type ChatEvent

type ChatEvent struct {
	// contains filtered or unexported fields
}

ChatEvent encapsulates a chat system event, to avoid leaking Slack implementation details.

func VerifyEventMessage

func VerifyEventMessage(header http.Header, messageBody []byte) (ev ChatEvent, teamID string, err error)

VerifyEventMessage verifies an incoming request as being a valid event from Slack.

type EventedChatSystem

type EventedChatSystem interface {
	messages.ChatSystem

	HandleEvent(ctx context.Context, event ChatEvent) error
}

EventedChatSystem is the interface implemented by chat systems that have events to process.

func NewSlackInterface

func NewSlackInterface(logger *zap.Logger, setupData string) (EventedChatSystem, error)

NewSlackInterface creates an EventedChatSystem instance for a Slack server.

type Formatter

type Formatter struct{}

Formatter defines how messages can be formatted on Slack.

func (*Formatter) FormatBlockQuote

func (f *Formatter) FormatBlockQuote(msg string) string

FormatBlockQuote formats a message (line or paragraph) as a block quote, according to Slack syntax.

func (*Formatter) FormatBold

func (f *Formatter) FormatBold(msg string) string

FormatBold formats a message as bold according to Slack syntax.

func (f *Formatter) FormatChangeLink(project string, number int, url, subject string) string

FormatChangeLink formats a link to a Gerrit change according to Slack syntax.

func (f *Formatter) FormatChannelLink(channelID string) string

FormatChannelLink formats a reference to a channel ID.

func (*Formatter) FormatCode

func (f *Formatter) FormatCode(text string) string

FormatCode formats text as fixed-width (like a code listing) according to Slack syntax.

func (*Formatter) FormatItalic

func (f *Formatter) FormatItalic(msg string) string

FormatItalic formats a message in italics according to Slack syntax.

func (f *Formatter) FormatLink(url, text string) string

FormatLink formats an arbitrary link with the given text according to Slack syntax.

func (f *Formatter) FormatUserLink(chatID string) string

FormatUserLink formats a reference to a user chat ID.

func (f *Formatter) UnwrapChannelLink(channelLink string) string

UnwrapChannelLink accepts a formatted channel link and returns the associated channel ID.

func (f *Formatter) UnwrapLink(link string) string

UnwrapLink accepts a formatted link and returns the associated URL.

func (f *Formatter) UnwrapUserLink(userLink string) string

UnwrapUserLink accepts a formatted user link and returns the chat ID of the associated user.

type OAuthV2Response

type OAuthV2Response struct {
	AccessToken string              `json:"access_token"`
	TokenType   string              `json:"token_type"`
	Scope       string              `json:"scope"`
	BotUserID   string              `json:"bot_user_id"`
	AppID       string              `json:"app_id"`
	Team        OAuthV2ResponseTeam `json:"team"`
	Enterprise  OAuthV2ResponseTeam `json:"enterprise"`
	AuthedUser  OAuthV2ResponseUser `json:"authed_user"`
	slack.SlackResponse
}

OAuthV2Response is the structure of the JSON Slack provides as OAuth authentication for a team.

type OAuthV2ResponseTeam

type OAuthV2ResponseTeam struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

OAuthV2ResponseTeam is the structure of a team definition as returned by Slack as part of an OAuthV2Response.

type OAuthV2ResponseUser

type OAuthV2ResponseUser struct {
	ID          string `json:"id"`
	Scope       string `json:"scope"`
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
}

OAuthV2ResponseUser is the structure of a user definition as returned by Slack as part of an OAuthV2Response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL