A Matrix bot for tracking personal expenses with Chinese language support. The bot allows users to record expenses in a simple format and provides statistical summaries.
- 📝 Simple Expense Recording: Record expenses using format
项目 金额 分类(item amount category) - 📊 Statistics Export: View spending summaries by category with
!导出 - 🗑️ Data Management: Clear all records with
!清除 - 📌 Auto-pinned Instructions: Automatically pins usage instructions in the room
- 💾 Persistent Storage: Saves data in JSON files for persistence
- 🔐 Session Management: Handles Matrix authentication and session persistence
- Record Expense:
午餐 20 餐饮(lunch 20 food) - Export Statistics:
!导出 - Clear All Data:
!清除 - Update Instructions:
!更新说明(admin only)
- Clone the repository:
git clone <repository-url>
cd matrix-bot- Create a virtual environment:
python3 -m venv .venv
source ./.venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile with your Matrix credentials:
MATRIX_HOMESERVER=https://matrix.org
MATRIX_USER_ID=@yourusername:matrix.org
MATRIX_PASSWORD=your_password
MATRIX_ROOM_ID=!roomid:matrix.org- Run the bot:
python bot.pydocker build -t matrix-bot .
docker run --rm --env-file .env matrix-botdocker-compose up -dCreate a .env file in the project root with the following variables:
MATRIX_HOMESERVER=https://your-matrix-server.org
MATRIX_USER_ID=@your-bot-username:your-matrix-server.org
MATRIX_PASSWORD=your_bot_password
MATRIX_ROOM_ID=!your-room-id:your-matrix-server.orgThe bot creates and manages several JSON files:
expenses.json: Stores all expense recordssession.json: Matrix session data for authentication persistencesync_token.json: Matrix sync token for message synchronizationmanual.json: Stores the pinned instruction message details
matrix-nio[e2e]>=0.22.0: Matrix client library with end-to-end encryption supportaiohttp>=3.8.1: Async HTTP client librarypython-dotenv>=1.0.0: Environment variable loading
- Start the bot in your Matrix room
- The bot will automatically pin usage instructions
- Send messages like:
咖啡 25 餐饮(coffee 25 food)打车 15 出行(taxi 15 transportation)电影票 45 娱乐(movie ticket 45 entertainment)
- Export statistics:
!导出 - Clear data when needed:
!清除
matrix-bot/
├── bot.py # Main bot logic
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose setup
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions, please open an issue on GitHub.