autobot

module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2020 License: Apache-2.0

README

Autobot

Autobot

gopherbadger-tag-do-not-edit Github Action Go Report Card License Apache 2 Taylor Swift Volkswagen

Autobot is your nice and friendly bot. He is here to save you from the 👹 decepticons of #devops and other evil.

🙈 Contributions are welcome.

Features

Purpose

We build Autobot to be a scalable and pluggable tool for creating any kind of bot or chat operations tool. We choose NATS + NATS Streaming Server as the foundation because it is natual to use a log-based storage for any kind of messaging system. But also because it can be embedded. Embedding the storage into the server makes it much easier to have Autobot up and running.

Because we use a message queue as foundation we can build any kind of plugins via Pub/Sub on top of it. NATS uses the Raft Algoritm for replication, which also means that our server uses replication and can be highly available. This is really create for large-scale systems, archiving and auditing (we may think about end to end encryption later). Again, the intention for Autobot was to have this run in production at scale.

Architecture

Autobot is made of a server and plugins. The server starts an embedded Nats Streaming Server. The plugins subscribe and publish message to the provided queues. They can be run in their custom Docker containers. The plugins are started with an environment that exposes two channels for publishing and subscribing to messages and some more information. The plugins package exposed functions to subscribe to the inbox channel, which should be used to publish messages from message services and outbox which should publish to these services (e.g. Slack or Microsoft Teams).

    Slack /                                                                
 Microsoft Teams               +-----------------------------------+    
        ^                    +-|---------------------------------+ |    
        |                    | |            Server               | |    
        |                    | | +---------------+               | |    
 +------|---------\          | | |     NATS      |               | |    
 |   Plugin    |   -----\    | | |               |               | |    
 +-------------<-\       -----\| |+-------------+|               | |    
                  ----\    ------->   Inbox     ||               | |    
                   -------\  | | |+-------------+|               | |    
 +-------------<--/        ----\ |+-------------+|               | |    
 |   Plugin    |         --------->   Outbox    ||               | |    
 +----------------------/    | | |+-------------+|               | |    
                             | | +---------------+               | |    
                             | +-----------------------------------+    
                             +-----------------------------------+  
Clustering

NATS Streaming Server supports clustering and data replication. Because Autobot embedds the streaming server it supports clustering as the mechanism for high availability. Autobot supports the two modes of clustering. We recommend the "auto" mode in which you specify the list of peers to each started node. They elect a leader and start the replication. Because it uses the RAFT consensus algorithm it needs an uneven number of peers in the cluster. 3 or 5 are sufficient.

# this create a cluster consiting of 3 nodes
docker-compose up

Plugins

godoc.org for writing plugins

The plugins package provides you a simplified interface to connect to the underlying NATS server. You can subscribe and publishe to the autobot.inbox and autobot.outbox topics. Also it provides you with an easy interface to the messages. It is actually the place where much of the ✨ happens.

There are some example plugins which demonstrate the capabilities of Autobot.

Plugins are run on their own. They are not controlled by the server. Autobot uses pub/sub to be pluggable.

Plugins can be either configured by the automatically exposed command line parameters or the prefixed environment variables. A plugin can use the provided and automatically populated environment from the runtime. They use these environment variables to populated the runtime environment.

  • AUTOBOT_CLUSTER_URL
  • AUTOBOT_CLUSTER_ID
  • AUTOBOT_INBOX
  • AUTOBOT_OUTBOX
  • AUTOBOT_LOG_FORMAT
  • AUTOBOT_LOG_LEVEL

Example for the Slack Plugin:

SLACK_TOKEN=
AUTOBOT_CLUSTER_ID=autobot
AUTOBOT_CLUSTER_URL=nats://controller:4222
AUTOBOT_LOG_FORMAT=json
AUTOBOT_LOG_LEVEL=info
AUTOBOT_DEBUG=true
AUTOBOT_VERBOSE=true

There are two log formats supported text (default) and json. The log levels reflect the logrus levels.

Example

The images are hosted on Docker Hub you should change .env for your specific setup (very much only add a valid Slack Bot Token)

This example uses Docker Compose and you will need a Slack Bot Token (e.g. xob-xxxx).

You should provide this token in the .env file. Which is used to configure the plugins containers. Because Autobot is using pub/sub to communicate with its plugins they can be run independently in their own containers. Anders Normal contains the plugins in containers.

# start the containers
docker-compose up

You should now see your Slack Bot connect in your Workspace and can send him a direct message which he will respond to with hello world.

🙌 you have your own bot running.

Next, you can write your own plugins. It would be really cool if you could contribute it.

Development

we use Picasso for build automation

You can build the Protobuf by running

picasso proto

We use a specific version of proto package generator. In order to build it with this version you will have to install it as follows

GIT_TAG="v1.2.0" # change as needed
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go

The server is build by running

picasso build/server

The options of the server can be shown by ./server --help.

License

Apache 2.0

Directories

Path Synopsis
pkg
plugins
Package plugins provides the functionality to subscribe, and publish message according to the plugin.proto.
Package plugins provides the functionality to subscribe, and publish message according to the plugin.proto.
plugins/filters
Package filters provides functionality to filter messages.
Package filters provides functionality to filter messages.
plugins/runtime
Package runtime contains functionality for runtime information of a plugin.
Package runtime contains functionality for runtime information of a plugin.
cmd

Jump to

Keyboard shortcuts

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