Telegram bot to coordinate the attendance to games that require a specific/maximum number of players, such as Five-a-side football.
- 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.
-
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 forHH:MM
is the time to schedule the new game atMAX
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. -
Users can RSVP by sending
/yes
/no
/maybe
commands: -
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: -
To add guests, that is, users that are not part of the group chat, use
/guest_add GUEST-NAME
-
Guests are also displayed and accounted in the
/status
command -
To remove guests, use
/guest_remove GUEST-NUMBER
- For example,
/guest_remove 2
will remove the guest number 2.
- For example,
en
Englishes
Español
- Create your own Telegram bot
Please refer to Telegram documentation to create your own telegram bot.
-
Database Setup
2.1 Create a MongoDb instance configured as replica set.
2.2 Run
npx prisma db push
-
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
-
Create an
.env
file. Use the.env.template
to know the required keys. Update all values with values for your project. -
Transform your
.env
file to.env.yaml
. You can you this command to do it:
npx dotenv-to-yaml .env .env.yaml
-
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 -
Setup Bot in a Telegram group chat
7.1 Add your bot as Administrator to a group chat.
7.2 Send
/init <language>
command7.3 Users need to
/enroll
to be included in the list of players. This needs to be done just once per user. -
Optionally, configure bot commands to enable command autocomplete and inline help.
8.1 Open chat with @BotFather
8.2 Send the
setcommands
command8.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>
- 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)
-
Run
npm install
-
Run
npx prisma db push
-
npm install -g localtunnel
Note: it requires admin privileges
-
(Optionally) Run
npx prisma db seed
- Run
lt --port 3001
- Update
.env
, keyFALLBACK_BASE_URL
file the url provided by thelt
command - Run
npm run dev
npm test
- MongoShell:
db.dropDatabase()
- Terminal:
npx prisma db push
npx prisma db seed