It just does simple stuff like greeting when login and logout.
This bot:
- Greets users with a welcome message when they log in.
- Sends farewell messages when they log out.
-
Modular Design: Each module has a single responsibility and is easy to maintain.
-
Layered Architecture:
- Configuration Layer: Environment variables and settings.
- API Client Layer: Communicates with the
rocketchat_API
. - Business Logic Layer: Handles greeting messages and user events.
- Entry Point: Starts the bot and orchestrates all components.
- Separation of Concerns: Keeps configuration, API calls, and logic separate.
- Single Responsibility Principle: Each module does one job, making it easy to debug and test.
- Security: Uses environment variables to avoid exposing sensitive credentials.
python-rocketchat-bot/
│
├── src/
│ ├── bot.py # Main bot entry point
│ ├── config.py # Loads environment variables
│ ├── handlers.py # Logic for greeting messages
│ └── rocket_client.py # Rocket.Chat API wrapper
├── requirements.txt # Dependencies
├── .envrc # Direnv configuration
└── .env.example # Example environment file (DO NOT COMMIT real credentials)
-
Clone the repository
git clone https://github.com/ahmed-n-abdeltwab/python-rocketchat-bot cd python-rocketchat-bot
-
Create and activate a virtual environment (optional but recommended)
python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Set up your environment variables
- Create a
.env
file based on.env.example
- Example:
ROCKETCHAT_URL=https://your.rocket.chat ROCKETCHAT_USER=bot_username ROCKETCHAT_PASSWORD=bot_password CHANNEL=general
- Create a
python3 src/bot.py
The bot will start polling for user login/logout events and send greeting messages to the configured channel.
- Channel ID: Make sure the
CHANNEL
exists in Rocket.Chat. You can use either a#channel
name or a direct room ID.