Skip to content

fabricior/rsvp-telegram-bot

Repository files navigation

RSVP Telegram Bot

About

Telegram bot to coordinate the attendance to games that require a specific/maximum number of players, such as Five-a-side football.

Tech stack

  • NodeJs
  • TypeScript
  • telegraf
  • MongoDB
  • Prisma
  • Jest
  • Google Cloud Functions
  • Docker
    • Limited support. Dockerfile is no longer needed for deployment as Google Cloud Functions create their own image.

Features overview

  • Create a new game by sending the /new command using following format:

    /new YYYY-MM-DD HH:MM MAX

    where:

    • YYYY-MM-DD is the date to schedule the new game for
    • HH:MM is the time to schedule the new game at
    • MAX is the maximum number of players

    For example, /new 2022-04-19 20:00 10 will schedule a new game for 4/19/2022 at 08:00 PM with a max number of players set at 10. Screenshot of Sending /new command.

  • Users can RSVP by sending /yes /no /maybe commands:

    Screenshot of Sending /yes command.

  • At all times, you can send the /status command to see if there are any upcoming games. If so, the bot will display attendance details:

    Screenshot of Sending /status command.

  • To add guests, that is, users that are not part of the group chat, use /guest_add GUEST-NAME

    Screenshot of Sending /guest_add commands.

  • Guests are also displayed and accounted in the /status command

    Screenshot of Sending /status command when there are guests.

  • To remove guests, use /guest_remove GUEST-NUMBER

    • For example, /guest_remove 2 will remove the guest number 2.

Supported Languages

  • en English
  • es Español

How to deploy this bot as a Google Cloud Function

  1. Create your own Telegram bot

Please refer to Telegram documentation to create your own telegram bot.

  1. Database Setup

    2.1 Create a MongoDb instance configured as replica set.

    2.2 Run npx prisma db push

  2. Google Cloud Console

    3.1 Make you you have created a project in Google Cloud Console.

    3.2 Enable Cloud Functions API

    3.3 Enable Cloud Build API

  3. Create an .env file. Use the .env.template to know the required keys. Update all values with values for your project.

  4. Transform your .env file to .env.yaml. You can you this command to do it:

npx dotenv-to-yaml .env .env.yaml
  1. Google Cloud SDK Shell

    6.1 Install Google Cloud SDK Shell in your local machine

    6.2 Run gcloud auth login

    6.3 Run gcloud functions deploy <function-name> --region=<your-region> --env-vars-file .env.yaml --runtime nodejs16 --trigger-http --allow-unauthenticated --entry-point cloudEntryPoint where: <function-name> is the new cloud function name <your-region> is the selected region

  2. Setup Bot in a Telegram group chat

    7.1 Add your bot as Administrator to a group chat.

    7.2 Send /init <language> command

    Screenshot of Sending /init command.

    7.3 Users need to /enroll to be included in the list of players. This needs to be done just once per user.

    Screenshot of Sending /enroll command.

  3. Optionally, configure bot commands to enable command autocomplete and inline help.

    8.1 Open chat with @BotFather

    8.2 Send the setcommands command

    8.3 Select your bot

    8.4 Send below message:

init - Initialize the robot.
enroll - Each player needs to send this command to let the bot know they want to interact with it. This needs to be done just once per user.
new - creates a new game. Usage: /new YYYY-MM-DD HH:MM MAX
yes - you are attending the upcoming gameHow to deploy this bot as a Google Cloud Function
no - you are NOT attending the upcoming game
maybe - you don't know yet if you can make it
status - get details about the attendance of players
guest_add - Add a guest player. Usage: /guest_add <name>
guest_remove - Removes a guest player. Usage: /guest_remove <number>

Development

Requirements

  • Node v16.x or later
  • A MongoDb instance configured as replica set.
  • All the steps described in the deployment section (except for the Google Cloud SDK Shell steps)

Setup

  1. Run npm install

  2. Run npx prisma db push

  3. npm install -g localtunnel

    Note: it requires admin privileges

  4. (Optionally) Run npx prisma db seed

Run locally

  • Run lt --port 3001
  • Update .env, key FALLBACK_BASE_URL file the url provided by the lt command
  • Run npm run dev

Run tests

npm test

Recreate DB from scratch

  1. MongoShell: db.dropDatabase()
  2. Terminal: npx prisma db push npx prisma db seed