Documentation
¶
Overview ¶
This package contains the Slap framework for developing Slack Applications.
Index ¶
- type Application
- func (app *Application) RegisterBlockAction(actionID string, handler BlockActionHandler)
- func (app *Application) RegisterCommand(command string, handler CommandHandler)
- func (app *Application) RegisterEventHandler(eventType string, handler EventHandler)
- func (app *Application) RegisterViewSubmission(callbackID string, handler ViewSubmissionHandler)
- type BlockActionHandler
- type BlockActionPayload
- type BlockActionRequest
- type BotTokenGetter
- type CommandHandler
- type CommandPayload
- type CommandRequest
- type CommandResponseAction
- type CommandResponseActionType
- type Config
- type EventHandler
- type EventPayload
- type EventRequest
- type MessageEvent
- type OuterEventType
- type ViewResponseAction
- type ViewResponseActionType
- type ViewSubmissionHandler
- type ViewSubmissionPayload
- type ViewSubmissionRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
A Slap Application.
func (*Application) RegisterBlockAction ¶
func (app *Application) RegisterBlockAction(actionID string, handler BlockActionHandler)
Registers a block action handler.
Panics if the actionID has already been registered.
func (*Application) RegisterCommand ¶
func (app *Application) RegisterCommand(command string, handler CommandHandler)
Registers a slash command handler.
Panics if the slash command has already been registered.
func (*Application) RegisterEventHandler ¶
func (app *Application) RegisterEventHandler(eventType string, handler EventHandler)
Registers an EventAPI event handler for a subscribed event type.
Panics if the eventType has already been registered.
func (*Application) RegisterViewSubmission ¶
func (app *Application) RegisterViewSubmission(callbackID string, handler ViewSubmissionHandler)
Registers a view submission handler.
Panics if the callbackID has already been registered.
type BlockActionHandler ¶
type BlockActionHandler func(req *BlockActionRequest) error
A function to handle a block action request
type BlockActionPayload ¶
type BlockActionPayload struct {
Container slack.Container `json:"container"`
Actions []slack.BlockAction `json:"actions"`
Hash string `json:"hash"`
BotAccessToken string `json:"bot_access_token"`
Enterprise *string `json:"enterprise,omitempty"`
Channel *struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"channel,omitempty"`
Message *slack.MessageEvent `json:"message,omitempty"`
View *slack.View `json:"view,omitempty"`
State *slack.BlockActionStates `json:"state,omitempty"`
// contains filtered or unexported fields
}
The payload of a Slack block action request
type BlockActionRequest ¶
type BlockActionRequest struct {
Payload BlockActionPayload
// contains filtered or unexported fields
}
A block action request
type BotTokenGetter ¶
A function taking a Slack teamID (workspace ID) that returns the workspace's bot token as a string. For a non-distributed app, simply return your bot token.
type CommandHandler ¶
type CommandHandler func(req *CommandRequest) error
A function to handle slash command requests
type CommandPayload ¶
type CommandPayload struct {
// Deprecated: The verification token.
Token string
// The command that was called
Command string
// The text after the command
Text string
// The Team ID of the workspace this command was used in.
TeamID string
// The domain name of the workspace.
TeamDomain string
// The Enterprise ID this workspace belongs to if using Enterprise Grid.
EnterpriseID string
// The name of the enterprise this workspace belongs to if using Enterprise Grid..
EnterpriseName string
// The ID of the channel the command was used in.
ChannelID string
// The name of the channel the command was used in.
ChannelName string
// The ID of the user calling the command.
UserID string
// Deprecated: The name of the user calling the command.
UserName string
// A temporary webhook URL that used to generate message responses.
ResponseURL string
// A short-lived ID that can be used to open modals.
TriggerID string
// Your Slack App's unique identifier.
APIAppID string
}
The payload of a Slack slash command request
type CommandRequest ¶
type CommandRequest struct {
// The paylaod of the Slack request
Payload CommandPayload
// contains filtered or unexported fields
}
A slash command request from Slack
func (*CommandRequest) Ack ¶
func (event *CommandRequest) Ack()
Acknowledge Slack's request with Status 200
func (*CommandRequest) AckWithAction ¶
func (req *CommandRequest) AckWithAction(action CommandResponseAction)
Immediately respond to Slack's slash command request with an action
type CommandResponseAction ¶
type CommandResponseAction struct {
// The type of response: "in_channel" or "ephemeral"
ResponseType CommandResponseActionType `json:"response_type"`
// Text to send in the response
Text string `json:"text"`
// Slack Block Kit Blocks to send in the response
Blocks []slack.Block `json:"blocks,omitempty"`
}
An immediate action to be ran in response to a slash command
type CommandResponseActionType ¶
type CommandResponseActionType string
The type in a command action response
const ( RespondInChannel CommandResponseActionType = "in_channel" RespondEphemeral CommandResponseActionType = "ephemeral" )
The allowed CommandResponseAction ResponseType values
type Config ¶
type Config struct {
// Required. Slap will overwrite the following POST routes:
// "POST /interactions", "POST /events",
// and "POST /commands".
Router *http.ServeMux
// Optional. Adds a path to the start of the Slack routes.
PathPrefix string
// Required. Method for fetching bot tokens
// for a workspace based on its team ID
BotToken BotTokenGetter
// Required. The Slack webhook signing secret for your app
SigningSecret string
// A logger for the Slap Application
Logger *slog.Logger
// A generic, ephemeral error message to send the user
// when a handler returns an error.
//
// Defaults to: "An error occurred".
ErrorMessage string
}
Configuration options for the Slap Application
type EventHandler ¶
type EventHandler func(req *EventRequest) error
type EventPayload ¶
type EventPayload struct {
Event json.RawMessage
// contains filtered or unexported fields
}
type EventRequest ¶
type EventRequest struct {
Payload EventPayload
// contains filtered or unexported fields
}
type MessageEvent ¶
type MessageEvent struct {
slack.MessageEvent
// contains filtered or unexported fields
}
func (*MessageEvent) IsBot ¶
func (e *MessageEvent) IsBot() bool
type OuterEventType ¶
type OuterEventType string
const ( EventCallback OuterEventType = "event_callback" UrlVerification OuterEventType = "url_verification" RateLimited OuterEventType = "app_rate_limited" )
type ViewResponseAction ¶
type ViewResponseAction struct {
// The type of response: "clear", "errors", "update", or "push"
ResponseAction ViewResponseActionType `json:"response_action"`
// The view for "update" or "push" actions
View *slack.View `json:"view,omitempty"`
// The blockID-error map for "errors" actions.
//
// Example:
// errors := map[string]string {
// "email-input-block": "Please enter a valid email address."
// }
Errors map[string]string `json:"errors,omitempty"`
}
An immediate response action for a view submission
type ViewResponseActionType ¶
type ViewResponseActionType string
A view response action ResponseType
const ( // Clears the modal stack ViewResponseClear ViewResponseActionType = "clear" // Displays an error to the user in the modal ViewResponseErrors ViewResponseActionType = "errors" // Updates the view of the currently open modal ViewResponseUpdate ViewResponseActionType = "update" // Adds a new modal to the modal stack ViewResponsePush ViewResponseActionType = "push" )
The ViewResponseAction ResponseType values
type ViewSubmissionHandler ¶
type ViewSubmissionHandler func(req *ViewSubmissionRequest) error
A function to handle a view submission request
type ViewSubmissionPayload ¶
type ViewSubmissionPayload struct {
View slack.View `json:"view"`
// contains filtered or unexported fields
}
The payload of the Slack view_submission request
type ViewSubmissionRequest ¶
type ViewSubmissionRequest struct {
Payload ViewSubmissionPayload
// contains filtered or unexported fields
}
A Slack view submission request
func (*ViewSubmissionRequest) Ack ¶
func (event *ViewSubmissionRequest) Ack()
Acknowledge Slack's request with Status 200
func (*ViewSubmissionRequest) AckWithAction ¶
func (req *ViewSubmissionRequest) AckWithAction(action ViewResponseAction)
Immediately respond to Slack with a view response action