Documentation ¶
Overview ¶
quadlek is a slack Bot that is built on top of the nlopes Slack client.
For a good source of examples, look at the included plugins at https://github.com/jirwin/quadlek/tree/master/plugins.
Read more about the client and Slack APIs at: https://github.com/nlopes/slack and https://api.slack.com
Index ¶
- Variables
- type Bot
- func (b *Bot) GetApi() *slack.Client
- func (b *Bot) GetBotId() string
- func (b *Bot) GetChannel(chanId string) (*slack.Channel, error)
- func (b *Bot) GetChannelId(chanName string) (string, error)
- func (b *Bot) GetCommand(cmdText string) *registeredCommand
- func (b *Bot) GetInteraction(callbackID string) *registeredInteraction
- func (b *Bot) GetMessage(channel, ts string) (slack.Message, error)
- func (b *Bot) GetMessageLog(channel string, opts MessageLotOpts) ([]slack.Message, error)
- func (b *Bot) GetUser(userId string) (*slack.User, error)
- func (b *Bot) GetUserID(userName string) (string, error)
- func (b *Bot) GetUserId() string
- func (b *Bot) GetUserName(userId string) (string, error)
- func (b *Bot) GetWebhook(name string) *registeredWebhook
- func (b *Bot) InitPluginBucket(pluginId string) error
- func (b *Bot) MsgToBot(msg string) bool
- func (b *Bot) OpenView(triggerID string, response slack.ModalViewRequest) (*slack.ViewResponse, error)
- func (b *Bot) PostMessage(channel string, options ...slack.MsgOption) (string, string, error)
- func (b *Bot) React(msg *slack.Msg, reaction string)
- func (b *Bot) RegisterPlugin(p interface{}) error
- func (b *Bot) Respond(msg *slack.Msg, resp string)
- func (b *Bot) RespondToSlashCommand(url string, cmdResp *CommandResp) error
- func (b *Bot) Say(channel string, resp string)
- func (b *Bot) Start()
- func (b *Bot) Stop()
- func (b *Bot) ValidateSlackRequest(r *http.Request) error
- func (b *Bot) WebhookServer()
- type Command
- type CommandMsg
- type CommandPlugin
- type CommandResp
- type Hook
- type HookMsg
- type HookPlugin
- type Interaction
- type InteractionMsg
- type InteractionPlugin
- type LoadPlugin
- type MessageLotOpts
- type Plugin
- type PluginWebhook
- type ReactionHook
- type ReactionHookMsg
- type ReactionHookPlugin
- type Store
- func (s *Store) ForEach(forEachFunc func(bucket *bolt.Bucket, key string, value []byte) error) error
- func (s *Store) Get(key string, getFunc func([]byte) error) error
- func (s *Store) GetAndUpdate(key string, updateFunc func([]byte) ([]byte, error)) error
- func (s *Store) Update(key string, value []byte) error
- func (s *Store) UpdateRaw(updateFunc func(*bolt.Bucket) error) error
- type Webhook
- type WebhookMsg
- type WebhookPlugin
Constants ¶
This section is empty.
Variables ¶
var InvalidRequestSignature = errors.New("invalid request signature")
Functions ¶
This section is empty.
Types ¶
type Bot ¶
This is the core struct for the Bot, and provides all methods required for interacting with various Slack APIs.
An instance of the bot is provided to plugins to enable plugins to interact with the Slack API.
func NewBot ¶
func NewBot(parentCtx context.Context, apiKey, verificationToken, dbPath string, debug bool) (*Bot, error)
NewBot creates a new instance of Bot for use.
apiKey is the Slack API key that the Bot should use to authenticate
verificationToken is the webhook token that is used to validate webhooks are coming from slack
dbPath is the path to the database on the filesystem.
func (*Bot) GetApi ¶
GetApi returns the Slack API client. You can use this client to perform actions that use the Slack Web API. See https://api.slack.com/web for more details.
func (*Bot) GetChannel ¶
GetChannel returns the Slack channel object given a channel ID
func (*Bot) GetChannelId ¶
GetChannelId returns the Slack channel ID for a given human-readable channel name.
func (*Bot) GetCommand ¶
GetCommand returns the registeredCommand for the provided command name
func (*Bot) GetInteraction ¶
GetWebhook returns the registeredWebhook for the given webhook name
func (*Bot) GetMessageLog ¶
GetMessageLog uses channel and a set of options to get historical messages from the Slack API.
func (*Bot) GetUserID ¶ added in v0.0.7
GetUserID returns the slack user name for a human readable username
func (*Bot) GetUserName ¶
GetUserName returns the human-readable user name for a given user ID
func (*Bot) GetWebhook ¶
GetWebhook returns the registeredWebhook for the given webhook name
func (*Bot) InitPluginBucket ¶
InitPluginBucket initializes the database bucket for the given pluginId
func (*Bot) OpenView ¶
func (b *Bot) OpenView(triggerID string, response slack.ModalViewRequest) (*slack.ViewResponse, error)
func (*Bot) PostMessage ¶
PostMessage sends a new message to Slack using the provided channel and message string. It returns the channel ID the message was posted to, and the timestamp that the message was posted at. In combination these can be used to identify the exact message that was sent.
func (*Bot) React ¶
React attaches an emojii reaction to a message. Reactions are formatted like: :+1:
func (*Bot) RegisterPlugin ¶
RegisterPlugin registers the given Plugin with the Bot.
func (*Bot) Respond ¶
Respond responds to a Slack message The sent message will go to the same channel as the message that is being responded to and will highlight the author of the original message.
func (*Bot) RespondToSlashCommand ¶
func (b *Bot) RespondToSlashCommand(url string, cmdResp *CommandResp) error
RespondToSlashCommand sends a command response to the slack API in order to respond to a slash command.
func (*Bot) Start ¶
func (b *Bot) Start()
Start activates the Bot, creating a new API client. It also calls out to the Slack API to obtain all of the channels and users.
func (*Bot) Stop ¶
func (b *Bot) Stop()
Stop cancel's the bots main context, closes the DB handle, and disconnects from slack
func (*Bot) ValidateSlackRequest ¶
Validates the signature header for slack webhooks
func (*Bot) WebhookServer ¶
func (b *Bot) WebhookServer()
WebhookServer starts a new http server that listens and responds to incoming webhooks. The Slack API uses webhooks for processing slash commands, and this server is used to respond to them. Plugins can also register custom webhooks that can be used however they choose. An example of this would be to process oauth2 callbacks to facilitate oauth2 flows for associating a user's slack account with an external service.
type Command ¶
type Command interface { GetName() string Channel() chan<- *CommandMsg Run(ctx context.Context) }
Command is the interface that plugins implement for slash commands. Slash commands are actively triggered by users in slack, and only receive messages when they are invoked.
func MakeCommand ¶
func MakeCommand(name string, runFn func(ctx context.Context, cmdChan <-chan *CommandMsg)) Command
MakeCommand is a helper function that accepts a name and a runFunc, and returns a Command.
type CommandMsg ¶
CommandMsg is the struct that is passed to a commands channel as it is activated.
type CommandPlugin ¶
type CommandResp ¶
type CommandResp struct { Text string `json:"text"` Attachments []slack.Attachment `json:"attachments"` ResponseType string `json:"response_type"` InChannel bool `json:"-"` }
CommandResp is the struct that is used to respond to a command if interaction is required.
type Hook ¶
Hook is the interface that a plugin can implement to create a hook.
Hooks receive every message that the Bot sees so plugins can react accordingly.
type HookPlugin ¶
type Interaction ¶
type Interaction interface { GetName() string Channel() chan<- *InteractionMsg Run(ctx context.Context) }
Interaction is the interface that plugins implement for slash Shortcuts. Slash Shortcuts are actively triggered by users in slack, and only receive messages when they are invoked.
func MakeInteraction ¶
func MakeInteraction(name string, runFn func(ctx context.Context, cmdChan <-chan *InteractionMsg)) Interaction
MakeInteraction is a helper function that accepts a name and a runFunc, and returns a Interaction.
type InteractionMsg ¶
type InteractionMsg struct { Bot *Bot Interaction *slack.InteractionCallback Store *Store }
InteractionMsg is the struct that is passed to a Shortcuts channel as it is activated.
type InteractionPlugin ¶
type InteractionPlugin interface { GetId() string GetInteractions() []Interaction }
func MakeInteractionPlugin ¶
func MakeInteractionPlugin(id string, plugins []Interaction) InteractionPlugin
MakePlugin is a helper function that returns a Plugin.
type MessageLotOpts ¶
MessageLotOpts is the stuct that you use to configure what messages you want to retrieve from the API.
IncludeBots: If true, include messages from bots(not just quadlek bots)
Count: The max number of messages to return
Period: The amount of time to look backwards when looking for messages
SkipAttachments: If true, don't return message attachments.
type Plugin ¶
type Plugin interface {
GetId() string
}
Plugin is the interface to implement a plugin
func MakePlugin ¶
func MakePlugin(id string, commands []Command, hooks []Hook, reactionHooks []ReactionHook, webhooks []Webhook, loadFunction loadPluginFn) Plugin
MakePlugin is a helper function that returns a Plugin.
type PluginWebhook ¶
type PluginWebhook struct { Name string Request *http.Request ResponseWriter http.ResponseWriter }
PluginWebhook stores an incoming web request to be passed to a plugin
type ReactionHook ¶
type ReactionHook interface { Channel() chan<- *ReactionHookMsg Run(ctx context.Context) }
ReactionHook is the interface that plugins implement to create reaction hooks. Reaction hooks receive an event every time a message is reacted to.
func MakeReactionHook ¶
func MakeReactionHook(runFunc func(ctx context.Context, reactionHookChan <-chan *ReactionHookMsg)) ReactionHook
MakeReactionHook is a helper function that returns a ReactionHook
type ReactionHookMsg ¶
type ReactionHookMsg struct { Bot *Bot Reaction *slackevents.ReactionAddedEvent Store *Store }
ReactionHookMsg is the struct that is sent to a reaction hook when a message is reacted to.
type ReactionHookPlugin ¶
type ReactionHookPlugin interface { Plugin GetReactionHooks() []ReactionHook }
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
The Store struct provides a plugin a namespaced key value store for the plugin to use however it needs. By default, keys are strings, and values are []byte. You can use UpdateRaw() if this doesn't fit your needs.
func (*Store) GetAndUpdate ¶
GetAndUpdate retrieves a key from the database and passes its value to the provided updateFunc. This allows you to transform data atomically.
type Webhook ¶
type Webhook interface { GetName() string Channel() chan<- *WebhookMsg Run(ctx context.Context) }
Webhook is the interface that a plugin implements to register a custom webhook.
func MakeWebhook ¶
func MakeWebhook(name string, runFunc func(ctx context.Context, whChan <-chan *WebhookMsg)) Webhook
MakeWebhook is a helper function that returns a Webhook
type WebhookMsg ¶
type WebhookMsg struct { Bot *Bot Request *http.Request ResponseWriter http.ResponseWriter Store *Store Done chan bool }
WebhookMsg is the struct that is sent to the plugin's channel