- A Matrix homeserver (e.g., Synapse, Dendrite, Conduit)
- Node.js 18+ installed
- A bot account created on your Matrix homeserver
- Access your homeserver's admin panel
- Create a new user account for the bot
- Generate an access token for the bot
curl -X POST "https://your-matrix-server.com/_matrix/client/r0/register" \
-H "Content-Type: application/json" \
-d '{
"username": "oddnet-bot",
"password": "secure-password-here",
"auth": {"type": "m.login.dummy"}
}'curl -X POST "https://your-matrix-server.com/_matrix/client/r0/login" \
-H "Content-Type: application/json" \
-d '{
"type": "m.login.password",
"user": "oddnet-bot",
"password": "your-bot-password"
}'The response will contain an access_token field - save this for your .env file.
- Log in with the bot account using Element or another Matrix client
- Go to Settings → Help & About → Advanced
- Click "Access Token" and copy it
Create a .env file in the project root:
cp .env.example .envEdit .env with your actual values:
MATRIX_SERVER=https://your-matrix-server.com
MANAGER_MATRIX_ID=@oddnet-bot:your-matrix-server.com
MANAGER_MATRIX_ACCESS_TOKEN=your_access_token_from_step2
STORAGE_PATH=./storagenpm installnpm run devnpm run build
npm start- Create a new encrypted room in your Matrix client (e.g., Element)
- Invite the bot to the room using its full Matrix ID (e.g.,
@oddnet-bot:your-matrix-server.com) - The bot will automatically join the room
- Send a message:
!ping - The bot should respond with "Pong!"
- Try:
!echo Hello, encrypted world! - The bot should echo back: "Hello, encrypted world!"
The bot is configured with:
- RustSdkCryptoStorageProvider: Handles encryption/decryption of messages
- SimpleFsStorageProvider: Persists bot state and sync tokens
- AutojoinRoomsMixin: Automatically accepts room invitations
- Message event handlers: Responds to commands in both encrypted and unencrypted rooms
The bot stores its data in the ./storage directory (configurable via STORAGE_PATH):
storage/bot.json: Bot state and sync tokenstorage/crypto/: Encryption keys and device information
Important: Keep the storage directory backed up. If you lose the crypto storage, the bot won't be able to decrypt old messages or participate in existing encrypted rooms.
- Check that the bot successfully started (look for "Bot is ready and listening for messages!")
- Verify the bot joined the room
- Make sure messages start with
!for commands
- Ensure
@matrix-org/olmis installed:npm install @matrix-org/olm - Delete and recreate the
storage/cryptodirectory if encryption keys are corrupted - The bot may need to re-verify with other devices in encrypted rooms
- Verify
MATRIX_SERVERURL is correct and accessible - Check that the
ACCESS_TOKENis valid - Ensure your homeserver allows bot accounts
!ping- Responds with "Pong!"!echo <message>- Echoes back the message
To add more commands, edit the message handler in src/main.ts (lines 49-78). The bot can now read and send messages in both encrypted and unencrypted rooms.
For more advanced features, check out the matrix-bot-sdk documentation.