slacker

package
v0.0.0-...-67e30d3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(opt *Options)

func ValidateOptions

func ValidateOptions(opt *Options) error

Types

type BotCommand

type BotCommand interface {
	Usage() string
	Definition() *CommandDefinition

	Match(text string) (*proper.Properties, bool)
	Tokenize() []*commander.Token
	Execute(request Request, response ResponseWriter)
}

BotCommand interface

func NewBotCommand

func NewBotCommand(usage string, definition *CommandDefinition) BotCommand

NewBotCommand creates a new bot command object

type ClientDefaults

type ClientDefaults struct {
	Debug bool
}

ClientDefaults configuration

type ClientOption

type ClientOption func(*ClientDefaults)

ClientOption an option for client values

func WithDebug

func WithDebug(debug bool) ClientOption

WithDebug sets debug toggle

type CommandDefinition

type CommandDefinition struct {
	Description       string
	Example           string
	AuthorizationFunc func(request Request) bool
	Handler           func(request Request, response ResponseWriter)
}

CommandDefinition structure contains definition of the bot command

type Options

type Options struct {
	ListenAddress     string
	VerificationToken string
}

type ReplyDefaults

type ReplyDefaults struct {
	Attachments    []slack.Attachment
	Blocks         []slack.Block
	ThreadResponse bool
}

ReplyDefaults configuration

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 WithBlocks

func WithBlocks(blocks []slack.Block) ReplyOption

WithBlocks sets message blocks

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

type ReportErrorOption

type ReportErrorOption func(*ReportErrorDefaults)

ReportErrorOption an option for report error values

func WithThreadError

func WithThreadError(useThread bool) ReportErrorOption

WithThreadError 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
	Context() context.Context
	Event() *slackevents.MessageEvent
	Properties() *proper.Properties
}

Request interface that contains the Event received and parameters

func NewRequest

func NewRequest(ctx context.Context, event *slackevents.MessageEvent, properties *proper.Properties) Request

NewRequest creates a new Request structure

type ResponseWriter

type ResponseWriter interface {
	Reply(text string, options ...ReplyOption) error
	ReportError(err error, options ...ReportErrorOption)
	Client() *slack.Client
}

A ResponseWriter interface is used to respond to an event

func NewResponse

func NewResponse(event *slackevents.MessageEvent, client *slack.Client) ResponseWriter

NewResponse creates a new response structure

type Slacker

type Slacker struct {
	// contains filtered or unexported fields
}

func NewSlacker

func NewSlacker(client *slack.Client, opt Options) *Slacker

func (*Slacker) Command

func (s *Slacker) Command(usage string, definition *CommandDefinition)

Command define a new command and append it to the list of existing commands

func (*Slacker) DefaultCommand

func (s *Slacker) DefaultCommand(defaultMessageHandler func(request Request, response ResponseWriter))

DefaultCommand handle messages when none of the commands are matched

func (*Slacker) Help

func (s *Slacker) Help(definition *CommandDefinition)

Help handle the help message, it will use the default if not set

func (*Slacker) Listen

func (s *Slacker) Listen(ctx context.Context) error

func (*Slacker) Run

func (s *Slacker) Run(ctx context.Context)

Jump to

Keyboard shortcuts

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