server

package
v0.0.0-...-0e217c4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogFunc

type LogFunc func(...interface{})

LogFunc is an abstraction that allows using any external logger with a Print signature Set to nil to disable logging completely

type LogfFunc

type LogfFunc func(string, ...interface{})

LogfFunc is an abstraction that allows using any external logger with a Printf signature Set to nil to disable logging completely

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request wraps http.Request

func (*Request) EventAPIEvent

func (r *Request) EventAPIEvent(body []byte) (*slackevents.EventsAPIEvent, error)

EventAPIEvent returns the parsed event from the Slack Event API if it exists and is valid

func (*Request) InteractionCallbackPayload

func (r *Request) InteractionCallbackPayload() (*slack.InteractionCallback, error)

InteractionCallbackPayload returns the parsed payload for an interaction if it exists and is valid

func (*Request) Validate

func (r *Request) Validate(secret string, dnHeader *string) error

Validate the request comes from Slack

type Response

type Response struct {
	http.ResponseWriter
}

Response wraps http.ResponseWriter

func (*Response) Text

func (r *Response) Text(code int, body string)

Text is a convenience method for sending a response

type Route

type Route struct {
	CallbackID, Path, Command, InteractionType, EventType string
	Handler                                               SlackHandlerFunc
}

Route is a handler which is invoked when a path is matched

type SlackHandler

type SlackHandler struct {
	Log          LogFunc
	Logf         LogfFunc
	ErrorLog     LogFunc
	ErrorLogf    LogfFunc
	Routes       []*Route
	DefaultRoute SlackHandlerFunc
	// contains filtered or unexported fields
}

SlackHandler is a function executed when a route is invoked

func NewSlackHandler

func NewSlackHandler(basePath, appToken, secretToken string, dnHeader *string, l LogFunc, lf LogfFunc, el LogFunc, elf LogfFunc) *SlackHandler

NewSlackHandler returns an initialised SlackHandler

func (*SlackHandler) HandleCommand

func (h *SlackHandler) HandleCommand(c string, f SlackHandlerFunc)

HandleCommand registers a handler to be executed when a slash command request is sent to the BasePath

func (*SlackHandler) HandleEventCallback

func (h *SlackHandler) HandleEventCallback(et string, f SlackHandlerFunc)

HandleEventCallback registers a handler to be executed when a specific EventsAPICallbackEvent type is present in the request

func (*SlackHandler) HandleInteractionCallback

func (h *SlackHandler) HandleInteractionCallback(it, cid string, f SlackHandlerFunc)

HandleInteractionCallback registers a handler to be executed when a specific InteractionType / CallbackID pair is present in the request

func (*SlackHandler) HandlePath

func (h *SlackHandler) HandlePath(p string, f SlackHandlerFunc)

HandlePath registers handlers for specific paths

func (*SlackHandler) ServeHTTP

func (h *SlackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies http.Handler interface

type SlackHandlerFunc

type SlackHandlerFunc func(res *Response, req *Request, ctx interface{}) error

SlackHandlerFunc is an http.HandlerFunc which can return an error and has a context Context varies depending on the request type and is for injecting arbitrary data in at routing time

Jump to

Keyboard shortcuts

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