Documentation ¶
Index ¶
- type BotContext
- type BotInteractionMode
- type ClientDefaults
- type ClientOption
- type Command
- type CommandDefinition
- type CommandEvent
- type InteractiveBotContext
- type Job
- type JobContext
- type JobDefinition
- type MessageEvent
- type ReplyDefaults
- type ReplyOption
- type ReportErrorDefaults
- type ReportErrorOption
- type Request
- type ResponseWriter
- type Slacker
- func (s *Slacker) APIClient() *slack.Client
- func (s *Slacker) BotCommands() []Command
- func (s *Slacker) Command(usage string, definition *CommandDefinition)
- func (s *Slacker) CommandEvents() <-chan *CommandEvent
- func (s *Slacker) CustomBotContext(...)
- func (s *Slacker) CustomCommand(commandConstructor func(usage string, definition *CommandDefinition) Command)
- func (s *Slacker) CustomInteractiveBotContext(...)
- func (s *Slacker) CustomJobContext(...)
- func (s *Slacker) CustomRequest(...)
- func (s *Slacker) CustomResponse(responseConstructor func(botCtx BotContext) ResponseWriter)
- func (s *Slacker) DefaultCommand(...)
- func (s *Slacker) DefaultEvent(defaultEventHandler func(interface{}))
- func (s *Slacker) DefaultInnerEvent(...)
- func (s *Slacker) Err(errorHandler func(err string))
- func (s *Slacker) Help(definition *CommandDefinition)
- func (s *Slacker) Init(initHandler func())
- func (s *Slacker) Interactive(...)
- func (s *Slacker) Job(spec string, definition *JobDefinition)
- func (s *Slacker) Listen(ctx context.Context) error
- func (s *Slacker) SanitizeEventText(sanitizeEventText func(in string) string)
- func (s *Slacker) SocketModeClient() *socketmode.Client
- func (s *Slacker) UnAuthorizedError(errUnauthorized error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotContext ¶
type BotContext interface { Context() context.Context Event() *MessageEvent APIClient() *slack.Client SocketModeClient() *socketmode.Client }
BotContext interface is for bot command contexts
func NewBotContext ¶
func NewBotContext(ctx context.Context, apiClient *slack.Client, socketModeClient *socketmode.Client, event *MessageEvent) BotContext
NewBotContext creates a new bot context
type BotInteractionMode ¶
type BotInteractionMode int
BotInteractionMode instruct the bot on how to handle incoming events that originated from a bot.
const ( // BotInteractionModeIgnoreAll instructs our bot to ignore any activity coming // from other bots, including our self. BotInteractionModeIgnoreAll BotInteractionMode = iota // BotInteractionModeIgnoreApp 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. BotInteractionModeIgnoreApp // BotInteractionModeIgnoreNone 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. BotInteractionModeIgnoreNone )
type ClientDefaults ¶
type ClientDefaults struct { Debug bool BotMode BotInteractionMode }
ClientDefaults configuration
type ClientOption ¶
type ClientOption func(*ClientDefaults)
ClientOption an option for client values
func WithBotInteractionMode ¶
func WithBotInteractionMode(mode BotInteractionMode) ClientOption
WithBotInteractionMode instructs Slacker on how to handle message events coming from a bot.
type Command ¶ added in v1.4.0
type Command interface { Usage() string Definition() *CommandDefinition Match(string) (*proper.Properties, bool) Tokenize() []*commander.Token Execute(BotContext, Request, ResponseWriter) Interactive(InteractiveBotContext, *socketmode.Request, *slack.InteractionCallback) }
Command interface
func NewCommand ¶ added in v1.4.0
func NewCommand(usage string, definition *CommandDefinition) Command
NewCommand creates a new bot command object
type CommandDefinition ¶
type CommandDefinition struct { Description string Examples []string BlockID string AuthorizationFunc func(BotContext, Request) bool Handler func(BotContext, Request, ResponseWriter) Interactive func(InteractiveBotContext, *socketmode.Request, *slack.InteractionCallback) // HideHelp will hide this command definition from appearing in the `help` results. HideHelp bool }
CommandDefinition structure contains definition of the bot command
type CommandEvent ¶
type CommandEvent struct { Timestamp time.Time Command string Parameters *proper.Properties Event *MessageEvent }
CommandEvent is an event to capture executed commands
func NewCommandEvent ¶
func NewCommandEvent(command string, parameters *proper.Properties, event *MessageEvent) *CommandEvent
NewCommandEvent creates a new command event
type InteractiveBotContext ¶ added in v1.4.0
type InteractiveBotContext interface { Context() context.Context Event() *socketmode.Event APIClient() *slack.Client SocketModeClient() *socketmode.Client }
InteractiveBotContext interface is interactive bot command contexts
func NewInteractiveBotContext ¶ added in v1.4.0
func NewInteractiveBotContext(ctx context.Context, apiClient *slack.Client, socketModeClient *socketmode.Client, event *socketmode.Event) InteractiveBotContext
NewInteractiveBotContext creates a new interactive bot context
type Job ¶ added in v1.4.0
type Job interface { Spec() string Definition() *JobDefinition Callback(JobContext) func() }
Job interface
func NewJob ¶ added in v1.4.0
func NewJob(spec string, definition *JobDefinition) Job
NewJob creates a new job object
type JobContext ¶ added in v1.4.0
type JobContext interface { Context() context.Context APIClient() *slack.Client SocketModeClient() *socketmode.Client }
JobContext interface is for job command contexts
func NewJobContext ¶ added in v1.4.0
func NewJobContext(ctx context.Context, apiClient *slack.Client, socketModeClient *socketmode.Client) JobContext
NewJobContext creates a new bot context
type JobDefinition ¶ added in v1.4.0
type JobDefinition struct { Description string Handler func(JobContext) // HideHelp will hide this job definition from appearing in the `help` results. HideHelp bool }
JobDefinition structure contains definition of the job
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 interface{} // 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 NewMessageEvent ¶ added in v1.4.0
func NewMessageEvent(slacker *Slacker, event interface{}, req *socketmode.Request) *MessageEvent
NewMessageEvent creates a new message event structure
func (*MessageEvent) IsBot ¶
func (e *MessageEvent) IsBot() bool
IsBot indicates if the message was sent by a bot
func (*MessageEvent) IsThread ¶
func (e *MessageEvent) IsThread() bool
IsThread indicates if a message event took place in a thread.
type ReplyDefaults ¶
type ReplyDefaults struct { Attachments []slack.Attachment Blocks []slack.Block ThreadResponse bool }
ReplyDefaults configuration
func NewReplyDefaults ¶
func NewReplyDefaults(options ...ReplyOption) *ReplyDefaults
NewReplyDefaults builds our ReplyDefaults from zero or more ReplyOption.
type ReplyOption ¶
type ReplyOption func(*ReplyDefaults)
ReplyOption an option for reply values
func WithAttachments ¶
func WithAttachments(attachments []slack.Attachment) ReplyOption
WithAttachments sets message attachments
func WithThreadReply ¶
func WithThreadReply(useThread bool) ReplyOption
WithThreadReply specifies the reply to be inside a thread of the original message
type ReportErrorDefaults ¶
type ReportErrorDefaults struct {
ThreadResponse bool
}
ReportErrorDefaults configuration
func NewReportErrorDefaults ¶
func NewReportErrorDefaults(options ...ReportErrorOption) *ReportErrorDefaults
NewReportErrorDefaults builds our ReportErrorDefaults from zero or more ReportErrorOption.
type ReportErrorOption ¶
type ReportErrorOption func(*ReportErrorDefaults)
ReportErrorOption an option for report error values
func WithThreadReplyError ¶ added in v1.4.0
func WithThreadReplyError(useThread bool) ReportErrorOption
WithThreadReplyError specifies the reply to be inside a thread of the original message
type Request ¶
type Request interface { Param(key string) string StringParam(key string, defaultValue string) string BooleanParam(key string, defaultValue bool) bool IntegerParam(key string, defaultValue int) int FloatParam(key string, defaultValue float64) float64 Properties() *proper.Properties }
Request interface that contains the Event received and parameters
func NewRequest ¶
func NewRequest(botCtx BotContext, properties *proper.Properties) Request
NewRequest creates a new Request structure
type ResponseWriter ¶
type ResponseWriter interface { Post(channel string, message string, options ...ReplyOption) error Reply(text string, options ...ReplyOption) error ReportError(err error, options ...ReportErrorOption) }
A ResponseWriter interface is used to respond to an event
func NewResponse ¶
func NewResponse(botCtx BotContext) ResponseWriter
NewResponse creates a new response structure
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, options ...ClientOption) *Slacker
NewClient creates a new client using the Slack API
func (*Slacker) APIClient ¶ added in v1.4.1
APIClient returns the internal slack.Client of Slacker struct
func (*Slacker) BotCommands ¶
BotCommands returns Bot Commands
func (*Slacker) Command ¶
func (s *Slacker) Command(usage string, definition *CommandDefinition)
Command define a new command and append it to the list of existing bot commands
func (*Slacker) CommandEvents ¶
func (s *Slacker) CommandEvents() <-chan *CommandEvent
CommandEvents returns read only command events channel
func (*Slacker) CustomBotContext ¶ added in v0.1.0
func (s *Slacker) CustomBotContext(botContextConstructor func(context.Context, *slack.Client, *socketmode.Client, *MessageEvent) BotContext)
CustomBotContext creates a new bot context
func (*Slacker) CustomCommand ¶ added in v0.1.0
func (s *Slacker) CustomCommand(commandConstructor func(usage string, definition *CommandDefinition) Command)
CustomCommand creates a new BotCommand
func (*Slacker) CustomInteractiveBotContext ¶ added in v1.4.0
func (s *Slacker) CustomInteractiveBotContext(interactiveBotContextConstructor func(context.Context, *slack.Client, *socketmode.Client, *socketmode.Event) InteractiveBotContext)
CustomInteractiveBotContext creates a new interactive bot context
func (*Slacker) CustomJobContext ¶ added in v1.4.0
func (s *Slacker) CustomJobContext(jobContextConstructor func(context.Context, *slack.Client, *socketmode.Client) JobContext)
CustomJobContext creates a new job context
func (*Slacker) CustomRequest ¶
func (s *Slacker) CustomRequest(requestConstructor func(botCtx BotContext, properties *proper.Properties) Request)
CustomRequest creates a new request
func (*Slacker) CustomResponse ¶
func (s *Slacker) CustomResponse(responseConstructor func(botCtx BotContext) ResponseWriter)
CustomResponse creates a new response writer
func (*Slacker) DefaultCommand ¶
func (s *Slacker) DefaultCommand(defaultMessageHandler func(botCtx BotContext, request Request, response ResponseWriter))
DefaultCommand handle messages when none of the commands are matched
func (*Slacker) DefaultEvent ¶
func (s *Slacker) DefaultEvent(defaultEventHandler func(interface{}))
DefaultEvent handle events when an unknown event is seen
func (*Slacker) DefaultInnerEvent ¶ added in v1.3.0
func (s *Slacker) DefaultInnerEvent(defaultInnerEventHandler func(ctx context.Context, evt interface{}, request *socketmode.Request))
DefaultInnerEvent handle events when an unknown inner event is seen
func (*Slacker) Help ¶
func (s *Slacker) Help(definition *CommandDefinition)
Help handle the help message, it will use the default if not set
func (*Slacker) Init ¶
func (s *Slacker) Init(initHandler func())
Init handle the event when the bot is first connected
func (*Slacker) Interactive ¶
func (s *Slacker) Interactive(interactiveEventHandler func(InteractiveBotContext, *slack.InteractionCallback))
Interactive assigns an interactive event handler
func (*Slacker) Job ¶ added in v1.4.0
func (s *Slacker) Job(spec string, definition *JobDefinition)
Job define a new cron job and append it to the list of existing jobs
func (*Slacker) SanitizeEventText ¶ added in v1.4.0
SanitizeEventText allows the api consumer to override the default event text sanitization
func (*Slacker) SocketModeClient ¶ added in v1.4.0
func (s *Slacker) SocketModeClient() *socketmode.Client
SocketModeClient returns the internal socketmode.Client of Slacker struct
func (*Slacker) UnAuthorizedError ¶
UnAuthorizedError error message