Code Monkey home page Code Monkey logo

matrix-bots's Introduction

matrix-bots

The community.wordpress.org Matrix server relies on bots (non-human users) that perform a variety of tasks. Bots can react to messages or other events posted on Matrix, and/or post to Matrix whenever something happens.

Bots run in a bot engine called Maubot, which provides an Admin UI through which bots can be created and configured. Maubot bots are implemented in Python, and are known as Plugins. There is an ecosystem of existing plugins for Maubot, and custom plugins can be implemented as well.

This repository provides the following:

  1. Documentation on how to configure bots through Maubot's Admin UI
  2. The source code for custom plugins used in community.wordpress.org
  3. Local development environment to test, modify and create plugins
  4. Automation to produce the Docker image for community.wordpress.org's Maubot instance
  5. Documentation on how to redeploy Maubot so that it uses the latest docker image

Configuring bots

Bots are configured through an Admin UI that is available to server maintainers. You can get a replica of that UI in your local machine, see development environment for instructions.

To effectively use the Admin UI, it's important to understand a few Maubot concepts. A Maubot bot is achieved by combining the following three things:

  • Plugin: a Python module that implements the logic of the bot.
  • Client: the Matrix user that the bot will use to post to Matrix, and to receive messages from Matrix.
  • Instance: an instance ties a Plugin to a Client, and allows passing configuration to the Plugin. There can be multiple instances of the same Plugin, each potentially using a different Client, and specific configuration.

Using Maubot's CLI

To use Maubot's CLI, you first need to set up a development environment.

Certain operations are easier to do through Maubot's CLI than through the Admin UI. An example of this is creating clients, since it's not possible to automatically retrieve an access token when creating a client through the Admin UI, but the CLI is capable of doing so.

You can access Maubot's CLI with:

bin/mbc

Login

When using the CLI, the first step is typically to log in to a Maubot instance, so that the CLI can control said instance. As part of the setup process of the development environment, the CLI has already been logged in to the local Maubot instance (wporg-local).

However, you can also log in to the production instance (provided you're a server maintainer, and have access to Maubot's admin password):

bin/mbc login \
  --server https://wporg.automattrix.com \
  --username admin \
  --alias wporg-prod

Notice we assigned the instance an alias of wporg-prod. This allows you to use wporg-prod whenever you need to pass the --server argument to any bin/mbc command.

You can see all Maubot servers you're logged-in to (and their aliases) with:

cat ~/.config/maubot-cli.json

Creating clients

You can create Maubot clients through the CLI, which will automatically set an access token for the client you're creating.

Note that the WordPress.org user must already exists, prior to attempting to create a client for it. If the WordPress.org user does not yet exists, you must first register an account like you would for any normal WordPress.org user.

The username of the WordPress.org user MUST end with bot. For example, if you're creating a Foo Bot, its WordPress.org username MUST be foobot.

You can then create the Maubot client as follows:

Make sure to first log out from WordPress.org in your default browser (or be logged-in to the user for which you want to create a client for). The following command will initiate the OIDC flow in your default browser, and you don't want to accidentally use the wrong user.

# Replace the value for the --username argument with the Matrix username of the bot.

bin/mbc auth \
  --server wporg-prod \
  --update-client \
  --homeserver community.wordpress.org \
  --username examplebot \
  --sso

Once you complete the OIDC flow, a Maubot client will have been created in the Maubot Admin UI. Both the display name and the avatar will have been set to disable, but you should set correct values for them, through the Admin UI. If the username of the bot would be examplebot, its display name should be Example Bot.

To set an avatar, you must first upload the image to a public Matrix room (e.g. #matrix-testing:community.wordpress.org). You can then copy the URL from the room event (in Element: click the ... in the menu that appears when hovering the image in the timeline, then View source, then copy the value from content.url, it starts with mxc://).

Development environment

You can set up a local development environment that allows you to do the following:

  1. Run a local instance of Maubot, along with a homeserver and a Matrix client. This is useful to test existing plugins or develop new ones.
  2. Use the Maubot CLI to talk to both the local and production Maubot instances. Note the production instance is only available to server maintainers.

Setup

Start by cloning the repository:

git clone [email protected]:WordPress/matrix-bots.git
cd matrix-bots

Do initial setup:

make

From the repo root, run:

docker compose up

The first time you do this, Maubot will likely fail to start due to not being able to connect to Postgres. To fix this, wait for the matrix-bots-wporg-synapse container to say No more background updates, then restart all containers:

# ctrl-c to stop all containers, then:
docker compose up

Finally, run the setup script:

bin/setup

Available services

You should now have the following services running:

The homeserver domain is matrix-bots-wporg.local. An @admin Matrix user and a respective Maubot client should have been created. You can use that client to test and develop plugins.

Custom plugins

Custom plugins are plugins that have been developed by the WordPress.org community. Their source code is contained in this repo (under plugins/), and they are made available to the production Maubot through the Docker image.

To develop custom plugins, you'll need a development environment running locally.

Building a plugin

You can build a custom plugin and deploy it to the local Maubot instance with the following command (plugins/example is the path to the directory containing the plugin you want to build and deploy):

bin/build plugins/example

The local Maubot instance will automatically start using the newly-built version of the plugin.

Creating a new plugin

TODO

Start from scratch

If you wish to delete all containers and data, you can use the following script, which will restore the local checkout of the repository to its initial state, as if it had just been cloned:

bin/wipe

Docker image

This repository provides the Docker image for community.wordpress.org's Maubot instance. The image is exactly the same as Maubot's official image, but with plugins placed in /data/plugins.

Since community.wordpress.org's Maubot instance does not (deliberately) allow uploading plugins through the Admin UI, the only plugins that will be available are the ones bundled into this Docker image.

Issuing a new release

To issue a new release of the image, edit the version file so that it contains the version you want to release. The versioning scheme used is: whatever Maubot's version is, with an extra decimal. For example, if Maubot's version (in Dockerfile) is v0.4.2, the version file would contain something like:

v0.4.2.0

Then commit the version file and push. A GitHub Action will then publish the Docker image to the GitHub Container Registry.

Deploying

Redeploy of Maubot in production will be done by server maintainers when a new Docker image version is published.

matrix-bots's People

Contributors

ashfame avatar psrpinto avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

matrix-bots's Issues

Integrations for #buddypress-commits

Accordingt to our records, the #buddypress-commits Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #contributor-mentorship

Accordingt to our records, the #contributor-mentorship Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #6-1-site-editor-merge

Accordingt to our records, the #6-1-site-editor-merge Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-fields

For the #core-fields Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #6-4-release-leads

Accordingt to our records, the #6-4-release-leads Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #6-2-release-leads

Accordingt to our records, the #6-2-release-leads Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #accessibility-events

Accordingt to our records, the #accessibility-events Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-committers

For the #core-committers Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #community-team

For the #community-team Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trello
  • Workflow "Community Team Welcome Bot"
  • Trac Bot

Integrations for #core-passwords

For the #core-passwords Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Github
    • Commits
  • Trac Bot

Integrations for #6-3-release-leads

Accordingt to our records, the #6-3-release-leads Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #contributor-day

Accordingt to our records, the #contributor-day Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #bbpress-commits

Accordingt to our records, the #bbpress-commits Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #announcements

For the #announcements Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #cli-firehose

For the #cli-firehose Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Travis CI

Integrations for #core-bootstrap

For the #core-bootstrap Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #bbpress-firehose

Accordingt to our records, the #bbpress-firehose Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-http-api

For the #core-http-api Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Github
    • Commits

Integrations for #accessibility-testing

Accordingt to our records, the #accessibility-testing Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-docs

For the #core-docs Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #community-events

For the #community-events Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #core-newtickets

Accordingt to our records, the #core-newtickets Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-commits

Accordingt to our records, the #core-commits Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #buddypress-firehose

Accordingt to our records, the #buddypress-firehose Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #buddypress-newtickets

Accordingt to our records, the #buddypress-newtickets Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-editor-firehose

Accordingt to our records, the #core-editor-firehose Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-firehose

Accordingt to our records, the #core-firehose Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-importers

Accordingt to our records, the #core-importers Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #bbpress-newtickets

Accordingt to our records, the #bbpress-newtickets Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Integrations for #core-datetime

For the #core-datetime Slack channel on Making WordPress, the following integrations need to be migrated from Slack to Matrix:

  • Trac Bot

Integrations for #core-ci-firehose

Accordingt to our records, the #core-ci-firehose Slack channel on Making WordPress does not have any integrations that need to be migrated from Slack to Matrix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.