Crate matrixbot_ezlogin

Source
Expand description

matrixbot-ezlogin: “I wrote the login and E2EE bootstrap code for Matrix bots so you don’t have to.”

Writing a Matrix bot is easy, but supporting end-to-end encryption is extremely difficult.

Not only because the bot must maintain a database to store encryption keys between sessions, but also because the bootstrap process requires a human to interactively type in or copy out the recovery key.

Sadly, the official Matrix SDK doesn’t provide a complete solution to bootstrap a Matrix bot, resulting in bot developers needing to waste time writing the authentication code again and again.

Here, I publish this library called matrixbot-ezlogin, as a good starting point for every Matrix bot. So, you can skip the trouble and directly hop into the bot logic.

§Two-stages of a bot

In order to set up a Matrix bot with E2EE support, there are two steps:

  1. Creating a Matrix session, setting up cross-signing keys, creating or recovering from a server-side backup, then exit. This step requires human intervention.

  2. Restoring the Matrix session to run actual bot logic. This step is unattended and can be set to auto-start when computer boots up.

§Components of matrixbot-ezlogin

This library provides the functions setup (or setup_interactive) and login to simplify these two steps.

Additionally, DuplexLog helps handling duplex terminal input / output. SyncHelper helps remembering sync tokens between process restarts.

The examples folder contains a simple echo-bot for you to experience the feature of matrixbot-ezlogin, and serves as a good starting point to develop a new Matrix bot.

Structs§

DuplexLog
Provides a way to handle terminal input while also allowing other parts of the application to log messages.
SetupConfig
Information to set up a Matrix bot using setup.
SyncHelper
Helps you maintain sync positions between process restarts.

Functions§

login
Log in and restore a Matrix session from a state database saved by setup or setup_interactive.
logout
Log out a Matrix session and delete the state database.
setup
Set up a Matrix bot account by providing credentials through a SetupConfig.
setup_interactive
Set up a Matrix bot account by asking credentials through the terminal interactively.