router

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2021 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

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(api slack.Client, router Router, 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"`
	Authoritzations []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(api slack.Client, router Router, ev slackevents.AppMentionEvent, message string)

Execute calls Plugin()

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
	DefaultMentionRoute  MentionRoute
	DeniedMentionRoute   MentionRoute
	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) 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) SetupDb

func (router Router) SetupDb()

SetupDb migrates the shcemas

func (*Router) UpdateBotUID added in v0.2.1

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

UpdateUID sets the UID field from an event body. Only updates if currently empty

Jump to

Keyboard shortcuts

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