Skip to main content

Get Started in Minutes

This guide will walk you through setting up and deploying your Telegram Subscription Manager bot as quickly as possible.
Prerequisites: Make sure you have Node.js 18+, a Telegram account, MongoDB Atlas account, and Paystack account ready.

Setup Process

1

Create Your Telegram Bot

Open Telegram and message @BotFather:
  1. Send /newbot command
  2. Choose a name for your bot (e.g., “VIP Subscription Bot”)
  3. Choose a username (must end in “bot”, e.g., “myvipchannel_bot”)
  4. Copy the bot token (format: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
Keep your bot token secure! Never commit it to version control or share it publicly.
2

Configure Bot Commands

In BotFather, send /setcommands, select your bot, and paste:
start - Welcome message and payment instructions
pay - Get payment link for subscription
verify_basic - Verify Basic plan payment (7 days)
verify_biweekly - Verify Bi-Weekly plan payment (14 days)
verify_monthly - Verify Monthly plan payment (30 days)
verify_premium - Verify Premium plan payment (14 days + copier)
verify_promo - Verify promo code payment
status - Check subscription status
mt5setup - Setup MT5 Auto Copier (Premium only)
settings - Configure copier settings (Premium only)
mystats - View copier statistics (Premium only)
help - Show help and instructions
3

Get Your Channel ID

You need to get the ID of your private Telegram channel:
  1. Forward any message from your channel to @userinfobot
  2. The bot will reply with channel details
  3. Copy the channel ID (format: -100xxxxxxxxxx)
  4. Add your bot as an administrator to the channel
  5. Grant these permissions:
    • ✅ Invite users via link
    • ✅ Restrict members (ban/unban)
Without admin permissions, the bot cannot create invite links or remove expired users.
4

Clone and Install

Get the project code and install dependencies:
# Clone the repository
git clone <your-repo-url>
cd telegram-subscription-manager

# Install dependencies
npm install
5

Configure Environment Variables

Create a .env.local file in the project root:
.env.local
# Telegram Bot Configuration
TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather
TELEGRAM_CHANNEL_ID=-100xxxxxxxxxx

# Paystack Configuration
PAYSTACK_SECRET_KEY=sk_test_your_paystack_secret_key

# Database Configuration
DATABASE_URL=mongodb+srv://username:[email protected]/vipbot

# Cron Security (generate a random string)
CRON_SECRET=your_random_secret_string_here

# Application URL
NEXT_PUBLIC_APP_URL=http://localhost:3000
  • TELEGRAM_BOT_TOKEN: From BotFather (Step 1)
  • TELEGRAM_CHANNEL_ID: From userinfobot (Step 3)
  • PAYSTACK_SECRET_KEY: From Paystack Dashboard → Settings → API Keys
  • DATABASE_URL: From MongoDB Atlas → Database → Connect → Application
  • CRON_SECRET: Generate a random string (e.g., use openssl rand -hex 32 in terminal)
6

Setup MongoDB Database

Initialize your database schema:
# Generate Prisma client
npx prisma generate

# Push schema to MongoDB (creates collections)
npx prisma db push
MongoDB doesn’t use migrations like SQL databases. The db push command creates or updates collections based on your schema.
7

Run Locally

Start the development server:
npm run dev
Your bot should now be running at http://localhost:3000.
The bot won’t respond yet because Telegram doesn’t know your local server’s URL. Continue to the next step.
8

Setup Webhook (Development)

For local testing, use ngrok to create a public URL:
# Install ngrok (or use npx)
npx ngrok http 3000
Copy the HTTPS URL (e.g., https://abc123.ngrok.io) and set the webhook:
curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://abc123.ngrok.io/api/telegram/webhook"
Or visit this URL in your browser:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://abc123.ngrok.io/api/telegram/webhook
You should see:
{"ok":true,"result":true,"description":"Webhook was set"}
9

Test Your Bot

Open Telegram and message your bot:
  1. Send /start - You should see the welcome message with plan details
  2. Send /pay - Provide an email and receive payment buttons
  3. Click a payment button - Complete a test transaction on Paystack
  4. Send /verify_basic <reference> - The bot should verify and send an invite link
Use Paystack test mode initially. Test cards are available in the Paystack documentation.

Deploy to Production

1

Push to GitHub

git init
git add .
git commit -m "Initial commit"
git remote add origin <your-github-repo-url>
git push -u origin main
2

Import to Vercel

  1. Go to vercel.com and sign in
  2. Click “Add New” → “Project”
  3. Import your GitHub repository
  4. Click “Deploy”
3

Add Environment Variables

In Vercel dashboard:
  1. Go to your project → Settings → Environment Variables
  2. Add all variables from your .env.local file
  3. Update NEXT_PUBLIC_APP_URL to your Vercel domain (e.g., https://your-bot.vercel.app)
  4. Redeploy the project
4

Configure Cron Job

Create vercel.json in your project root:
vercel.json
{
  "crons": [
    {
      "path": "/api/cron/remove-expired",
      "schedule": "0 * * * *"
    }
  ]
}
This runs the expiry check every hour at minute 0.
5

Update Webhook URL

Set your production webhook URL:
curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://your-bot.vercel.app/api/telegram/webhook"
Vercel automatically handles SSL certificates, so your webhook URL will be HTTPS (required by Telegram).

Verification Checklist

Before going live, verify everything works:
  • /start shows welcome message with all plans
  • /pay collects email and shows payment buttons
  • Payment links open correctly in browser
  • Test payments are processed by Paystack
  • /verify_basic verifies payment and sends invite link
  • Invite links allow joining the channel
  • /status shows correct subscription details
  • /help displays help information
  • Set your admin user ID in src/lib/config.ts (line 52)
  • Test /broadcast sends messages to all users
  • Test /botstats shows user statistics
  • Test /checkuser looks up user subscriptions
  • Environment variables are not committed to git
  • .env.local is in .gitignore
  • Paystack webhook signature verification is enabled
  • Cron endpoint is protected with CRON_SECRET
  • Bot token is kept secret
  • Cron job is configured to run hourly
  • Test that expired subscriptions are detected
  • Users are removed from channel when expired
  • Expiry notifications are sent to users

Common Issues

Possible causes:
  • Webhook URL is incorrect or not set
  • Server is not running or unreachable
  • Bot token is invalid
  • Environment variables not loaded
Solutions:
  1. Check webhook status: curl https://api.telegram.org/bot<TOKEN>/getWebhookInfo
  2. Verify server is running and accessible
  3. Check server logs for errors
  4. Confirm environment variables are set correctly
Possible causes:
  • Paystack secret key is incorrect
  • Transaction reference is invalid
  • Payment status is not “success”
  • Payment amount doesn’t match plan
Solutions:
  1. Verify Paystack secret key is correct
  2. Check payment status in Paystack dashboard
  3. Ensure reference is copied correctly
  4. Check payment amount matches expected plan amount
Possible causes:
  • Cron not configured on hosting platform
  • CRON_SECRET mismatch
  • Endpoint returns error
Solutions:
  1. Verify vercel.json cron configuration
  2. Check Vercel cron logs in dashboard
  3. Manually test endpoint: curl -H "Authorization: Bearer <CRON_SECRET>" https://your-bot.vercel.app/api/cron/remove-expired

Next Steps

Customize Plans

Learn how to modify pricing and features

Setup Premium Features

Configure the MT5 Auto Copier integration

API Reference

Explore webhook endpoints and integrations

Troubleshooting

Detailed solutions for common problems

Build docs developers (and LLMs) love