Skip to content

Repository files navigation

Java Matrix Bot Lib

A Java library for communicating with a Matrix server, meant to aid in creating a chatbot.

Usage

Currently requires at least JDK 21. If you are using Maven, add the following repository to your pom.xml to add java-matrix-bot-lib as a dependency:

<dependency>
    <groupId>org.synyx</groupId>
    <artifactId>java-matrix-bot-lib</artifactId>
    <version>VERSIONHERE</version>
</dependency>

Example

public class MyMatrixBot implements MatrixEventConsumer {

  private MatrixClient matrixClient;

  public MyMatrixBot() {

    MatrixClient matrixClient = MatrixClient.create("https://matrix.example.com", "username", "password");
    matrixClient.setPersistedState(matrixStatePersistence);
  }

  public void startBot() {
    // Blocks the thread
    matrixClient.syncContinuous();
  }

  public void stopBot() {

    matrixClient.requestStopOfSync();
  }

  @Override
  public void onMessage(MatrixState state, MatrixMessageEvent event) {
    // ...
  }
}

Development

If you want to develop on the library locally and test out your changes, you can publish it to your maven local like this:

./gradlew -Pversion="dev" publishToMavenLocal

This enables you to use your local development version like this:

<dependency>
    <groupId>org.synyx</groupId>
    <artifactId>java-matrix-bot-lib</artifactId>
    <version>dev</version>
</dependency>

About

A small Java library to aid in creating a matrix chat bot

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages