router

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 Imported by: 4

Documentation

Index

Constants

View Source
const (
	RouteTypeMention        = "mention"
	RouteTypeChannelMessage = "channel_message"
	RouteTypeSlashCommand   = "slash_command"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelMessageRoute added in v0.2.1

type ChannelMessageRoute struct {
	Route
	Plugin func(router Router, route Route, api slack.Client, ev slackevents.MessageEvent, message string)
}

ChannelMessageRoute handles the `message.channels` Event

func (ChannelMessageRoute) Execute added in v0.2.1

func (route ChannelMessageRoute) Execute(router Router, api slack.Client, ev slackevents.MessageEvent, message string)

Execute calls Plugin()

type EventMessageAuthorization added in v0.2.1

type EventMessageAuthorization struct {
	UserId string `json:"user_id"`
	TeamId string `json:"team_id"`
}

type EventsAPICallbackEvent added in v0.2.1

type EventsAPICallbackEvent struct {
	Type           string                      `json:"type"`
	Token          string                      `json:"token"`
	TeamID         string                      `json:"team_id"`
	APIAppID       string                      `json:"api_app_id"`
	Authorizations []EventMessageAuthorization `json:"authorizations"`
	EventID        string                      `json:"event_id"`
	EventTime      int                         `json:"event_time"`
	EventContext   string                      `json:"event_context"`
}

this is required because slack-go doesn't seem to provide a way to get the bot's own ID

type MentionRoute

type MentionRoute struct {
	Route
	Plugin func(router Router, route Route, api slack.Client, ev slackevents.AppMentionEvent, message string)
}

func (MentionRoute) Execute

func (route MentionRoute) Execute(router Router, api slack.Client, ev slackevents.AppMentionEvent, message string)

Execute calls Plugin()

type RegisteredRoute added in v0.3.0

type RegisteredRoute struct {
	Route
	Type string // RouteTypeMention, RouteTypeChannelMessage, or RouteTypeSlashCommand
}

RegisteredRoute wraps a Route with its type for introspection

type Route

type Route struct {
	Name        string
	Pattern     string
	Description string
	Help        string
	Permissions []string
	Priority    int
}

Route The primary type used by event specific routes

type Router

type Router struct {
	MentionRoutes             map[string]MentionRoute
	ChannelMessageRoutes      map[string]ChannelMessageRoute
	SlashCommandRoutes        map[string]SlashCommandRoute
	DefaultMentionRoute       MentionRoute
	DeniedMentionRoute        MentionRoute
	DeniedChannelMessageRoute ChannelMessageRoute
	DeniedSlashCommandRoute   SlashCommandRoute
	DbConnection              *gorm.DB
	BotUID                    string
}

Router the HTTP router which handles Events from Slack

func NewRouter

func NewRouter() *Router

NewRouter returns a new Router

func (*Router) AddChannelMessageRoute added in v0.2.1

func (router *Router) AddChannelMessageRoute(route ChannelMessageRoute)

AddChannelMessageRoute sets the key for ChannelMessages key to route.Name and it's value to route

func (*Router) AddChannelMessageRoutes added in v0.2.1

func (router *Router) AddChannelMessageRoutes(routes []ChannelMessageRoute)

AddChannelMessageRoutes same as AddChannelMessageRoute but plural

func (*Router) AddMentionRoute

func (router *Router) AddMentionRoute(route MentionRoute)

AddMentionRoute sets upserts and element into `MentionRoutes` whose key is the provided `Name` field

func (*Router) AddMentionRoutes

func (router *Router) AddMentionRoutes(routes []MentionRoute)

AddMentionRoutes calls `AddMentionRoute()` for each element in `routes`

func (*Router) AddSlashCommandRoute added in v0.3.0

func (router *Router) AddSlashCommandRoute(route SlashCommandRoute)

AddSlashCommandRoute adds a slash command route keyed by its Name

func (*Router) AddSlashCommandRoutes added in v0.3.0

func (router *Router) AddSlashCommandRoutes(routes []SlashCommandRoute)

AddSlashCommandRoutes calls AddSlashCommandRoute for each element in routes

func (Router) Can

func (router Router) Can(u models.User, permissions []string) bool

Can Returns true if `u` possesses the provided permissions

func (Router) FindChannelMessageRouteByMessage added in v0.2.1

func (router Router) FindChannelMessageRouteByMessage(message string) (ChannelMessageRoute, bool)

FindChannelMessageRouteByMessage Returns the ChannelMessageRoute that matches the provided message

func (Router) FindChannelMessageRouteByName added in v0.2.1

func (router Router) FindChannelMessageRouteByName(name string) (ChannelMessageRoute, bool)

FindChannelMessageRouteByName looks up and return the ChannelMessageRoute by the provided Name field value

func (Router) FindMentionRouteByMessage

func (router Router) FindMentionRouteByMessage(message string) (MentionRoute, bool)

FindMentionRouteByMessage Returns the route to execute based on the first matched Route.Pattern.

func (Router) FindMentionRouteByName

func (router Router) FindMentionRouteByName(name string) (MentionRoute, bool)

FindMentionRouteByName Returns the named mention route

func (Router) FindSlashCommandRouteByCommand added in v0.3.0

func (router Router) FindSlashCommandRouteByCommand(command string) (SlashCommandRoute, bool)

FindSlashCommandRouteByCommand looks up a SlashCommandRoute by command name

func (Router) RegisteredRoutes added in v0.3.0

func (router Router) RegisteredRoutes() []RegisteredRoute

RegisteredRoutes returns all registered routes sorted by priority (descending), then by name (alphabetical). DefaultMentionRoute and DeniedMentionRoute are excluded because they are stored as separate struct fields, not entries in the route maps.

func (Router) SetupDb

func (router Router) SetupDb()

SetupDb migrates the schemas

func (*Router) UpdateBotUID added in v0.2.1

func (r *Router) UpdateBotUID(body []byte) error

UpdateBotUID sets the BotUID field from an event body. Only updates if currently empty.

Note: BotUID is effectively set-once; no synchronization is needed because concurrent calls with valid bodies will all set the same value.

type SlashCommandRoute added in v0.3.0

type SlashCommandRoute struct {
	Route
	Command           string // Slack command name, e.g. "/deploy"
	ImmediateResponse string // Optional ephemeral response sent before async plugin execution
	Plugin            func(router Router, route Route, api slack.Client, cmd slack.SlashCommand)
}

SlashCommandRoute handles Slack slash command invocations. Plugin execution is dispatched asynchronously in a goroutine, so the HTTP handler acknowledges the command with an empty 200 within Slack's 3-second deadline. For commands that need to send a visible response, the Plugin should post a follow-up message using the Slack API (e.g. chat.postMessage or the slash command's ResponseURL).

func (SlashCommandRoute) Execute added in v0.3.0

func (route SlashCommandRoute) Execute(router Router, api slack.Client, cmd slack.SlashCommand)

Execute calls Plugin()

Jump to

Keyboard shortcuts

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