A Telegram bot for interacting with the WEEE-Open/grillo lab booking and management API.
Compatible with: main branch of WEEE-Open/grillo
- Check status - See who's in the lab and upcoming bookings
- Clock in/out - Track your lab time with audits
- Auto-reload - Development mode with automatic restart on file changes
- Python 3.11 or higher
- A Telegram Bot Token (from @BotFather)
- A Grillo API Token (from the Grillo web UI settings)
Telegram Bot Token:
- Message @BotFather on Telegram
- Send
/newbotand follow the prompts - Copy the token
Grillo API Token:
- Log in to the Grillo web interface
- Go to Settings → API Tokens → Create Token
- Set permissions to Read-Write
- Copy the token
git clone https://github.com/yourusername/grillo-bot.git
cd grillo-bot
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# Edit .env with your tokens
python dev.py # Development mode with auto-reloadEnvironment Variables (.env):
TELEGRAM_BOT_TOKEN=your_bot_token_here
GRILLO_API_TOKEN=your_api_token_here
GRILLO_API_URL=http://localhost:3000/api/v1# Development mode (auto-reloads on file changes)
python dev.py
# Production mode
python bot.py- Find your bot on Telegram
- Send
/start - Your account will be auto-linked if your Telegram ID is in LDAP
- Use
/helpto see available commands
| Command | Description |
|---|---|
/start |
Welcome message - auto-links your account if Telegram ID is in LDAP |
/help |
Show available commands |
/status [location] |
Check who's in the lab and upcoming bookings |
/clockin [location] |
Clock in to the lab |
/clockout <summary> |
Clock out with work summary |
Note: The bot automatically links your Telegram account on /start if your Telegram ID is configured in the Grillo LDAP server.
grillo-bot/
├── bot.py # Main bot with command handlers
├── dev.py # Development runner with auto-reload
├── grillo_client.py # Grillo API client
├── user_mapper.py # Telegram ↔ LDAP user mapping
├── config.py # Configuration management
├── utils.py # Utility functions
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── .env # Your config (gitignored)
├── user_mapping.json # User mappings (gitignored, auto-created)
└── README.md # This file
The bot uses a hybrid authentication system:
- Auto-Discovery: When you send
/start, the bot queries the Grillo API endpoint/user?telegram_id=YOUR_ID - User Mapping: If found, your Telegram account is automatically linked to your LDAP user
- Session Generation: The bot generates a session cookie for authenticated operations
- UID Tracking: All API requests include your user ID for proper tracking
Requirements:
- Your Telegram ID must be configured in the Grillo LDAP server
- The bot needs an admin API token to query user information
Mappings are stored locally in user_mapping.json (gitignored).
Use dev.py for development - it automatically restarts the bot when you modify any Python file:
python dev.pyFeatures:
- Watches all
.pyfiles for changes - Automatic bot restart on save
- Debouncing (1s delay to prevent rapid restarts)
- Crash recovery
- Clean shutdown with Ctrl+C
- Add handler function in
bot.py:
async def mycommand(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
grillo = get_user_client_by_telegram(update.effective_user.id)
# Your logic here
await update.message.reply_text("Response")- Register in
main():
handlers = [start, help, status, clockin, clockout, mycommand]Add to GrilloClient in grillo_client.py:
def my_method(self, param: str) -> Dict[str, Any]:
return self._make_request("GET", f"/endpoint/{param}")- Follow PEP 8
- Use type hints
- Add docstrings to functions
- Handle errors gracefully
| Endpoint | Method | Purpose |
|---|---|---|
/user?telegram_id=<id> |
GET | Auto-discover user by Telegram ID |
/locations/:id |
GET | Get location details with people/bookings |
/audits |
GET | Get audit entries (time tracking) |
/audits |
POST | Clock in to lab |
/audits |
PATCH | Clock out from lab |
/session |
POST | Generate user session cookie |
See the Grillo API source for complete documentation.
Bot not responding:
- Verify
TELEGRAM_BOT_TOKENin.env - Check bot is running:
ps aux | grep bot.py - Look for errors in terminal output
Auto-linking fails:
- Ensure your Telegram ID is in the Grillo LDAP server
- Check
GRILLO_API_TOKENhas proper permissions - Verify
GRILLO_API_URLis correct and accessible
MIT
Pull requests welcome! For major changes, please open an issue first.
MIT
- WEEE-Open/grillo - The Grillo lab booking system
- Main branch: Core functionality
- Schedule branch - Enhanced scheduling features
- WEEEOpen - WEEE Open - Student team at Politecnico di Torino
- Basile Francesco (@parmigggiana)