-
Notifications
You must be signed in to change notification settings - Fork 16
Components
go-sarah
is composed of fine-grained components to provide rich features with higher customizability. Those components have their own interfaces and default implementations, so developers are free to customize bot behavior by replacing default implementation with their own customized implementation. Those components support a unique feature called "stateful command" as well as some basic features such as command and scheduled task. In addition to those features, rich lifecycle management including live configuration update, customizable alerting mechanism, automated command/task (re-)building and concurrent command/task execution are supported.
Instead of trying to meet all developers’ needs with one implementation, this bot framework is composed of fine-grained replaceable components. Each component has its own interface and at least one default implementation. If one wishes to modify the bot’s behavior, one may implement the corresponding interface and replace the default implementation. They each are designed to have one and only one domain to serve, so customization should require minimum effort.
go-sarah
's core -- technically a private struct called runner
-- is responsible for coordinating all other components' life cycles.
See Runner for details.
sarah.Bot
implementation is responsible for receiving input from a chat service, responding with proper command execution, and sending output back to the chat service. While sarah.Runner
is responsible for coordinating all components, this works as a bridge between go-sarah's system and the connected chat service.
See Default Bot and Adapter for details.
sarah.Command
interface represents a plugin that receives user input and returns a response. See Command for details.
While the command is a job executed against user input, a scheduled task is a job that is executed in a scheduled manner. See ScheduledTask for details.
The idea and its implementation of "user's conversational context" is go-sarah's signature feature. While typical bot implementation is somewhat "stateless" and hence user-bot interaction does not consider the previous state, Sarah let sarah.Command
tell what action to follow on next user input and stash current state temporarily. UserContextStorage is where the user's current state is stored. See UserContextStorage for details.
sarah.Runner
coordinates other components' job execution with its internal worker. By default sarah.Worker
's default implementation that supports panic-proof concurrent job execution is used. A command is also executed in this worker so developers do not have to worry about flooding inputs. Use preferred sarah.Worker
implementation to customize worker behavior.
When a bot confronts a critical situation and cannot continue its operation or recover, go-sarah's alerting mechanism sends an alert to the administrator. Zero or more sarah.Alerter
implementations can be registered to send alerts to desired destinations.
Seee Alerter for details.
sarah.ConfigWatcher
subscribes to change events of sarah.Command
/sarah.ScheduledTask
s' configuration values. When this notifies a change for a configuration, Live Configuration Update is triggered and the corresponding Command/ScheduledTask is updated. A reference implementation that subscribes to the file system is provided. Other configuration repository systems such as Hashicorp's Consul or LINE's Central Dogma can be subscribed by implementing sarah.ConfigWatcher
.
To have a grasp of overall architecture, have a look at Components.