Skip to content

Components

Go Hagiwara edited this page Jul 7, 2019 · 12 revisions

Overview

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 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.

Design Rationale

Instead of trying to meet all developers’ needs, this bot framework is composed of fine-grained replaceable components. Each component has its interface and at least one default implementation. If one wishes to modify bot’s behavior, one may implement the corresponding interface and replace default implementation. They each are designed to have one and only one domain to serve, so customization should require minimum effort.

Details

Runner

sarah.Runner is responsible for coordinating all other components life cycles. See Runner for details.

Bot / Adapter

sarah.Bot implementation is responsible for receiving input from chat service, respond with proper command execution, sending output back to chat service. While sarah.Runner is responsible for coordinating all components, this works as a bridge between go-sarah's system and connected chat service. See Default Bot and Adapter for details.

Command

sarah.Command interface represents a plugin that receives user input and returns response. See Command for details.

Scheduled Task

While the command is a job that is executed against user input, a scheduled task is a job that is executed in a scheduled manner. See ScheduledTask for details.

UserContextStorage

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 temporary. UserContextStorage is where user's current state is stored. See UserContextStorage for details.

Worker

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. 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.

Alerter

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.

Clone this wiki locally