This Telegram Bot is designed to simplify the process of managing credit balances in a group. It uses Google App Script to deploy a serverless application that can automatically deduct credit balances each month and provide reminders for insufficient balance. The bot is flexible and can be used for various purposes, such as tracking monthly bills like Spotify, YouTube, or any other service's credit balance. It's an excellent tool for group management and can be customized to suit your needs.
-
Clone this repository
git clone [email protected]:moebarox/credit-balance-bot.git && cd credit-balance-bot
-
Create a new Google Apps Script project
clasp create --title "Credit Balance Bot" --type webapp
-
Push this repository to the new Google Apps Script project
clasp push
-
Deploy the new Google Apps Script project
-
Open the new Google Apps Script project
-
Click Deploy and select New deployment.
-
Click gear icon on the right of Select type and select Web app.
-
Fill in the following information:
- New description: "Credit Balance Bot"
- Execute as: "Me"
- Who has access: "Anyone"
-
Click Deploy.
-
Click Authorize access and complete the process.
-
Copy the Web app URL.
-
-
Add Script Properties
-
On the Google Apps Script project, go to Project Settings
-
On the Script Properties section, click Edit Script Properties and add the following properties:
WEBHOOK_URL
- Web app URL from the previous stepBOT_TOKEN
- Your bot token from @BotFatherBOT_ADMIN_ID
- Your telegram ID (for debugging purposes)MONGO_HOST
- MongoDB hostMONGO_DATABASE
- MongoDB databaseMONGO_DATA_SOURCE
- MongoDB data sourceMONGO_API_KEY
- MongoDB Atlas API key
-
Click Save script properties.
-
-
Set Webhook
Do the following steps. This is required only once.
- On the Google Apps Script project, go to Editor
- Select
index.gs
file - On the toolbar, select
setWebhook
function - Click Run
-
Test the bot
Try to send
/about
command to the bot.
-
On the Google Apps Script project, go to Triggers
-
Click Add Trigger
-
Fill in the following information:
- Choose which function to run: "billingScheduler"
- Choose which deployment should run: (Select your deployment version)
- Select event source: "Time-driven"
- Select type of time based trigger: "Day timer"
- Select time of day: "8am to 9am"
-
Click Save.
Everytime you make changes, you need to deploy the new version. Do the following steps.
-
On the Google Apps Script project, click Deploy and select Manage deployment.
-
Click Edit (pen icon).
-
Fill in the following information:
- Version: "New version"
- Description: Fill with the new description (optional)
-
Click Deploy.
/about
/newbilling [key] [billingDate] [billingAmount]
/editbilling [key] [newBillingDate] [newBillingAmount]
/join [key]
/addmember [key] [username(s)]
/removemember [key] [username(s)]
/showbalance [key]
/editbalance [key] [username(s)] [amount]
Get information about the message. See Telegram Bot API Update for more details.
/about
Add new billing group.
key
- Billing key.billingDate
- Billing date. The scheduler will run on this date.billingAmount
- Billing amount. This is a group billing amount and will be divided by the number of members.
/newbilling youtube 1 120000
Edit billing group detail.
key
- Billing key.newBillingDate
- New billing date. The scheduler will run on this date.newBillingAmount
- New billing amount. This is a group billing amount and will be divided by the number of members.
/editbilling youtube 8 149900
Join as a member to the group billing.
key
- Billing key.
/join youtube
Register new member to the group billing. This command is similar to /join
, but only admin can run this command.
key
- Billing key.username(s)
- Username of the new member. Can be multiple, separate by space. Using@
will be allowed.
/addmember youtube johndoe
/addmember youtube johndoe janedee
/addmember youtube @johndoe @janedee
Remove member from the group billing. Only admin can run this command.
key
- Billing key.username(s)
- Username of the member. Can be multiple, separate by space. Using@
will be allowed.
/removemember youtube johndoe
/removemember youtube johndoe janedee
/removemember youtube @johndoe @janedee
Show current balance of every member
key
- Billing key (optional). If not provided, it will show all billing groups.
/showbalance
/showbalance youtube
Edit balance of the member. Only admin can run this command.
key
- Billing key.username(s)
- Username of the member. Can be multiple, separate by space. Using@
will be allowed.amount
- Topup/topdown amount. Positive value will be topup, negative value will be topdown. If multiple members is provided, the amount will affect all of them.
/editbalance youtube johndoe 1000
/editbalance youtube janedee +1000
/editbalance youtube johndoe janedee -1000
/editbalance youtube @johndoe @janedee 1000
/editbalance youtube @johndoe @janedee -1000