Required Variables
Your Telegram bot token from BotFather.Format:
123456:ABC-DEF...How to get it:- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow prompts to name your bot
- Copy the bot token provided
The ID of your private Telegram channel where users will be added.Format:
-100xxxxxxxxxxHow to get it:- Forward a message from your private channel to @userinfobot
- Copy the channel ID from the response
- Add your bot as an administrator to the channel with these permissions:
- ✅ Invite users via link
- ✅ Restrict members
Your Paystack API secret key for payment verification.Format:
sk_live_... or sk_test_...How to get it:- Log in to Paystack Dashboard
- Go to Settings → API Keys
- Copy your Secret Key
MongoDB connection string for storing user subscriptions and payment records.Format:
mongodb+srv://username:[email protected]/databaseHow to set it up:- Create a free account at MongoDB Atlas
- Create a new cluster (M0 free tier works)
- Create a database user
- Whitelist IP
0.0.0.0/0(required for Vercel) - Copy the connection string and replace
<username>and<password>with your credentials
A secret key used to authenticate cron job requests for removing expired users.How to generate:
This prevents unauthorized access to your cron endpoint at
/api/cron/remove-expired.The public URL where your application is deployed.Examples:
- Development:
http://localhost:3000 - Production:
https://your-domain.vercel.app
This variable is prefixed with
NEXT_PUBLIC_ which means it’s accessible on the client side.Setting Up Locally
-
Create environment file:
-
Edit
.env.localwith your credentials: -
Initialize the database:
Deploying to Vercel
When deploying to Vercel, you need to add all environment variables to your project settings:- Go to your project in Vercel Dashboard
- Navigate to Settings → Environment Variables
- Add each variable listed above
- Deploy your application
Testing Environment
For testing, you can use Paystack’s test mode:- Get test API keys from Paystack dashboard (starts with
sk_test_) - Use
PAYSTACK_SECRET_KEY=sk_test_...in your.env.local - Make test payments using Paystack’s test payment page
- Verify with test transaction references
Security Best Practices
Troubleshooting
Bot Not Responding
- Verify
TELEGRAM_BOT_TOKENis correct - Check that webhook is set to the correct URL
- Ensure all environment variables are loaded in Vercel
Payment Verification Failing
- Confirm
PAYSTACK_SECRET_KEYis correct and matches the environment (test vs live) - Verify transaction references are from the same Paystack account
- Check that payment status is “success”
Database Connection Issues
- Ensure
DATABASE_URLis correctly formatted - Verify IP whitelist includes
0.0.0.0/0in MongoDB Atlas - Check database user credentials are correct
Cron Job Not Running
- Verify
CRON_SECRETmatches in both code and Vercel environment variables - Check Vercel cron logs for errors
- Ensure the endpoint returns 200 status