A Java library for communicating with a Matrix server, meant to aid in creating a chatbot.
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>
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) { // ... } }
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" publishToMavenLocalThis 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>