You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
14 KiB

8 years ago
8 years ago
4 years ago
8 years ago
8 years ago
4 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. # ⚠️ Discontinued
  2. Go-NEB has been discontinued and won't recieve any updates or support. [matrix-hookshot](https://github.com/matrix-org/matrix-hookshot) is the spiritual successor
  3. to Go-NEB and supports migrating RSS and GitHub integrations. Other options are also available from [matrix.org](https://matrix.org/ecosystem/integrations/).
  4. # Go-NEB
  5. [![Build Status](https://github.com/matrix-org/go-neb/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/matrix-org/go-neb/actions/workflows/ci.yaml)
  6. Go-NEB is a [Matrix](https://matrix.org) bot written in Go. It is the successor to [Matrix-NEB](https://github.com/matrix-org/Matrix-NEB), the original Matrix bot written in Python.
  7. # Table of Contents
  8. * [Quick Start](#quick-start)
  9. * [Features](#features)
  10. * [Installing](#installing)
  11. * [Running](#running)
  12. * [Configuration file](#configuration-file)
  13. * [API](#api)
  14. * [Configuring clients](#configuring-clients)
  15. * [Configuring services](#configuring-services)
  16. * [Configuring realms](#configuring-realms)
  17. * [SAS verification](#sas-verification)
  18. * [Developing](#developing)
  19. * [Architecture](#architecture)
  20. * [API Docs](#viewing-the-api-docs)
  21. # Quick Start
  22. Clone and run (Requires Go 1.16+):
  23. ```bash
  24. go build github.com/matrix-org/go-neb
  25. BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=go-neb.db?_busy_timeout=5000 BASE_URL=http://localhost:4050 ./go-neb
  26. ```
  27. Get a Matrix user ID and access token. You can do this, for example, with the following curl command by replacing the user ID, password and Synapse URL with your own.
  28. ```bash
  29. curl -X POST --header 'Content-Type: application/json' -d '{
  30. "identifier": { "type": "m.id.user", "user": "nebUsername" },
  31. "password": "nebPassword",
  32. "type": "m.login.password"
  33. }' 'http://localhost:8008/_matrix/client/r0/login'
  34. ```
  35. This is preferable to, for example, logging in via Riot and copying the access token and device ID from there, as then Riot will have uploaded its own device keys which Go-NEB won't have access to causing it to be unable to create encryption sessions.
  36. The response of this command will be a JSON object with an access token and device ID.
  37. Then, give the values to Go-NEB:
  38. ```bash
  39. curl -X POST localhost:4050/admin/configureClient --data-binary '{
  40. "UserID": "@goneb:localhost",
  41. "HomeserverURL": "http://localhost:8008",
  42. "AccessToken": "<access_token>",
  43. "DeviceID": "<DEVICEID>",
  44. "Sync": true,
  45. "AutoJoinRooms": true,
  46. "DisplayName": "My Bot"
  47. }'
  48. ```
  49. Tell it what service to run:
  50. ```bash
  51. curl -X POST localhost:4050/admin/configureService --data-binary '{
  52. "Type": "echo",
  53. "Id": "myserviceid",
  54. "UserID": "@goneb:localhost",
  55. "Config": {}
  56. }'
  57. ```
  58. Invite the bot user into a Matrix room and type `!echo hello world`. It will reply with `hello world`.
  59. ## Features
  60. ### Github
  61. - Login with OAuth2.
  62. - Ability to create Github issues on any project.
  63. - Ability to track updates (add webhooks) to projects. This includes new issues, pull requests as well as commits.
  64. - Ability to expand issues when mentioned as `foo/bar#1234`.
  65. - Ability to assign a "default repository" for a Matrix room to allow `#1234` to automatically expand, as well as shorter issue creation command syntax.
  66. ### JIRA
  67. - Login with OAuth1.
  68. - Ability to create JIRA issues on a project.
  69. - Ability to expand JIRA issues when mentioned as `FOO-1234`.
  70. ### Giphy
  71. - Ability to query Giphy's "text-to-gif" engine.
  72. ### Guggy
  73. - Ability to query Guggy's gif engine.
  74. ### RSS Bot
  75. - Ability to read Atom/RSS feeds.
  76. ### Travis CI
  77. - Ability to receive incoming build notifications.
  78. - Ability to adjust the message which is sent into the room.
  79. ### Alertmanager
  80. - Ability to receive alerts and render them with go templates
  81. # Installing
  82. Go-NEB is built using Go 1.16+. Once you have installed Go, run the following commands:
  83. ```bash
  84. # Clone the go-neb repository
  85. git clone https://github.com/matrix-org/go-neb
  86. cd go-neb
  87. # Build go-neb
  88. go build github.com/matrix-org/go-neb
  89. ```
  90. # Running
  91. Go-NEB uses environment variables to configure its SQLite database and bind address. To run Go-NEB, run the following command:
  92. ```bash
  93. BIND_ADDRESS=:4050 DATABASE_TYPE=sqlite3 DATABASE_URL=go-neb.db?_busy_timeout=5000 BASE_URL=https://public.facing.endpoint ./go-neb
  94. ```
  95. - `BIND_ADDRESS` is the port to listen on.
  96. - `DATABASE_TYPE` MUST be "sqlite3". No other type is supported.
  97. - `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.
  98. - `BASE_URL` should be the public-facing endpoint that sites like Github can send webhooks to.
  99. - `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.
  100. - `LOG_DIR` is a directory that log files will be written to, with log rotation enabled. If set, logging to stderr will be disabled.
  101. 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.
  102. ## Configuration file
  103. 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](config.sample.yaml) which explains all the options. In most cases, these are *direct mappings* to the corresponding HTTP API.
  104. # API
  105. The API is documented in sections using godoc. The sections consists of:
  106. - An HTTP API (the path and method to use)
  107. - A "JSON request body" (the JSON that is inside the HTTP request body)
  108. - "Configuration" information (any additional information that is specific to what you're creating)
  109. 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.
  110. ## Configuring Clients
  111. 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.
  112. - [HTTP API Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/handlers/index.html#ConfigureClient.OnIncomingRequest)
  113. - [JSON Request Body Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/index.html#ClientConfig)
  114. ## Configuring Services
  115. 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.
  116. Every service has an "ID", "type" and "user ID". Services may specify additional "config" keys: see the specific
  117. service you're interested in for the additional keys, if any.
  118. - [HTTP API Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/handlers/index.html#ConfigureService.OnIncomingRequest)
  119. - [JSON Request Body Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/index.html#ConfigureServiceRequest)
  120. List of Services:
  121. - [Echo](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/echo/) - An example service
  122. - [Giphy](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/giphy/) - A GIF bot
  123. - [Github](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/github/) - A Github bot
  124. - [Github Webhook](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/github/index.html#WebhookService) - A Github notification bot
  125. - [Guggy](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/guggy/) - A GIF bot
  126. - [JIRA](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/jira/) - Integration with JIRA
  127. - [RSS Bot](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/rssbot/) - An Atom/RSS feed reader
  128. - [Travis CI](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/services/travisci/) - Receive build notifications from Travis CI
  129. ## Configuring Realms
  130. Realms are how Go-NEB authenticates users on third-party websites.
  131. - [HTTP API Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/handlers/index.html#ConfigureAuthRealm.OnIncomingRequest)
  132. - [JSON Request Body Docs](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/api/index.html#ConfigureAuthRealmRequest)
  133. List of Realms:
  134. - [Github](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/github/index.html#Realm)
  135. - [JIRA](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/jira/index.html#Realm)
  136. Authentication via HTTP:
  137. - [Github](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/github/index.html#Realm.RequestAuthSession)
  138. - [JIRA](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/jira/index.html#Realm.RequestAuthSession)
  139. Authentication via the config file:
  140. - [Github](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/github/index.html#Session)
  141. - [JIRA](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb/realms/jira/index.html#Session)
  142. ## SAS verification
  143. Go-NEB supports SAS verification using the decimal method. Another user can start a verification transaction with Go-NEB using their client, and it will be accepted. In order to confirm the devices, the 3 SAS integers must then be sent to Go-NEB, to the endpoint '/verifySAS' so that it can mark the device as trusted.
  144. For example, if your user ID is `@user:localhost` and your device ID is `ABCD`, you start a SAS verification with Go-NEB and get the SAS "1111 2222 3333". You can perform the following curl request to let Go-NEB know the SAS integers so that it can match them with its own:
  145. ```bash
  146. curl -X POST --header 'Content-Type: application/json' -d '{
  147. "UserID": "@neb:localhost",
  148. "OtherUserID": "@user:localhost",
  149. "OtherDeviceID": "ABCD",
  150. "SAS": [1111,2222,3333]
  151. }' 'http://localhost:4050/verifySAS'
  152. ```
  153. If the SAS match and you also confirm that via the other device's client, the verification should finish successfully.
  154. # Contributing
  155. Before submitting pull requests, please read the [Matrix.org contribution guidelines](https://github.com/matrix-org/synapse/blob/develop/CONTRIBUTING.md#sign-off) regarding sign-off of your work.
  156. # Developing
  157. This project depends on `libolm` for the end-to-end encryption. Therefore,
  158. you need to install `libolm3` and `libolm-dev` on Ubuntu / `libolm-devel` on
  159. CentOS to be able to build and run it.
  160. There's a bunch more tools this project uses when developing in order to do
  161. things like linting. Some of them are bundled with go (fmt and vet) but some
  162. are not. You should install the ones which are not:
  163. ```bash
  164. go install honnef.co/go/tools/cmd/staticcheck@latest
  165. go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
  166. ```
  167. You can then install the pre-commit hook:
  168. ```bash
  169. ./hooks/install.sh
  170. ```
  171. ## Architecture
  172. ```
  173. HOMESERVER
  174. |
  175. +=============================================================+
  176. | | Go-NEB |
  177. | +---------+ |
  178. | | Clients | |
  179. | +---------+ |
  180. | | |
  181. | +---------+ +------------+ +--------------+ |
  182. | | Service |-------| Auth Realm |------| Auth Session |-+ |
  183. | +---------+ +------------+ +--------------+ | |
  184. | ^ ^ +---------------+ |
  185. | | | |
  186. +=============================================================+
  187. | |
  188. WEBHOOK REDIRECT
  189. REQUEST REQUEST
  190. Clients = A thing which can talk to homeservers and listen for events. /configureClient makes these.
  191. Service = An individual bot, configured by a user. /configureService makes these.
  192. Auth Realm = A place where a user can authenticate with. /configureAuthRealm makes these.
  193. Auth Session = An individual authentication session /requestAuthSession makes these.
  194. ```
  195. ## Viewing the API docs
  196. The full docs can be found on [Github Pages](https://matrix-org.github.io/go-neb/pkg/github.com/matrix-org/go-neb). Alternatively, you can locally host the API docs:
  197. ```
  198. # Start a documentation server listening on :6060
  199. GOPATH=$GOPATH:$(pwd) godoc -v -http=localhost:6060 &
  200. # Open up the documentation for go-neb in a browser.
  201. sensible-browser http://localhost:6060/pkg/github.com/matrix-org/go-neb
  202. ```
  203. ## Docker image
  204. To get started quickly, use the image from docker.io:
  205. ```
  206. docker run -v /path/to/data:/data -e "BASE_URL=http://your.public.url:4050" matrixdotorg/go-neb
  207. ```
  208. If you'd prefer to build the file yourself, clone this repository and build the `Dockerfile`.
  209. The image sets the following environment variables:
  210. ```
  211. BIND_ADDRESS=:4050
  212. DATABASE_TYPE=sqlite3
  213. DATABASE_URL=/data/go-neb.db?_busy_timeout=5000
  214. ```
  215. 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.