Documentation
¶
Index ¶
- Variables
- func AddAdapter(a Adapter)
- func GetCommandEntry(ctx context.Context, bundleName, commandName string) (data.CommandEntry, error)
- func GetCommandEntryByTrigger(ctx context.Context, tokens []string) (data.CommandEntry, error)
- func GetCommandRequest(ctx context.Context, rawCommand string, id RequestorIdentity, ...) (*data.CommandRequest, error)
- func OnChannelMessage(ctx context.Context, event *ProviderEvent, data *ChannelMessageEvent) (*data.CommandRequest, error)
- func OnConnected(ctx context.Context, event *ProviderEvent, data *ConnectedEvent)
- func OnDirectMessage(ctx context.Context, event *ProviderEvent, data *DirectMessageEvent) (*data.CommandRequest, error)
- func SendEnvelope(ctx context.Context, a Adapter, channelID string, ...) error
- func SendErrorMessage(ctx context.Context, a Adapter, channelID string, title, text string) error
- func SendMessage(ctx context.Context, a Adapter, channelID string, message string) error
- func StartListening(ctx context.Context) (<-chan data.CommandRequest, chan<- data.CommandResponseEnvelope, <-chan error)
- func TokenizeParameters(commandString string) []string
- type Adapter
- type AuthenticationErrorEvent
- type ChannelInfo
- type ChannelJoinedEvent
- type ChannelMessageEvent
- type ConnectedEvent
- type DirectMessageEvent
- type DisconnectedEvent
- type ErrorEvent
- type EventType
- type Info
- type ProviderEvent
- type ProviderInfo
- type RequestorIdentity
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAdapterNameCollision is emitted by AddAdapter() if two adapters // have the same name. ErrAdapterNameCollision = errors.New("adapter name collision") // ErrAuthenticationFailure is emitted when an AuthenticationErrorEvent // is received. ErrAuthenticationFailure = errors.New("authentication failure") // ErrChannelNotFound is returned when OnChannelMessage can't find // information is the originating channel. ErrChannelNotFound = errors.New("channel not found") // ErrGortNotBootstrapped is returned by findOrMakeGortUser() if a user // attempts to trigger a command but Gort hasn't yet been bootstrapped. ErrGortNotBootstrapped = errors.New("gort hasn't been bootstrapped yet") // ErrSelfRegistrationOff is returned by findOrMakeGortUser() if an unknown // user attempts to trigger a command but self-registration is configured // to false. ErrSelfRegistrationOff = errors.New("user doesn't exist and self-registration is off") // ErrMultipleCommands is returned by GetCommandEntry when the same command // shortcut matches commands in two or more bundles. ErrMultipleCommands = errors.New("multiple commands match that pattern") // ErrNoSuchAdapter is returned by GetAdapter if a requested adapter name // can't be found. ErrNoSuchAdapter = errors.New("no such adapter") // ErrNoSuchCommand is returned by GetCommandEntry if a request command // isn't found. ErrNoSuchCommand = errors.New("no such bundle") // ErrUserNotFound is throws by several methods if a provider fails to // return requested user information. ErrUserNotFound = errors.New("user not found") // ErrNotAllowed is thrown when checking user permissions for a command if // the user does not have the appropriate permissions to use the command. ErrNotAllowed = errors.New("user not allowed to use command") )
Functions ¶
func GetCommandEntry ¶
func GetCommandEntry(ctx context.Context, bundleName, commandName string) (data.CommandEntry, error)
GetCommandEntry accepts a tokenized parameter slice and returns any associated data.CommandEntry instances. If the number of matching commands is > 1, an error is returned.
func GetCommandEntryByTrigger ¶
GetCommandEntryByTrigger accepts a tokenized parameter slice and returns any associated data.CommandEntry instances. If the number of matching commands is > 1, an error is returned.
func GetCommandRequest ¶
func GetCommandRequest( ctx context.Context, rawCommand string, id RequestorIdentity, fCommandFromTokens commandFromTokens, ) (*data.CommandRequest, error)
GetCommandRequest builds a CommandRequest object based on the provided message content and user id. Both user existence and authorization are verified. A lookup function for identifying a command based on tokens must be provided as a parameter. Telemetry for the lookup operation are handled inside this function.
func OnChannelMessage ¶
func OnChannelMessage(ctx context.Context, event *ProviderEvent, data *ChannelMessageEvent) (*data.CommandRequest, error)
OnChannelMessage handles ChannelMessageEvent events. If a command is found in the text, it will emit a data.CommandRequest instance to the commands channel. TODO Support direct in-channel mentions.
func OnConnected ¶
func OnConnected(ctx context.Context, event *ProviderEvent, data *ConnectedEvent)
OnConnected handles ConnectedEvent events.
func OnDirectMessage ¶
func OnDirectMessage(ctx context.Context, event *ProviderEvent, data *DirectMessageEvent) (*data.CommandRequest, error)
OnDirectMessage handles DirectMessageEvent events.
func SendEnvelope ¶ added in v0.9.0
func SendEnvelope(ctx context.Context, a Adapter, channelID string, envelope data.CommandResponseEnvelope, tt data.TemplateType) error
Send the contents of a response envelope to a specified channel. If channelID is empty the value of envelope.Request.ChannelID will be used.
func SendErrorMessage ¶ added in v0.9.0
SendErrorMessage sends an error message to a specified channel.
func SendMessage ¶ added in v0.9.0
SendMessage sends a standard output message to a specified channel.
func StartListening ¶
func StartListening(ctx context.Context) (<-chan data.CommandRequest, chan<- data.CommandResponseEnvelope, <-chan error)
StartListening instructs all relays to establish connections, receives all events from all relays, and forwards them to the various On* handler functions.
func TokenizeParameters ¶
TokenizeParameters splits a command string into parameter tokens. Any trigger characters (i.e., !) are expected to have already been removed.
Types ¶
type Adapter ¶
type Adapter interface { // GetChannelInfo provides info on a specific provider channel accessible // to the adapter. GetChannelInfo(channelID string) (*ChannelInfo, error) // GetName provides the name of this adapter as per the configuration. GetName() string // GetPresentChannels returns a slice of channels that the adapter is present in. GetPresentChannels() ([]*ChannelInfo, error) // GetUserInfo provides info on a specific provider user accessible // to the adapter. GetUserInfo(userID string) (*UserInfo, error) // Listen causes the Adapter to initiate a connection to its provider and // begin relaying back events (including errors) via the returned channel. Listen(ctx context.Context) <-chan *ProviderEvent // Send sends the contents of a response envelope to a // specified channel. If channelID is empty the value of // envelope.Request.ChannelID will be used. Send(ctx context.Context, channelID string, elements templates.OutputElements) error // SendText sends a simple text message to the specified channel. SendText(ctx context.Context, channelID string, message string) error // SendError is a break-glass error message function that's used when the // templating function fails somehow. Obviously, it does not utilize the // templating engine. SendError(ctx context.Context, channelID string, title string, err error) error }
Adapter represents a connection to a chat provider.
func GetAdapter ¶
GetAdapter returns the requested adapter instance, if one exists. If not, an error is returned.
type AuthenticationErrorEvent ¶
type AuthenticationErrorEvent struct {
Msg string
}
AuthenticationErrorEvent indicates failure to authenticate
type ChannelInfo ¶
ChannelInfo contains the basic information for a single channel in any provider.
type ChannelJoinedEvent ¶
type ChannelJoinedEvent struct {
Channel string
}
ChannelJoinedEvent indicates the bot has joined a channel
type ChannelMessageEvent ¶
ChannelMessageEvent indicates received a message via a public or private channel (message.channels)
type ConnectedEvent ¶
type ConnectedEvent struct { }
ConnectedEvent indicates the client has successfully connected to the provider server
type DirectMessageEvent ¶
DirectMessageEvent indicates the bot has received a direct message from a user (message.im)
type DisconnectedEvent ¶
type DisconnectedEvent struct {
Intentional bool
}
DisconnectedEvent indicates the client has disconnected from the provider server
type ErrorEvent ¶
ErrorEvent indicates an error reported by the provider. The occurs before a successful connection, Code will be unset.
func (ErrorEvent) Error ¶
func (e ErrorEvent) Error() string
type EventType ¶ added in v0.8.2
type EventType string
EventType specifies the kind of event received from an adapter in response to an event from the chat server.
const ( EventChannelMessage EventType = "channel_message" EventConnected EventType = "connected" EventConnectionError EventType = "connection_error" EventDirectMessage EventType = "direct_message" EventDisconnected EventType = "disconnected" EventAuthenticationError EventType = "authentication_error" EventError EventType = "error" )
type Info ¶
type Info struct {
Provider *ProviderInfo
}
Info is used by events to wrap user and provider info.
type ProviderEvent ¶
type ProviderEvent struct { // The type of event EventType EventType // The event instance Data interface{} // Contextual info (user, provider) Info *Info // The adapter that generated the event Adapter Adapter }
ProviderEvent is the main wrapper. You will find all the other messages attached as Data
type ProviderInfo ¶
ProviderInfo contains the basic information for a chat provider.
func NewProviderInfoFromConfig ¶
func NewProviderInfoFromConfig(provider data.Provider) *ProviderInfo
NewProviderInfoFromConfig can create a ProviderInfo from a data.Provider instance.
type RequestorIdentity ¶
type RequestorIdentity struct { Adapter Adapter ChatUser *UserInfo ChatChannel *ChannelInfo GortUser *rest.User }