Documentation
¶
Overview ¶
Package slack implements a slack adapter for the joe bot library.
Index ¶
- func Adapter(token string, opts ...Option) joe.Module
- func EventsAPIAdapter(listenAddr, token, verificationToken string, opts ...Option) joe.Module
- type BotAdapter
- type Config
- type EventsAPIConfig
- type EventsAPIServer
- type Option
- func WithDebug(debug bool) Option
- func WithListenPassive() Option
- func WithLogUnknownMessageTypes() Option
- func WithLogger(logger *zap.Logger) Option
- func WithMessageParams(params slack.PostMessageParameters) Option
- func WithMiddleware(mw func(next http.Handler) http.Handler) Option
- func WithReadTimeout(d time.Duration) Option
- func WithTLS(certFile, keyFile string) Option
- func WithTLSConfig(tlsConf *tls.Config) Option
- func WithTimeouts(d time.Duration) Option
- func WithWriteTimeout(d time.Duration) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Adapter ¶
Adapter returns a new BotAdapter as joe.Module.
Apart from the typical joe.ReceiveMessageEvent event, this adapter also emits the joe.UserTypingEvent. The ReceiveMessageEvent.Data field is always a pointer to the corresponding github.com/slack-go/slack.MessageEvent instance.
func EventsAPIAdapter ¶ added in v2.1.0
EventsAPIAdapter returns a new EventsAPIServer as joe.Module. If you want to use the slack RTM API instead (i.e. using web sockets), you should use the slack.Adapter(…) function instead.
Types ¶
type BotAdapter ¶
type BotAdapter struct {
// contains filtered or unexported fields
}
BotAdapter implements a joe.Adapter that reads and writes messages to and from Slack using the RTM API.
func NewAdapter ¶
func NewAdapter(ctx context.Context, conf Config) (*BotAdapter, error)
NewAdapter creates a new *BotAdapter that connects to Slack using the RTM API. Note that you will usually configure the slack adapter as joe.Module (i.e. using the Adapter function of this package).
You need to close the adapter if it has been created without error in order to release the connection to the Slack RTM API.
func (*BotAdapter) Close ¶
func (a *BotAdapter) Close() error
Close disconnects the adapter from the slack API.
func (*BotAdapter) React ¶
React implements joe.ReactionAwareAdapter by letting the bot attach the given reaction to the message.
func (*BotAdapter) RegisterAt ¶
func (a *BotAdapter) RegisterAt(brain *joe.Brain)
RegisterAt implements the joe.Adapter interface by emitting the slack API events to the given brain.
func (*BotAdapter) Send ¶
func (a *BotAdapter) Send(text, channelID string) error
Send implements joe.Adapter by sending all received text messages to the given slack channel ID.
type Config ¶
type Config struct { Token string VerificationToken string Name string Debug bool Logger *zap.Logger SlackAPIURL string // defaults to github.com/slack-go/slack.APIURL but can be changed for unit tests // SendMsgParams contains settings that are applied to all messages sent // by the BotAdapter. SendMsgParams slack.PostMessageParameters // Log unknown message types as error message for debugging. This option is // disabled by default. LogUnknownMessageTypes bool // Listen and respond to all messages not just those directed at the Bot User. ListenPassive bool // Options if you want to use the Slack Events API. Ignored on the normal RTM adapter. EventsAPI EventsAPIConfig }
Config contains the configuration of a BotAdapter.
type EventsAPIConfig ¶ added in v2.1.0
type EventsAPIConfig struct { Middleware func(next http.Handler) http.Handler ShutdownTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration TLSConf *tls.Config CertFile, KeyFile string }
EventsAPIConfig contains the configuration of an EventsAPIServer.
type EventsAPIServer ¶ added in v2.1.0
type EventsAPIServer struct { *BotAdapter // contains filtered or unexported fields }
EventsAPIServer is an adapter that receives messages from Slack using the events API. In contrast to the classical adapter, this server receives messages as HTTP requests instead of via a websocket.
See https://api.slack.com/events-api
func NewEventsAPIServer ¶ added in v2.1.0
func NewEventsAPIServer(ctx context.Context, listenAddr string, conf Config) (*EventsAPIServer, error)
NewEventsAPIServer creates a new *EventsAPIServer that connects to Slack using the events API. Note that you will usually configure this type of slack adapter as joe.Module (i.e. using the EventsAPIAdapter function of this package).
func (*EventsAPIServer) Close ¶ added in v2.1.0
func (a *EventsAPIServer) Close() error
Close shuts down the disconnects the adapter from the slack API.
func (*EventsAPIServer) RegisterAt ¶ added in v2.1.0
func (a *EventsAPIServer) RegisterAt(brain *joe.Brain)
RegisterAt implements the joe.Adapter interface by emitting the slack API events to the given brain.
type Option ¶
An Option is used to configure the slack adapter.
func WithListenPassive ¶
func WithListenPassive() Option
WithListenPassive makes the adapter listen and respond to all messages not just those directed at it
func WithLogUnknownMessageTypes ¶
func WithLogUnknownMessageTypes() Option
WithLogUnknownMessageTypes makes the adapter log unknown message types as error message for debugging. This option is disabled by default.
func WithLogger ¶
WithLogger can be used to inject a different logger for the slack adapater.
func WithMessageParams ¶
func WithMessageParams(params slack.PostMessageParameters) Option
WithMessageParams overrides the default parameters that are used when sending any message to slack.
func WithMiddleware ¶ added in v2.2.0
WithMiddleware is an option for the EventsAPIServer that allows the user to inject an HTTP middleware to the HTTP server.
func WithReadTimeout ¶ added in v2.1.0
WithReadTimeout is an option for the EventsAPIServer that sets the servers maximum duration for reading the entire HTTP request, including the body.
func WithTLS ¶ added in v2.1.0
WithTLS is an option for the EventsAPIServer that enables serving HTTP requests via TLS.
func WithTLSConfig ¶ added in v2.1.0
WithTLSConfig is an option for the EventsAPIServer that can be used in combination with the WithTLS(…) option to configure the HTTPS server.
func WithTimeouts ¶ added in v2.1.0
WithTimeouts is an option for the EventsAPIServer that sets both the read and write timeout of the HTTP server to the same given value.
func WithWriteTimeout ¶ added in v2.1.0
WithWriteTimeout is an option for the EventsAPIServer that sets the servers maximum duration before timing out writes of the HTTP response.