This project implements a Telegram chat bot that retrieves registration data for the Event and sends it to a specified chat group. The bot fetches the total number of registrations and the details of registered users from a specific URL and posts them in the Telegram group at a scheduled time.
app.js
: The main script file that fetches registration data, calculates the total count, and sends messages to the Telegram group.app-local-schedule
: The script file schedules to rollout telegram messages locally.app-console-test.js
: The script file to test locally uses console.log.config.yaml
: The encrypted configuration file that stores sensitive data.
Before setting up the Telegram chat bot, make sure you have the following:
- Node.js installed on your machine.
- A Telegram account.
To set up the Telegram chat bot and run the script, follow these steps:
-
Clone or download this repository to your local machine.
-
Install the dependencies by running the following command:
npm install
- Create a Telegram Bot using BotFather:
- Open the Telegram app and search for BotFather.
- Start a chat with BotFather and follow the instructions to create a new bot.
- Once the bot is created, BotFather will provide you with a unique token. Make sure to keep this token secure.
- Create a Telegram group and add the bot to the group:
- Create a new group in Telegram or use an existing one.
- Add the Telegram bot to the group by inviting it via the group's members settings.
- Obtain the Telegram group ID:
-
Add the bot to the group as an administrator.
-
Temporarily disable the privacy settings for the bot by going to the bot's settings and disabling the "Group Privacy" option.
-
Send a message to the group using the bot.
-
Open a web browser and enter the following URL, replacing
<bot_token>
with your actual bot token:https://api.telegram.org/bot<bot_token>/getUpdates
This will return a JSON response containing information about recent messages received by your bot.
-
Look for the "chat" object within the JSON response and find the "id" value. This is the chat ID for the group chat.
- Encrypt the configuration file:
-
Create a new
config.yaml
file. -
Replace the placeholder values in the
config.yaml
file with your actual sensitive data. -
Encrypt the
config.yaml
file usingsops
by running the following command:# Encrypt the file for very first time sops --encrypt --in-place config.yaml # If config already set up, use sops -d and -e options for decrypting and encrypting config.yaml sops -d -i config.yaml sops -e -i config.yaml
Make sure you have
sops
installed and configured properly.
- Schedule locally: Start the script by running the following command:
node app-local-scheduler.js # Rolls out as local scheduler
The script will fetch registration data, calculate the total count, and send messages to the Telegram group at the scheduled time.
- To Automate with GHA
# See app.js, schedule.yaml
node app.js
- You can modify the schedule and other settings by editing the code in
app.js
according to your requirements.
This project is licensed under the MIT License.
Feel free to modify and use it according to your needs.
Make sure to replace the placeholders (YOUR_TELEGRAM_BOT_TOKEN and YOUR_TELEGRAM_CHAT_ID) with your actual Telegram Bot token and group ID. Also, ensure that you provide accurate instructions for the steps to create a Telegram bot, get the group ID, and encrypt the configuration file using sops.