How fabricior/rsvp-telegram-bot works
Project Type and Purpose
• This is a Telegram bot project focused on facilitating game attendance management (e.g., scheduling a Five-a-side football match). Users interact via Telegram commands (/new, /yes, /no, /maybe, /status, etc.) to schedule games and RSVP.
• It is a serverless application deployed as a Google Cloud Function, implemented in Node.js with TypeScript and using telegraf as the Telegram API wrapper. The data is stored in a MongoDB database managed through Prisma.
Main Components
a. Telegram Interface:
• Telegram API as the channel for incoming updates to your bot service.
b. Bot Service (Cloud Function):
• The core of the bot is implemented within the Node.js application under the “src” directory. Key files include:
• index.ts (likely the entry point for the Cloud Function)
• bot.ts (handles Telegram Bot initialization and command routing using telegraf)
• middleware.ts (for processing requests like authentication, logging, or internationalization)
• Other business logic files such as game.ts, rsvp.ts, and guest handling in guest.ts
c. Database Layer:
• MongoDB instance working as a replica set as described in the README.
• ORM layer using Prisma, referencing files in the “prisma” directory (schema.prisma and seed.ts). This is the bridge between the bot and the database.
d. External Tools & Deployment:
• Google Cloud Functions infrastructure, showing that the bot is deployed via a HTTP trigger.
• Optionally, include configuration steps related to environment variables (.env, .env.yaml conversion) and the Dockerfile (mention limited usage in deployment).
e. Testing & Development:
• Testing component (Jest tests inside src/test, specifically rsvp.test.ts) to emphasize continuous integration and validation of business logic.
Relationships and Data Flow
• Within the bot service, divide the internal logic into separate components:
• Command Parsing / Middleware (which intercepts and prepares incoming commands)
• Business Logic Handlers (corresponding to individual commands: create game, RSVP responses, guest management)
• Utility modules (such as dates, translations)
Architectural Patterns and Technologies
• Mention that the bot follows a modular design where each command/feature is handled in separate files.
• The use of middleware implies separation of concerns (authentication, enrollment, localization).
• Clearly label key technologies: Node.js, TypeScript, telegraf, MongoDB (with replica set), Prisma, and Google Cloud Functions as critical parts of the stack.
Instructing the Principal Software Engineer
• Use a hierarchical layout: External Clients (Telegram Users) → Telegram API → Cloud Function (RSVP Bot Service) → Business Logic Modules → Database (MongoDB via Prisma).
• Component with its file counterparts where applicable (e.g., “Bot Logic: src/bot.ts, src/rsvp.ts, src/guest.ts”).
• The flow of incoming messages from the Telegram API to your bot.
• How commands are processed by middleware and routed to specific business logic.
• The connection from business logic to the persistent database.
• That every key relation is captured (e.g., state changes in the database when a new game is created, how RSVP updates are handled, and guest management interactions).
• Don’t hesitate to capture even a small module (like translations) as a separate component if needed to fully explain interactions—this will help future maintainers and engineers understand where changes might be required.