Overview
Vercel provides the ideal hosting platform for the Telegram Subscription Manager with built-in support for Next.js, serverless functions, and cron jobs. This guide walks you through the complete deployment process.Prerequisites
Before deploying to Vercel, ensure you have:- Completed Database Setup
- Completed Telegram Bot Setup
- Completed Paystack Configuration
- A GitHub account (for connecting your repository)
- Your project pushed to a Git repository
Deployment Steps
Import Project to Vercel
- Go to vercel.com and sign in
- Click “Add New Project”
- Import your GitHub repository
- Select your repository from the list
Configure Environment Variables
Before deploying, add all required environment variables in the Vercel dashboard:
View All Required Environment Variables
View All Required Environment Variables
| Variable | Description | Example |
|---|---|---|
TELEGRAM_BOT_TOKEN | Your bot token from BotFather | 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 |
TELEGRAM_CHANNEL_ID | Your private channel ID | -1001234567890 |
PAYSTACK_SECRET_KEY | Paystack secret key | sk_live_abc123... or sk_test_abc123... |
DATABASE_URL | MongoDB connection string | mongodb+srv://user:[email protected]/db |
CRON_SECRET | Random secret for cron security | generate_a_random_secret_here |
NEXT_PUBLIC_APP_URL | Your Vercel deployment URL | https://your-app.vercel.app |
You can add environment variables in the Vercel dashboard under Project Settings → Environment Variables.
Deploy
Click “Deploy” and Vercel will:
- Install dependencies (
npm install) - Generate Prisma client (
prisma generate) - Build your Next.js application
- Deploy to a production URL
package.json automatically runs:Your first deployment will take 2-3 minutes. Subsequent deployments are faster.
Set Telegram Webhook
Once deployed, set your bot’s webhook to point to your Vercel deployment:Replace:
<YOUR_BOT_TOKEN>with your actual bot tokenyour-app.vercel.appwith your Vercel deployment URL
Configure Cron Jobs
Create a This configuration runs the expiry check every hour at minute 0.After adding Vercel will automatically redeploy and configure the cron job.
vercel.json file in your project root to configure the automated expiry check:vercel.json
Vercel cron jobs use standard cron syntax. The schedule
0 * * * * means “at minute 0 of every hour”.vercel.json, commit and push:Environment Variables Details
Generate CRON_SECRET
TheCRON_SECRET protects your cron endpoint from unauthorized access:
- Your Vercel environment variables
- Your local
.env.local(for development)
Update NEXT_PUBLIC_APP_URL
After deployment, updateNEXT_PUBLIC_APP_URL to your actual Vercel URL:
Cron Job Configuration
The cron job at/api/cron/remove-expired runs every hour to:
- Find all expired subscriptions
- Remove users from the Telegram channel
- Send expiry notifications
- Mark subscriptions as removed in the database
Cron Schedule Options
You can adjust the schedule invercel.json:
| Schedule | Runs |
|---|---|
0 * * * * | Every hour at minute 0 |
*/30 * * * * | Every 30 minutes |
0 */6 * * * | Every 6 hours |
0 0 * * * | Daily at midnight |
Monitoring and Logs
View Deployment Logs
- Go to your Vercel dashboard
- Select your project
- Click “Deployments”
- Click on a deployment to view logs
View Function Logs
For real-time debugging:- Go to Deployments → Functions
- Click on a function (e.g.,
/api/telegram/webhook) - View invocation logs and errors
View Cron Logs
- Go to Deployments → Cron Jobs
- See execution history and status
- Click on an execution to view logs
Vercel automatically retains logs for 7 days on the free tier, 30 days on Pro.
Troubleshooting
Bot Not Responding
Bot Not Responding
Check webhook setup:Verify:
urlmatches your Vercel deploymenthas_custom_certificateisfalsepending_update_countis0last_error_dateis not present
Environment Variables Not Working
Environment Variables Not Working
- Go to Project Settings → Environment Variables
- Verify all variables are present
- Check for extra spaces or quotes
- Ensure variables are set for Production environment
- Redeploy after adding/changing variables
Cron Job Not Running
Cron Job Not Running
Check cron job status:
- Go to Vercel dashboard → Deployments → Cron Jobs
- Verify the cron job is listed
- Check execution history for errors
CRON_SECRETmismatch (must match in environment variables)- Function timeout (increase in Vercel settings)
- Database connection errors (check
DATABASE_URL)
Build Failures
Build Failures
Check build logs:
- Go to Deployments
- Click on the failed deployment
- View the build logs
- Missing
DATABASE_URL(Prisma needs it at build time) - TypeScript errors
- Missing dependencies
DATABASE_URL is set in environment variables before deploying.Database Connection Errors
Database Connection Errors
If you see “Can’t reach database server” errors:
-
Verify MongoDB Atlas IP whitelist:
- Go to MongoDB Atlas → Network Access
- Ensure
0.0.0.0/0is whitelisted (allows Vercel to connect)
-
Check DATABASE_URL format:
-
Test connection locally:
Custom Domain (Optional)
To use a custom domain instead of*.vercel.app:
Add Domain in Vercel
- Go to Project Settings → Domains
- Enter your custom domain
- Follow DNS configuration instructions
Redeployment
To redeploy your application:-
Automatic: Push changes to GitHub
Vercel automatically deploys on every push to main branch.
-
Manual: Trigger deployment in Vercel dashboard
- Go to Deployments
- Click “Redeploy” on any previous deployment
Next Steps
Test Your Bot
Verify your deployment works correctly
Configure Plans
Customize subscription plans and pricing