Documentation ¶
Index ¶
- type BotMode
- type ClientOption
- type Command
- type CommandContext
- func (r *CommandContext) Context() context.Context
- func (r *CommandContext) Definition() *CommandDefinition
- func (r *CommandContext) Event() *MessageEvent
- func (r *CommandContext) Logger() Logger
- func (r *CommandContext) Request() *Request
- func (r *CommandContext) Response() *ResponseReplier
- func (r *CommandContext) SlackClient() *slack.Client
- type CommandDefinition
- type CommandGroup
- func (g *CommandGroup) AddCommand(definition *CommandDefinition)
- func (g *CommandGroup) AddMiddleware(middleware CommandMiddlewareHandler)
- func (g *CommandGroup) GetCommands() []Command
- func (g *CommandGroup) GetMiddlewares() []CommandMiddlewareHandler
- func (g *CommandGroup) GetPrefix() string
- func (g *CommandGroup) PrependCommand(definition *CommandDefinition)
- type CommandHandler
- type CommandMiddlewareHandler
- type Interaction
- type InteractionContext
- func (r *InteractionContext) Callback() *slack.InteractionCallback
- func (r *InteractionContext) Context() context.Context
- func (r *InteractionContext) Definition() *InteractionDefinition
- func (r *InteractionContext) Logger() Logger
- func (r *InteractionContext) Response() *ResponseReplier
- func (r *InteractionContext) SlackClient() *slack.Client
- type InteractionDefinition
- type InteractionHandler
- type InteractionMiddlewareHandler
- type Job
- type JobContext
- type JobDefinition
- type JobHandler
- type JobMiddlewareHandler
- type Logger
- type MessageEvent
- type PostOption
- type Replier
- type ReplyOption
- type Request
- func (r *Request) BooleanParam(key string, defaultValue bool) bool
- func (r *Request) FloatParam(key string, defaultValue float64) float64
- func (r *Request) IntegerParam(key string, defaultValue int) int
- func (r *Request) Param(key string) string
- func (r *Request) Properties() *proper.Properties
- func (r *Request) StringParam(key string, defaultValue string) string
- type ResponseReplier
- func (r *ResponseReplier) Delete(channel string, messageTimestamp string) (string, error)
- func (r *ResponseReplier) Post(channel string, message string, options ...PostOption) (string, error)
- func (r *ResponseReplier) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
- func (r *ResponseReplier) PostError(channel string, err error, options ...PostOption) (string, error)
- func (r *ResponseReplier) Reply(message string, options ...ReplyOption) (string, error)
- func (r *ResponseReplier) ReplyBlocks(blocks []slack.Block, options ...ReplyOption) (string, error)
- func (r *ResponseReplier) ReplyError(err error, options ...ReplyOption) (string, error)
- type ResponseWriter
- func (r *ResponseWriter) Delete(channel string, messageTimestamp string) (string, error)
- func (r *ResponseWriter) Post(channel string, message string, options ...PostOption) (string, error)
- func (r *ResponseWriter) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
- func (r *ResponseWriter) PostError(channel string, err error, options ...PostOption) (string, error)
- type Slacker
- func (s *Slacker) AddCommand(definition *CommandDefinition)
- func (s *Slacker) AddCommandGroup(prefix string) *CommandGroup
- func (s *Slacker) AddCommandMiddleware(middleware CommandMiddlewareHandler)
- func (s *Slacker) AddInteraction(definition *InteractionDefinition)
- func (s *Slacker) AddInteractionMiddleware(middleware InteractionMiddlewareHandler)
- func (s *Slacker) AddJob(definition *JobDefinition)
- func (s *Slacker) AddJobMiddleware(middleware JobMiddlewareHandler)
- func (s *Slacker) GetCommandGroups() []*CommandGroup
- func (s *Slacker) GetInteractions() []*Interaction
- func (s *Slacker) GetJobs() []*Job
- func (s *Slacker) Help(definition *CommandDefinition)
- func (s *Slacker) Listen(ctx context.Context) error
- func (s *Slacker) OnConnected(onConnected func(socketmode.Event))
- func (s *Slacker) OnConnecting(onConnecting func(socketmode.Event))
- func (s *Slacker) OnConnectionError(onConnectionError func(socketmode.Event))
- func (s *Slacker) OnDisconnected(onDisconnected func(socketmode.Event))
- func (s *Slacker) OnHello(onHello func(socketmode.Event))
- func (s *Slacker) SanitizeEventTextHandler(sanitizeEventTextHandler func(in string) string)
- func (s *Slacker) SlackClient() *slack.Client
- func (s *Slacker) SocketModeClient() *socketmode.Client
- func (s *Slacker) UnsupportedCommandHandler(unsupportedCommandHandler CommandHandler)
- func (s *Slacker) UnsupportedEventHandler(unsupportedEventHandler func(socketmode.Event))
- func (s *Slacker) UnsupportedInteractionHandler(unsupportedInteractionHandler InteractionHandler)
- type Writer
- func (r *Writer) Delete(channel string, messageTimestamp string) (string, error)
- func (r *Writer) Post(channel string, message string, options ...PostOption) (string, error)
- func (r *Writer) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
- func (r *Writer) PostError(channel string, err error, options ...PostOption) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotMode ¶
type BotMode int
BotMode instruct the bot on how to handle incoming events that originated from a bot.
const ( // BotModeIgnoreAll instructs our bot to ignore any activity coming // from other bots, including our self. BotModeIgnoreAll BotMode = iota // BotModeIgnoreApp will ignore any events that originate from a // bot that is associated with the same App (ie. share the same App ID) as // this bot. OAuth scope `user:read` is required for this mode. BotModeIgnoreApp // BotModeIgnoreNone will not ignore any bots, including our self. // This can lead to bots "talking" to each other so care must be taken when // selecting this option. BotModeIgnoreNone )
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption an option for client values
func WithAPIURL ¶
func WithAPIURL(url string) ClientOption
WithAPIURL sets the API URL (for testing)
func WithBotMode ¶
func WithBotMode(mode BotMode) ClientOption
WithBotMode instructs Slacker on how to handle message events coming from a bot.
func WithCronLocation ¶
func WithCronLocation(location *time.Location) ClientOption
WithCronLocation overrides the timezone of the cron instance.
type Command ¶
type Command interface { Definition() *CommandDefinition Match(string) (*proper.Properties, bool) Tokenize() []*commander.Token }
Command interface
type CommandContext ¶
type CommandContext struct {
// contains filtered or unexported fields
}
CommandContext contains information relevant to the executed command
func (*CommandContext) Context ¶
func (r *CommandContext) Context() context.Context
Context returns the context
func (*CommandContext) Definition ¶
func (r *CommandContext) Definition() *CommandDefinition
Definition returns the command definition
func (*CommandContext) Event ¶
func (r *CommandContext) Event() *MessageEvent
Event returns the slack message event
func (*CommandContext) Request ¶
func (r *CommandContext) Request() *Request
Request returns the command request
func (*CommandContext) Response ¶
func (r *CommandContext) Response() *ResponseReplier
Response returns the response writer
func (*CommandContext) SlackClient ¶
func (r *CommandContext) SlackClient() *slack.Client
SlackClient returns the slack API client
type CommandDefinition ¶
type CommandDefinition struct { Command string Aliases []string Description string Examples []string Middlewares []CommandMiddlewareHandler Handler CommandHandler // HideHelp will hide this command definition from appearing in the `help` results. HideHelp bool }
CommandDefinition structure contains definition of the bot command
type CommandGroup ¶
type CommandGroup struct {
// contains filtered or unexported fields
}
CommandGroup groups commands with a common prefix and middlewares
func (*CommandGroup) AddCommand ¶
func (g *CommandGroup) AddCommand(definition *CommandDefinition)
AddCommand define a new command and append it to the list of group bot commands
func (*CommandGroup) AddMiddleware ¶
func (g *CommandGroup) AddMiddleware(middleware CommandMiddlewareHandler)
AddMiddleware define a new middleware and append it to the list of group middlewares
func (*CommandGroup) GetCommands ¶
func (g *CommandGroup) GetCommands() []Command
GetCommands returns Commands
func (*CommandGroup) GetMiddlewares ¶
func (g *CommandGroup) GetMiddlewares() []CommandMiddlewareHandler
GetMiddlewares returns Middlewares
func (*CommandGroup) GetPrefix ¶
func (g *CommandGroup) GetPrefix() string
GetPrefix returns the group's prefix
func (*CommandGroup) PrependCommand ¶
func (g *CommandGroup) PrependCommand(definition *CommandDefinition)
PrependCommand define a new command and prepend it to the list of group bot commands
type CommandHandler ¶
type CommandHandler func(*CommandContext)
CommandHandler represents the command handler function
type CommandMiddlewareHandler ¶
type CommandMiddlewareHandler func(CommandHandler) CommandHandler
CommandMiddlewareHandler represents the command middleware handler function
type Interaction ¶
type Interaction struct {
// contains filtered or unexported fields
}
Interaction structure contains the bot's interaction, description and handler
func (*Interaction) Definition ¶
func (c *Interaction) Definition() *InteractionDefinition
Definition returns the interaction definition
type InteractionContext ¶
type InteractionContext struct {
// contains filtered or unexported fields
}
InteractionContext contains information relevant to the executed interaction
func (*InteractionContext) Callback ¶
func (r *InteractionContext) Callback() *slack.InteractionCallback
Callback returns the interaction callback
func (*InteractionContext) Context ¶
func (r *InteractionContext) Context() context.Context
Context returns the context
func (*InteractionContext) Definition ¶
func (r *InteractionContext) Definition() *InteractionDefinition
Definition returns the interaction definition
func (*InteractionContext) Logger ¶
func (r *InteractionContext) Logger() Logger
Logger returns the logger
func (*InteractionContext) Response ¶
func (r *InteractionContext) Response() *ResponseReplier
Response returns the response writer
func (*InteractionContext) SlackClient ¶
func (r *InteractionContext) SlackClient() *slack.Client
SlackClient returns the slack API client
type InteractionDefinition ¶
type InteractionDefinition struct { BlockID string Middlewares []InteractionMiddlewareHandler Handler InteractionHandler }
InteractionDefinition structure contains definition of the bot interaction
type InteractionHandler ¶
type InteractionHandler func(*InteractionContext)
InteractionHandler represents the interaction handler function
type InteractionMiddlewareHandler ¶
type InteractionMiddlewareHandler func(InteractionHandler) InteractionHandler
InteractionMiddlewareHandler represents the interaction middleware handler function
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job structure contains the job's spec and handler
func (*Job) Definition ¶
func (c *Job) Definition() *JobDefinition
Definition returns the job's definition
type JobContext ¶
type JobContext struct {
// contains filtered or unexported fields
}
JobContext contains information relevant to the executed job
func (*JobContext) Context ¶
func (r *JobContext) Context() context.Context
Context returns the context
func (*JobContext) Definition ¶
func (r *JobContext) Definition() *JobDefinition
Definition returns the job definition
func (*JobContext) Response ¶
func (r *JobContext) Response() *ResponseWriter
Response returns the response writer
func (*JobContext) SlackClient ¶
func (r *JobContext) SlackClient() *slack.Client
SlackClient returns the slack API client
type JobDefinition ¶
type JobDefinition struct { CronExpression string Name string Description string Middlewares []JobMiddlewareHandler Handler JobHandler // HideHelp will hide this job definition from appearing in the `help` results. HideHelp bool }
JobDefinition structure contains definition of the job
type JobMiddlewareHandler ¶
type JobMiddlewareHandler func(JobHandler) JobHandler
JobMiddlewareHandler represents the job middleware handler function
type MessageEvent ¶
type MessageEvent struct { // Channel ID where the message was sent ChannelID string // Channel contains information about the channel Channel *slack.Channel // User ID of the sender UserID string // UserProfile contains all the information details of a given user UserProfile *slack.UserProfile // Text is the unalterted text of the message, as returned by Slack Text string // TimeStamp is the message timestamp. For events that do not support // threading (eg. slash commands) this will be unset. // will be left unset. TimeStamp string // ThreadTimeStamp is the message thread timestamp. For events that do not // support threading (eg. slash commands) this will be unset. ThreadTimeStamp string // Data is the raw event data returned from slack. Using Type, you can assert // this into a slackevents *Event struct. Data any // Type is the type of the event, as returned by Slack. For instance, // `app_mention` or `message` Type string // BotID of the bot that sent this message. If a bot did not send this // message, this will be an empty string. BotID string }
MessageEvent contains details common to message based events, including the raw event as returned from Slack along with the corresponding event type. The struct should be kept minimal and only include data that is commonly used to prevent frequent type assertions when evaluating the event.
func (*MessageEvent) InThread ¶
func (e *MessageEvent) InThread() bool
InThread indicates if a message event took place in a thread.
func (*MessageEvent) IsBot ¶
func (e *MessageEvent) IsBot() bool
IsBot indicates if the message was sent by a bot
type PostOption ¶
type PostOption func(*postOptions)
PostOption an option for post values
func SetAttachments ¶
func SetAttachments(attachments []slack.Attachment) PostOption
SetAttachments sets message attachments
func SetEphemeral ¶
func SetEphemeral(userID string) PostOption
SetEphemeral sets the user who receives the ephemeral message
func SetReplace ¶
func SetReplace(originalMessageTS string) PostOption
SetReplace sets message url to be replaced
func SetSchedule ¶
func SetSchedule(timestamp time.Time) PostOption
SetSchedule sets message's schedule
func SetThreadTS ¶
func SetThreadTS(threadTS string) PostOption
SetThreadTS specifies whether to reply inside a thread
type Replier ¶
type Replier struct {
// contains filtered or unexported fields
}
Replier sends messages to the same channel the event came from
func (*Replier) Reply ¶
func (r *Replier) Reply(message string, options ...ReplyOption) (string, error)
Reply send a message to the current channel
func (*Replier) ReplyBlocks ¶
ReplyBlocks send blocks to the current channel
func (*Replier) ReplyError ¶
func (r *Replier) ReplyError(err error, options ...ReplyOption) (string, error)
ReplyError send an error to the current channel
type ReplyOption ¶
type ReplyOption func(*replyOptions)
ReplyOption an option for reply values
func WithAttachments ¶
func WithAttachments(attachments []slack.Attachment) ReplyOption
WithAttachments sets message attachments
func WithInThread ¶
func WithInThread(inThread bool) ReplyOption
WithInThread specifies whether to reply inside a thread of the original message
func WithReplace ¶
func WithReplace(originalMessageTS string) ReplyOption
WithReplace replaces the original message
func WithSchedule ¶
func WithSchedule(timestamp time.Time) ReplyOption
WithSchedule sets message's schedule
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request contains the Event received and parameters
func (*Request) BooleanParam ¶
BooleanParam attempts to look up a boolean value by key. If not found, return the default boolean value
func (*Request) FloatParam ¶
FloatParam attempts to look up a float value by key. If not found, return the default float value
func (*Request) IntegerParam ¶
IntegerParam attempts to look up a integer value by key. If not found, return the default integer value
func (*Request) Param ¶
Param attempts to look up a string value by key. If not found, return the an empty string
func (*Request) Properties ¶
func (r *Request) Properties() *proper.Properties
Properties returns the properties of the request
type ResponseReplier ¶
type ResponseReplier struct {
// contains filtered or unexported fields
}
ResponseReplier sends messages to Slack
func (*ResponseReplier) Delete ¶
func (r *ResponseReplier) Delete(channel string, messageTimestamp string) (string, error)
Delete deletes a message in a channel
func (*ResponseReplier) Post ¶
func (r *ResponseReplier) Post(channel string, message string, options ...PostOption) (string, error)
Post send a message to a channel
func (*ResponseReplier) PostBlocks ¶
func (r *ResponseReplier) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
PostBlocks send blocks to a channel
func (*ResponseReplier) PostError ¶
func (r *ResponseReplier) PostError(channel string, err error, options ...PostOption) (string, error)
PostError send an error to a channel
func (*ResponseReplier) Reply ¶
func (r *ResponseReplier) Reply(message string, options ...ReplyOption) (string, error)
Reply send a message to the current channel
func (*ResponseReplier) ReplyBlocks ¶
func (r *ResponseReplier) ReplyBlocks(blocks []slack.Block, options ...ReplyOption) (string, error)
ReplyBlocks send blocks to the current channel
func (*ResponseReplier) ReplyError ¶
func (r *ResponseReplier) ReplyError(err error, options ...ReplyOption) (string, error)
ReplyError send an error to the current channel
type ResponseWriter ¶
type ResponseWriter struct {
// contains filtered or unexported fields
}
ResponseWriter sends messages to slack
func (*ResponseWriter) Delete ¶
func (r *ResponseWriter) Delete(channel string, messageTimestamp string) (string, error)
Delete deletes a message in a channel
func (*ResponseWriter) Post ¶
func (r *ResponseWriter) Post(channel string, message string, options ...PostOption) (string, error)
Post send a message to a channel
func (*ResponseWriter) PostBlocks ¶
func (r *ResponseWriter) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
PostBlocks send blocks to a channel
func (*ResponseWriter) PostError ¶
func (r *ResponseWriter) PostError(channel string, err error, options ...PostOption) (string, error)
PostError send an error to a channel
type Slacker ¶
type Slacker struct {
// contains filtered or unexported fields
}
Slacker contains the Slack API, botCommands, and handlers
func NewClient ¶
func NewClient(botToken, appToken string, clientOptions ...ClientOption) *Slacker
NewClient creates a new client using the Slack API
func (*Slacker) AddCommand ¶
func (s *Slacker) AddCommand(definition *CommandDefinition)
AddCommand define a new command and append it to the list of bot commands
func (*Slacker) AddCommandGroup ¶
func (s *Slacker) AddCommandGroup(prefix string) *CommandGroup
AddCommandGroup define a new group and append it to the list of groups
func (*Slacker) AddCommandMiddleware ¶
func (s *Slacker) AddCommandMiddleware(middleware CommandMiddlewareHandler)
AddCommandMiddleware appends a new command middleware to the list of root level command middlewares
func (*Slacker) AddInteraction ¶
func (s *Slacker) AddInteraction(definition *InteractionDefinition)
AddInteraction define a new interaction and append it to the list of interactions
func (*Slacker) AddInteractionMiddleware ¶
func (s *Slacker) AddInteractionMiddleware(middleware InteractionMiddlewareHandler)
AddInteractionMiddleware appends a new interaction middleware to the list of root level interaction middlewares
func (*Slacker) AddJob ¶
func (s *Slacker) AddJob(definition *JobDefinition)
AddJob define a new cron job and append it to the list of jobs
func (*Slacker) AddJobMiddleware ¶
func (s *Slacker) AddJobMiddleware(middleware JobMiddlewareHandler)
AddJobMiddleware appends a new job middleware to the list of root level job middlewares
func (*Slacker) GetCommandGroups ¶
func (s *Slacker) GetCommandGroups() []*CommandGroup
GetCommandGroups returns Command Groups
func (*Slacker) GetInteractions ¶
func (s *Slacker) GetInteractions() []*Interaction
GetInteractions returns Groups
func (*Slacker) Help ¶
func (s *Slacker) Help(definition *CommandDefinition)
Help handle the help message, it will use the default if not set
func (*Slacker) OnConnected ¶
func (s *Slacker) OnConnected(onConnected func(socketmode.Event))
OnConnected handle the event when the bot is connected
func (*Slacker) OnConnecting ¶
func (s *Slacker) OnConnecting(onConnecting func(socketmode.Event))
OnConnecting handle the event when the bot is connecting
func (*Slacker) OnConnectionError ¶
func (s *Slacker) OnConnectionError(onConnectionError func(socketmode.Event))
OnConnectionError handle the event when the bot fails to connect
func (*Slacker) OnDisconnected ¶
func (s *Slacker) OnDisconnected(onDisconnected func(socketmode.Event))
OnDisconnected handle the event when the bot is disconnected
func (*Slacker) OnHello ¶
func (s *Slacker) OnHello(onHello func(socketmode.Event))
OnHello handle the event when slack sends the bot "hello"
func (*Slacker) SanitizeEventTextHandler ¶
SanitizeEventTextHandler overrides the default event text sanitization
func (*Slacker) SlackClient ¶
SlackClient returns the internal slack.Client of Slacker struct
func (*Slacker) SocketModeClient ¶
func (s *Slacker) SocketModeClient() *socketmode.Client
SocketModeClient returns the internal socketmode.Client of Slacker struct
func (*Slacker) UnsupportedCommandHandler ¶
func (s *Slacker) UnsupportedCommandHandler(unsupportedCommandHandler CommandHandler)
UnsupportedCommandHandler handles messages when none of the commands are matched
func (*Slacker) UnsupportedEventHandler ¶
func (s *Slacker) UnsupportedEventHandler(unsupportedEventHandler func(socketmode.Event))
UnsupportedEventHandler handles events when an unknown event is seen
func (*Slacker) UnsupportedInteractionHandler ¶
func (s *Slacker) UnsupportedInteractionHandler(unsupportedInteractionHandler InteractionHandler)
UnsupportedInteractionHandler handles interactions when none of the callbacks are matched
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer sends messages to Slack
func (*Writer) PostBlocks ¶
func (r *Writer) PostBlocks(channel string, blocks []slack.Block, options ...PostOption) (string, error)
PostBlocks send blocks to a channel