A Telegram bot platform that supports multiple bot instances with configurable message parsing. Each bot can receive notifications from various sources (like 18xx.games) and forward them to Telegram chats with custom message processing.
- Multi-Bot Support: Host multiple Telegram bots on a single Workers instance
- Configurable Message Parsers: Each bot can use different message parsing strategies
- KV-Based Configuration: Bot tokens and settings stored in Cloudflare Workers KV
- Legacy Compatibility: Maintains backward compatibility with existing deployments
- Global Edge Distribution: Runs on Cloudflare Workers for low latency worldwide
- TypeScript: Full type safety and modern JavaScript features
- New Routes:
/bot/{botId}/process-updatesand/bot/{botId}/send-notifications/{chatId} - Legacy Routes:
/process-updatesand/send-notifications/{chatId}(uses hardcoded18xx.gamesbot) - KV Storage: Bot configurations stored in
BOT_CONFIGnamespace
Each bot can be configured with different message parsers:
- Default Parser: Universal parser that handles any message format
- 18xx Parser: Specialized for 18xx.games notifications with validation and metadata
- Extensible: Easy to add custom parsers for new message sources
-
Clone and Install
git clone https://github.com/vandamm/notify-bot.git cd notify-bot npm install -
Deploy
npm run build npm run deploy
-
Configure Bots in KV Add bot configurations to the
BOT_CONFIGKV namespace:{ "token": "your-telegram-bot-token", "parser": "18xx" } -
Set Telegram Webhook For new multi-bot routing:
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://ping.vansach.me/bot/your-bot-id/process-updates"}'
For legacy compatibility:
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \ -H "Content-Type: application/json" \ -d '{"url": "https://ping.vansach.me/process-updates"}'
- Start a chat with your bot on Telegram
- Send
/startto get setup instructions - Copy the webhook URL provided by the bot
- Configure your notification source:
- Go to your application's webhook/notification settings
- Set up webhook notifications using the provided URL
- Set any required User ID field to any value (e.g., "notifications")
-
Create KV Entry: Add bot configuration to
BOT_CONFIGnamespace{ "token": "1234567890:ABCdefGHIjklMNOpqrsTUVwxyz", "parser": "18xx" } -
Set Webhook: Configure Telegram webhook to point to your bot's endpoint
-
Test: Send a test notification to verify everything works
See PARSER_CONFIGURATION.md for detailed parser configuration options.
POST /bot/{botId}/process-updates- Telegram webhook for specific botPOST /bot/{botId}/send-notifications/{chatId}- Notification webhook for specific bot
POST /process-updates- Telegram webhook (uses18xx.gamesbot)POST /send-notifications/{chatId}- Notification webhook (uses18xx.gamesbot)
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Watch mode for tests
npm run test:watch
# Start development server
npm run devThe project includes comprehensive tests for all functionality:
# Run all tests
npm test
# Run tests in CI mode
npm run test:ci
# Watch mode during development
npm run test:watchEach bot is configured via a JSON object in the BOT_CONFIG KV namespace:
{
"token": "your-telegram-bot-token",
"parser": "18xx"
}Required Fields:
token: Telegram bot token from @BotFather
Optional Fields:
parser: Message parser to use ("default", "18xx", or custom parser name)
default: Universal parser for any message format18xx: Specialized for 18xx.games notifications with validation
The application uses Cloudflare Workers KV for configuration. No environment variables are required.
KV Namespaces:
BOT_CONFIG: Stores bot configurations (tokens and parser settings)
See DEPLOYMENT.md for detailed deployment instructions.
ping.vansach.me- Primary domain18xx-bot.vansach.me- Alternative domain
test.ping.vansach.me- Test domaintest.18xx-bot.vansach.me- Alternative test domain
The application no longer uses the TELEGRAM_BOT_18XX environment variable. All bot configurations are now stored in KV.
To migrate:
- Add your bot configuration to KV with key
18xx.games - Update webhook URLs if using legacy routes (optional)
- Remove the environment variable
Existing deployments will continue to work via legacy routes. To use multi-bot features:
- Add additional bots to KV with unique keys
- Configure webhooks using new multi-bot routes
- Optionally migrate existing bot to explicit bot ID
- Bot Repository: Loads bot configurations from KV and instantiates bots
- Message Parser Registry: Manages available message parsers
- Bot Class: Encapsulates Telegram client and message parsing logic
- Route Handlers: Handle HTTP requests for different bot operations
- Incoming Notification: HTTP request to send-notifications endpoint
- Bot Resolution: Load bot configuration from KV
- Message Parsing: Parse message using configured parser
- Validation: Check if parsed message is valid
- Telegram Delivery: Send formatted message to Telegram
- Parser Interface: Standard interface for all message parsers
- Registry Pattern: Centralized parser management with fallback
- Extensible Design: Easy to add new parsers for different message sources
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Update documentation as needed
- Submit a pull request
MIT
- Parser Configuration Guide - Detailed parser setup and customization
- Deployment Guide - Production deployment instructions