Documentation
¶
Overview ¶
Package bot answers whodar questions from Slack. It is transport-agnostic: a socket-mode or events-api adapter normalizes Slack events into Events and feeds them to the Engine, which resolves and replies through a Replier.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine answers events by resolving the query and formatting a Slack reply.
type Event ¶
type Event struct {
// Text is the message text, possibly containing the bot mention.
Text string
// Channel is the channel or DM id to reply in.
Channel string
// ThreadTS is the thread timestamp to reply within, if any.
ThreadTS string
}
Event is a normalized inbound message for the bot to answer.
type EventsHandler ¶
type EventsHandler struct {
// contains filtered or unexported fields
}
EventsHandler serves the Slack Events API. It verifies the request signature, answers the url_verification handshake, and dispatches event callbacks.
func NewEventsHandler ¶
func NewEventsHandler(engine *Engine, replier Replier, botUserID, signingSecret string, opts ...EventsOption) *EventsHandler
NewEventsHandler builds an EventsHandler. It panics on a nil engine or replier, or an empty signing secret.
func (*EventsHandler) ServeHTTP ¶
func (h *EventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP verifies the request, answers url_verification, and dispatches event callbacks asynchronously so Slack receives a fast acknowledgment.
type EventsOption ¶
type EventsOption func(*EventsHandler)
EventsOption configures an EventsHandler.
func WithClock ¶
func WithClock(now func() time.Time) EventsOption
WithClock overrides the clock, for tests.
func WithEventsLog ¶
func WithEventsLog(w io.Writer) EventsOption
WithEventsLog sets where handler notices are written.
type Replier ¶
type Replier interface {
// Reply posts text to channel, threading under threadTS when non-empty.
Reply(ctx context.Context, channel, threadTS, text string) error
}
Replier sends a reply to Slack.
type SocketOption ¶
type SocketOption func(*SocketRunner)
SocketOption configures a SocketRunner.
func WithDialer ¶
func WithDialer(d Dialer) SocketOption
WithDialer overrides the WebSocket dialer, for tests.
func WithLog ¶
func WithLog(w io.Writer) SocketOption
WithLog sets where connection notices are written.
type SocketRunner ¶
type SocketRunner struct {
// contains filtered or unexported fields
}
SocketRunner runs a Slack Socket Mode session: it opens a WebSocket with the app-level token, reads event frames, acknowledges them, and dispatches questions to the Engine. It reconnects until the context is canceled.
func NewSocketRunner ¶
func NewSocketRunner(app *slack.Client, engine *Engine, replier Replier, botUserID string, opts ...SocketOption) *SocketRunner
NewSocketRunner builds a SocketRunner. It panics on nil dependencies.