Extensible matrix bot written in Go
Switch branches/tags
feature-slack-api gh-pages hs/remove-rss-url-metric kegan/all-the-docs kegan/auth-realms kegan/auth-session-api-tweak kegan/auth-session kegan/auth kegan/base64-paths kegan/better-gh-cmd-regex kegan/bot-options kegan/cache-rss-feeds kegan/case-insensitive-commands kegan/config-yaml kegan/configure-client-name kegan/create-with-json kegan/database-is-locked kegan/db-interface kegan/docs-services kegan/dots-in-repos kegan/expand-with-groups kegan/fail-if-bad-user kegan/feed-leak kegan/feedreader-struct kegan/feedreader kegan/finer-gh-controls kegan/fix-log-field-names kegan/get-service kegan/get-session kegan/gh-explicit-unregister-webhooks kegan/gh-help kegan/gh-logout kegan/gh-no-webhooks-means-no-service kegan/gh-service-client-id-is-opt kegan/giphy-translate-api kegan/giphy kegan/github-auth kegan/github-cmd-expan-service kegan/github-cmds kegan/github-join-room-on-register kegan/github-make-webhooks-on-register kegan/github-mutex-on-register kegan/github-possible-repos kegan/github-remove-hooks-on-webhook-event kegan/github-say-which-labels kegan/github-service kegan/github-starter-links kegan/github-webhook-creation kegan/github-webhook kegan/github kegan/gomatrix kegan/guggy-tests kegan/httpcache-update kegan/ignore-events-on-join kegan/jira-auth-sessions kegan/jira-auth kegan/jira-commands kegan/jira-expansion kegan/jira-realm kegan/jira-redirect kegan/jira-starter-links kegan/jira-webhook-2 kegan/jira-webhooks kegan/jsonresponse kegan/logging kegan/matrix-org-util kegan/metrics kegan/min-guid-length kegan/move-handlers kegan/neb-metrics kegan/per-service-poll kegan/persist-next-batch kegan/readme-to-docs kegan/realm-docs kegan/redirect kegan/remove-docs-from-readme kegan/remove-plugin kegan/rm-3pauth kegan/rss-dont-replace-if-no-guids kegan/rss-escape-entities kegan/rss-guids kegan/rss-limits kegan/rss-no-cache kegan/rss-notify-on-failures kegan/rss-user-agent kegan/rss kegan/rssbot kegan/service-docs kegan/service-isolation kegan/shut-up-golint kegan/smart-quotes kegan/split-gh-service kegan/sync-on-startup kegan/tests-prep kegan/tests kegan/testutils kegan/text-logging kegan/travis kegan/webhook-endpoint-fn kegan/webhook-path-as-id kegan/webhooks luke/guggy master michaelkaye/log_alertmanager_errors michaelkaye/upgrade-go rob/docker rxl881/google rxl881/riotbot t3chguy/github_regex_tweaks
Nothing to show
Clone or download

README.md

Go-NEB

Build Status

Go-NEB is a Matrix bot written in Go. It is the successor to Matrix-NEB, the original Matrix bot written in Python.

Table of Contents

Quick Start

Clone and run (Requires Go 1.7+ and GB):

gb build github.com/matrix-org/go-neb
BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=go-neb.db?_busy_timeout=5000 BASE_URL=http://localhost:4050 bin/go-neb

Get a Matrix user ID and access token and give it to Go-NEB:

curl -X POST localhost:4050/admin/configureClient --data-binary '{
    "UserID": "@goneb:localhost",
    "HomeserverURL": "http://localhost:8008",
    "AccessToken": "<access_token>",
    "Sync": true,
    "AutoJoinRooms": true,
    "DisplayName": "My Bot"
}'

Tell it what service to run:

curl -X POST localhost:4050/admin/configureService --data-binary '{
    "Type": "echo",
    "Id": "myserviceid",
    "UserID": "@goneb:localhost",
    "Config": {}
}'

Invite the bot user into a Matrix room and type !echo hello world. It will reply with hello world.

Features

Github

  • Login with OAuth2.
  • Ability to create Github issues on any project.
  • Ability to track updates (add webhooks) to projects. This includes new issues, pull requests as well as commits.
  • Ability to expand issues when mentioned as foo/bar#1234.
  • Ability to assign a "default repository" for a Matrix room to allow #1234 to automatically expand, as well as shorter issue creation command syntax.

JIRA

  • Login with OAuth1.
  • Ability to create JIRA issues on a project.
  • Ability to expand JIRA issues when mentioned as FOO-1234.

Giphy

  • Ability to query Giphy's "text-to-gif" engine.

Guggy

  • Ability to query Guggy's gif engine.

RSS Bot

  • Ability to read Atom/RSS feeds.

Travis CI

  • Ability to receive incoming build notifications.
  • Ability to adjust the message which is sent into the room.

Alertmanager

  • Ability to receive alerts and render them with go templates

Installing

Go-NEB is built using Go 1.7+ and GB. Once you have installed Go, run the following commands:

# Install gb
go get github.com/constabulary/gb/...

# Clone the go-neb repository
git clone https://github.com/matrix-org/go-neb
cd go-neb

# Build go-neb
gb build github.com/matrix-org/go-neb

Running

Go-NEB uses environment variables to configure its SQLite database and bind address. To run Go-NEB, run the following command:

BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=go-neb.db?_busy_timeout=5000 BASE_URL=https://public.facing.endpoint bin/go-neb
  • BIND_ADDRESS is the port to listen on.
  • DATABASE_TYPE MUST be "sqlite3". No other type is supported.
  • DATABASE_URL is where to find the database file. One will be created if it does not exist. It is a URL so parameters can be passed to it. We recommend setting _busy_timeout=5000 to prevent sqlite3 "database is locked" errors.
  • BASE_URL should be the public-facing endpoint that sites like Github can send webhooks to.
  • CONFIG_FILE is the path to the configuration file to read from. This isn't included in the example above, so Go-NEB will operate in HTTP mode.
  • LOG_DIR is a directory that log files will be written to, with log rotation enabled. If set, logging to stderr will be disabled. Go-NEB needs to be "configured" with clients and services before it will do anything useful. It can be configured via a configuration file OR by an HTTP API.

Configuration file

If you run Go-NEB with a CONFIG_FILE environment variable, it will load that file and use it for services, clients, etc. There is a sample configuration file which explains all the options. In most cases, these are direct mappings to the corresponding HTTP API.

API

The API is documented in sections using godoc. The sections consists of:

  • An HTTP API (the path and method to use)
  • A "JSON request body" (the JSON that is inside the HTTP request body)
  • "Configuration" information (any additional information that is specific to what you're creating)

To form the complete API, you need to combine the HTTP API with the JSON request body, and the "Configuration" information (which is always under a JSON key called Config). In addition, most APIs have a Type which determines which piece of code to load. To find out what the right type is for the thing you're creating, check the constants defined in godoc.

Configuring Clients

Go-NEB needs to connect as a matrix user to receive messages. Go-NEB can listen for messages as multiple matrix users. The users are configured using an HTTP API and the config is stored in the database.

Configuring Services

Services contain all the useful functionality in Go-NEB. They require a client to operate. Services are configured using an HTTP API and the config is stored in the database. Services use one of the matrix users configured on Go-NEB to send/receive matrix messages.

Every service has an "ID", "type" and "user ID". Services may specify additional "config" keys: see the specific service you're interested in for the additional keys, if any.

List of Services:

Configuring Realms

Realms are how Go-NEB authenticates users on third-party websites.

List of Realms:

Authentication via HTTP:

Authentication via the config file:

Developing

There's a bunch more tools this project uses when developing in order to do things like linting. Some of them are bundled with go (fmt and vet) but some are not. You should install the ones which are not:

go get github.com/golang/lint/golint
go get github.com/fzipp/gocyclo

You can then install the pre-commit hook:

./hooks/install.sh

Architecture


   HOMESERVER
       |
+=============================================================+
|      |                 Go-NEB                               |
| +---------+                                                 |
| | Clients |                                                 |
| +---------+                                                 |
|      |                                                      |
| +---------+       +------------+      +--------------+      |
| | Service |-------| Auth Realm |------| Auth Session |-+    |
| +---------+       +------------+      +--------------+ |    |
|     ^                   ^              +---------------+    |
|     |                   |                                   |
+=============================================================+
      |                   |                   
    WEBHOOK            REDIRECT
    REQUEST            REQUEST
    
    
Clients      = A thing which can talk to homeservers and listen for events. /configureClient makes these.
Service      = An individual bot, configured by a user. /configureService makes these.
Auth Realm   = A place where a user can authenticate with. /configureAuthRealm makes these.
Auth Session = An individual authentication session /requestAuthSession makes these.

Viewing the API docs

The full docs can be found on Github Pages. Alternatively, you can locally host the API docs:

# Start a documentation server listening on :6060
GOPATH=$GOPATH:$(pwd) godoc -v -http=localhost:6060 &

# Open up the documentation for go-neb in a browser.
sensible-browser http://localhost:6060/pkg/github.com/matrix-org/go-neb

Docker image

To get started quickly, use the image from docker.io:

docker run -v /path/to/data:/data -e "BASE_URL=http://your.public.url:4050" matrixdotorg/go-neb

If you'd prefer to build the file yourself, clone this repository and build the Dockerfile.

The image sets the following environment variables:

BIND_ADDRESS=:4050
DATABASE_TYPE=sqlite3
DATABASE_URL=/data/go-neb.db?_busy_timeout=5000

The image exposes port 4050 and a volume at /data. The BASE_URL environment variable needs to be set, a volume should be mounted at /data and port 4050 should be appropriately mapped as desired.