A simple chat bot in Go(lang) inspired by Hubot
Creating new actions are as simple as this:
func myAction(input string) (string, error) {
// Check if action supports input.
if input != "test" {
return "", ErrEventNotSupportedByAction
}
return "Hello world!", nil
}
func init() {
RegisterAction("directed-message", myAction)
}
Creating new connections are as simple as this:
func myConnector(bot Bot, toActions chan<- Event, toChannel <-chan Event) {
// Inputs
go func() {
// Query from service (Discord, Slack, Rocket.Chat, etc) here.
EmitActions("directed-message", "test", toActions)
}()
// Outputs
go func() {
// Output to service from here
}()
}
func init() {
RegisterConnector(myConnector)
}
package mybot
import "github.com/scott-wilson/dosbot"
func main() {
bot := NewBot("test")
// Register actions first
dosbot.RegisterAction("directed-message", myAction)
// Register connectors
RegisterConnector(myConnector)
// Run
Run(bot)
}