This guide explains how to integrate Coinbase Commerce for crypto payments and Telegram login for FutuChat access control.
- View Pricing → User sees pricing plans with "Buy with Crypto" buttons
- Initiate Payment → Click button → Create Coinbase Commerce charge
- Pay with Crypto → Redirect to Coinbase → Complete payment (BTC, ETH, USDC, etc.)
- Payment Confirmation → Coinbase confirms → Redirect back to app
- Telegram Login → User must login via Telegram to complete activation
- Auto-Activation → System verifies payment + Telegram → Generates access key → Activates automatically
- Access Granted → User can now use FutuChat
- ✅ Payment verification via Coinbase Commerce
- ✅ User identity via Telegram OAuth
- ✅ One payment = One Telegram account
- ✅ Prevents key sharing and abuse
- ✅ Trackable user activity
- Go to https://commerce.coinbase.com/
- Sign up or login
- Complete KYC verification (required for receiving payments)
- Navigate to Settings → API Keys
- Create a new API key
- Copy the API Key (starts with a long string)
- Save it securely
- Go to Settings → Webhook subscriptions
- Add webhook URL:
https://your-domain.vercel.app/api/webhook - Copy the Webhook Secret
- Select events to receive:
charge:confirmed,charge:resolved
- Test with small amounts first
- Coinbase Commerce supports: BTC, ETH, USDC, USDT, DAI, BCH, LTC, DOGE
- Payments are converted to USD equivalent
- Settlement to your bank account takes 1-2 business days
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow prompts to name your bot (e.g., "FutuChat Access Bot")
- Choose username (e.g.,
futuchat_access_bot) - BotFather will give you a Bot Token (format:
1234567890:ABCdefGHIjklMNOpqrsTUVwxyz) - Save this token securely
- Send
/setdomainto @BotFather - Select your bot
- Enter your domain:
your-domain.vercel.app - Send
/setdescriptionand add: "Access verification bot for FutuChat" - Send
/setabouttextand add: "This bot verifies your identity for FutuChat access"
/start - Start interaction with bot
/help - Get help with activation
/status - Check your subscription status
Add these environment variables in your Vercel project:
# X.AI API (existing)
XAI_API_KEY=your_xai_api_key_here
SYSTEM_PROMPT=your_system_prompt_here
# Coinbase Commerce
COINBASE_COMMERCE_API_KEY=your_coinbase_api_key_here
COINBASE_WEBHOOK_SECRET=your_webhook_secret_here
# Telegram Bot
TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz
TELEGRAM_BOT_USERNAME=futuchat_access_bot- Go to your project dashboard on Vercel
- Navigate to Settings → Environment Variables
- Add each variable with its value
- Select Production, Preview, and Development environments
- Click Save
- Redeploy your application for changes to take effect
Find this line (around line 381):
script.setAttribute('data-telegram-login', 'YOUR_BOT_USERNAME');Replace YOUR_BOT_USERNAME with your actual bot username (without @):
script.setAttribute('data-telegram-login', 'futuchat_access_bot');The current implementation stores data temporarily. For production, integrate a database:
npm install @vercel/kv- ✅ Serverless-ready
- ✅ Fast key-value storage
- ✅ Built-in Vercel integration
- ✅ Free tier available
npm install @upstash/redis- ✅ Serverless Redis
- ✅ REST API
- ✅ Pay-as-you-go pricing
npm install @supabase/supabase-js- ✅ Full PostgreSQL database
- ✅ Built-in authentication
- ✅ Real-time subscriptions
- ✅ Storage for files
// Payments table
{
chargeId: string,
chargeCode: string,
plan: string,
amount: number,
duration: number,
status: 'pending' | 'confirmed' | 'resolved',
createdAt: timestamp,
confirmedAt: timestamp
}
// Users table
{
telegramId: number,
telegramUsername: string,
firstName: string,
lastName: string,
chargeCode: string, // Link to payment
accessKeyHash: string,
activatedAt: timestamp,
expiresAt: timestamp
}
// Access logs (optional - for analytics)
{
telegramId: number,
action: 'login' | 'chat' | 'payment',
timestamp: timestamp,
metadata: json
}- Use small payment amounts for testing ($1-2)
- Use Coinbase Commerce test mode if available
- Create a test Telegram account
- Click "Buy with Crypto" on 7-day plan
- Should redirect to Coinbase Commerce
- Complete payment with crypto (or use test mode)
- Redirect back to your app
- See payment success screen
- Click Telegram login button
- Authorize bot access
- Should auto-activate and show chat interface
- Check Vercel logs for API calls
- Check Coinbase Commerce dashboard for payments
- Check browser console for errors
- Check localStorage for activation data
- ✅ NEVER commit API keys to git
- ✅ Use Vercel environment variables
- ✅ Rotate keys periodically
- ✅ Use different keys for development/production
- ✅ Always verify webhook signatures
- ✅ Check timestamp to prevent replay attacks
- ✅ Validate payload structure
- ✅ Verify Telegram auth hash on backend
- ✅ Check auth_date timestamp (reject old logins)
- ✅ Store access key hashes, not plain keys
- ✅ Implement rate limiting for API endpoints
- ✅ Only store necessary Telegram data (ID, username)
- ✅ Don't store payment details (use Coinbase IDs)
- ✅ Implement data deletion on request
- ✅ Clear expired activations periodically
- Coinbase Commerce account verified
- All environment variables set in Vercel
- Telegram bot domain configured
- Database integrated (recommended)
- Test full payment flow
- Set up error monitoring (Sentry, LogRocket)
- Enable Vercel Analytics
- Configure custom domain with SSL
- Update webhook URLs to production domain
- Test webhook delivery
- Monitor Coinbase Commerce dashboard for payments
- Check Vercel function logs for errors
- Track user activations
- Monitor support requests via Telegram
- Set up automated expiration notifications
- Payment conversions (clicks → payments)
- Telegram login completion rate
- Plan popularity (7-day vs 30-day)
- User retention
- Activation errors
- Webhook delivery success
- Vercel Analytics - Page views, conversions
- Coinbase Commerce Dashboard - Payment analytics
- Sentry - Error tracking
- PostHog - Product analytics
- Telegram Bot Analytics - User engagement
- Check COINBASE_COMMERCE_API_KEY is set correctly
- Verify API key has correct permissions
- Check Vercel function logs for errors
- Test with Coinbase Commerce API directly
- Verify bot username in code matches actual username
- Check domain is registered with @BotFather
- Ensure HTTPS is enabled (required for Telegram login)
- Test bot token with Telegram API directly
- Verify webhook URL is publicly accessible
- Check webhook secret matches environment variable
- Test signature verification logic
- Use Coinbase Commerce webhook testing tool
- Check browser console for errors
- Verify payment was confirmed in Coinbase
- Check localStorage for pending charge data
- Test activate-telegram API endpoint manually
- Docs: https://commerce.coinbase.com/docs/
- Support: https://help.coinbase.com/
- Docs: https://core.telegram.org/bots
- Login Widget: https://core.telegram.org/widgets/login
- Docs: https://vercel.com/docs
- Support: https://vercel.com/support
- Database Integration - Add persistent storage
- Email Notifications - Notify on successful activation
- Subscription Management - Allow users to check status
- Auto-Renewal - Remind users before expiration
- Referral System - Give discounts for referrals
- Usage Analytics - Track chat usage per user
- Admin Dashboard - View all activations, payments
- Multiple Plans - Add more pricing tiers
- Discounts - Implement promo codes
- Telegram Notifications - Send messages via bot
- Multi-currency pricing
- Team/organization plans
- API access tiers
- Custom AI model selection per plan
- Chat history export
- Priority support for premium users
🎉 You're all set! Good luck with your launch!
For questions or issues, refer to the troubleshooting section or contact support through the channels listed above.