webhooks

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BotEventPath = "/slack/event"
)
View Source
const (
	InteractionPath = "/slack/interaction"
)
View Source
const (
	SlashCommandPath = "/slack/command"
)

Variables

View Source
var BotEventHandlers = map[string]BotEventHandler{
	"app_mention": events.AppMentionHandler,

	"channel_archive": events.ChannelGroupHandler,
	"channel_created": events.ChannelCreatedHandler,

	"channel_unarchive": events.ChannelGroupHandler,

	"group_archive": events.ChannelGroupHandler,

	"group_open": events.ChannelGroupHandler,

	"group_unarchive": events.ChannelGroupHandler,

	"member_joined_channel": events.ChannelGroupHandler,

	"message": events.MessageHandler,

	"reaction_added":   events.ReactionHandler,
	"reaction_removed": events.ReactionHandler,

	"url_verification": events.URLVerificationHandler,
}

Functions

func NewHandler

func NewHandler(l *zap.Logger, vars sdkservices.Vars, d sdkservices.Dispatcher, id sdktypes.IntegrationID) handler

Types

type Action

type Action struct {
	Type string `json:"type,omitempty"`
	// Identifies the block within a surface that contained the interactive
	// component that was used. See https://api.slack.com/reference/block-kit/block-elements.
	BlockID  string `json:"block_id,omitempty"`
	ActionTS string `json:"action_ts,omitempty"`

	// Identifies the interactive component itself. Some blocks can contain
	// multiple interactive components, so [BlockID] alone may not be specific
	// enough to identify the source component. For more information, see
	// https://api.slack.com/reference/block-kit/block-elements.
	ActionID string `json:"action_id,omitempty"`
	// Set by your app when you composed the blocks, this is the value that was
	// specified in the interactive component when an interaction happened. For
	// example, a select menu will have multiple possible values depending on
	// what the user picks from the menu, and Value will identify the chosen
	// option. See https://api.slack.com/reference/block-kit/block-elements.
	Value string `json:"value,omitempty"`

	Style string     `json:"style,omitempty"`
	Text  *chat.Text `json:"text,omitempty"`
}

https://api.slack.com/reference/interaction-payloads/block-actions

type BlockActionsPayload

type BlockActionsPayload struct {
	// Type must be "block_actions" or "modal" (or "interactive_message" for
	// attachments, which we don't support because they're superseded by blocks).
	Type string `json:"type,omitempty"`

	User                *users.User `json:"user,omitempty"`
	APIAppID            string      `json:"api_app_id,omitempty"`
	Team                *Team       `json:"team,omitempty"`
	IsEnterpriseInstall bool        `json:"is_enterprise_install,omitempty"`
	Enterprise          *Enterprise `json:"enterprise,omitempty"`

	Channel   *conversations.Channel `json:"channel,omitempty"`
	Message   *chat.Message          `json:"message,omitempty"`
	Container *Container             `json:"container,omitempty"`
	// Contains data from the specific interactive component that was used.
	// App surfaces can contain blocks with multiple interactive components,
	// and each of those components can have multiple values selected by users.
	Actions []Action `json:"actions,omitempty"`

	// Short-lived webhook URL to send messages in response to interactions.
	// Attention: documented as deprecated for next-generation Slack apps, see
	// https://api.slack.com/reference/interaction-payloads/block-actions#fields
	// and compare with [webhooks.SlashCommand].
	ResponseURL string `json:"response_url,omitempty"`
	// https://api.slack.com/reference/interaction-payloads/views
	ResponseURLs []ResponseURL `json:"response_urls,omitempty"`

	// Short-lived ID that will let your app open a modal
	// (https://api.slack.com/surfaces/modals).
	TriggerID string `json:"trigger_id,omitempty"`
	// TODO: token?
	View *View `json:"view,omitempty"`
}

https://api.slack.com/reference/interaction-payloads/block-actions#fields

type BotEventHandler added in v0.3.3

type BotEventHandler = func(*zap.Logger, http.ResponseWriter, []byte, *events.Callback) any

type Container

type Container struct {
	Type        string `json:"type,omitempty"`
	MessageTS   string `json:"message_ts,omitempty"`
	ChannelID   string `json:"channel_id,omitempty"`
	IsEphemeral bool   `json:"is_ephemeral,omitempty"`
	ViewID      string `json:"view_id,omitempty"`
}

https://api.slack.com/reference/interaction-payloads/block-actions#examples

type Enterprise

type Enterprise struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

https://api.slack.com/methods/oauth.v2.access#examples

type Response

type Response struct {
	Text            string           `json:"text,omitempty"`
	Blocks          []map[string]any `json:"blocks,omitempty"`
	ResponseType    string           `json:"response_type,omitempty"`
	ThreadTS        string           `json:"thread_ts,omitempty"`
	ReplaceOriginal bool             `json:"replace_original,omitempty"`
	DeleteOriginal  bool             `json:"delete_original,omitempty"`
}

type ResponseURL added in v0.8.6

type ResponseURL struct {
	BlockID     string `json:"block_id,omitempty"`
	ActionID    string `json:"action_id,omitempty"`
	ChannelID   string `json:"channel_id,omitempty"`
	ResponseURL string `json:"response_url,omitempty"`
}

https://api.slack.com/reference/interaction-payloads/views

type SlashCommand

type SlashCommand struct {
	// Unique identifier of the Slack workspace where the event occurred.
	TeamID string
	// Human-readable name of the Slack workspace where the event occurred.
	TeamDomain string

	// Is the executing Slack workspace part of an Enterprise Grid?
	IsEnterpriseInstall bool
	EnterpriseID        string
	EnterpriseName      string

	// APIAppID is our Slack app's unique ID. Useful in case we point multiple
	// Slack apps to the same webhook URL, but want to treat them differently
	// (e.g. official vs. unofficial, breaking changes, and flavors).
	APIAppID  string
	ChannelID string
	// Human-readable name of the channel - don't rely on it.
	ChannelName string
	// ID of the user who triggered the command.
	// Use "<@value>" in messages to mention them.
	UserID string
	// Command must be "/ak" or "/autokitteh" in our Slack app.
	Command string
	// Text that the user typed after the command (e.g. "help").
	Text string

	// Short-lived webhook URL (https://api.slack.com/messaging/webhooks) to generate
	// message responses (https://api.slack.com/interactivity/handling#message_responses).
	// Compare with [api.BlockActionsInteractionPayload], where this field is deprecated
	// per https://api.slack.com/reference/interaction-payloads/block-actions#fields.
	ResponseURL string
	// Short-lived ID that will let your app open a modal
	// (https://api.slack.com/surfaces/modals).
	TriggerID string
}

See https://api.slack.com/interactivity/slash-commands#app_command_handling and https://api.slack.com/types/event.

type State added in v0.8.6

type State struct {
	Values map[string]map[string]any `json:"values,omitempty"`
}

https://api.slack.com/reference/interaction-payloads/views#view_submission_fields

type Team

type Team struct {
	ID     string `json:"id,omitempty"`
	Domain string `json:"domain,omitempty"`
	Name   string `json:"name,omitempty"`
}

https://api.slack.com/methods/oauth.v2.access#examples https://api.slack.com/reference/interaction-payloads/block-actions#examples

type View added in v0.8.6

type View struct {
	ID                 string `json:"id,omitempty"`
	AppID              string `json:"app_id,omitempty"`
	BotID              string `json:"bot_id,omitempty"`
	TeamID             string `json:"team_id,omitempty"`
	AppInstalledTeamID string `json:"app_installed_team_id,omitempty"`

	Type           string           `json:"type,omitempty"`
	CallbackID     string           `json:"callback_id,omitempty"`
	Title          *chat.Text       `json:"title,omitempty"`
	Blocks         []map[string]any `json:"blocks,omitempty"`
	Close          *chat.Text       `json:"close,omitempty"`
	Submit         *chat.Text       `json:"submit,omitempty"`
	ClearOnClose   bool             `json:"clear_on_close,omitempty"`
	NotifyOnClose  bool             `json:"notify_on_close,omitempty"`
	SubmitDisabled bool             `json:"submit_disabled,omitempty"`

	// https://api.slack.com/block-kit/dialogs-to-modals#state
	PrivateMetadata string `json:"private_metadata,omitempty"`

	ExternalID string `json:"external_id,omitempty"`
	ViewID     string `json:"view_id,omitempty"`

	// https://api.slack.com/surfaces/modals#handling_race_conditions
	Hash string `json:"hash,omitempty"`
	// https://api.slack.com/reference/interaction-payloads/views#view_submission_fields
	State *State `json:"state,omitempty"`

	// PreviousViewID = null?
	RootViewID string `json:"root_view_id,omitempty"`
}

https://api.slack.com/surfaces/modals#view-object-fields https://api.slack.com/reference/interaction-payloads/views https://api.slack.com/reference/workflows/configuration-view

Jump to

Keyboard shortcuts

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