This endpoint is designed to be called by a cron job scheduler (e.g., Vercel Cron, GitHub Actions, or external cron services) to automatically process expired subscriptions. It removes users from the Telegram channel, deletes their MetaCopier accounts, and sends notifications.
This endpoint is open (no authentication required in the current implementation) and should be protected by your cron service’s authentication or network-level security.
When a subscription expires, users receive the following notification:
⏰ Your subscription has expired.━━━━━━━━━━━━━━━━━━━Your access to Pear VIP signals channel has been removed.━━━━━━━━━━━━━━━━━━━Want to renew?Just tap the button below to make a new payment!💎 Basic: ₦5,000 (7 days)📊 Bi-Weekly: ₦10,000 (14 days)📅 Monthly: ₦15,000 (30 days)👑 Premium: ₦22,000 (14 days + Copier)━━━━━━━━━━━━━━━━━━━Or type /pay to get started.
✅ MetaCopier Account Removed━━━━━━━━━━━━━━━━━━━User: 123456789 (@username)MetaCopier Account: MC12345Reason: Subscription expired━━━━━━━━━━━━━━━━━━━User has been removed from channel and MetaCopier.
⚠️ MetaCopier Removal Failed - Manual Action Needed!━━━━━━━━━━━━━━━━━━━User: 123456789 (@username)MetaCopier Account: MC12345MetaCopier Copier: COPIER789Error: API connection timeout━━━━━━━━━━━━━━━━━━━Action Required:• User has been removed from channel• But MetaCopier account could NOT be removed automatically• Please remove manually from MetaCopier dashboardLogin: 12345678Server: ICMarkets-Demo01
The endpoint provides detailed console logging for monitoring:
// Success logsconsole.log(`Sending broadcast to ${subscriptions.length} users`)console.log(`Removed user ${subscription.telegramUserId} (subscription ${subscription.id})`)console.log(`Successfully removed MetaCopier account for user ${subscription.telegramUserId}`)// Error logsconsole.error(`Failed to ban user ${subscription.telegramUserId}`)console.error(`Failed to remove MetaCopier account: ${result.error}`)console.error(`Error removing subscription ${subscription.id}:`, error)
For testing in development, you can manually trigger the endpoint:
# Test locallycurl http://localhost:3000/api/cron/remove-expired# Test stagingcurl https://staging.your-domain.com/api/cron/remove-expired# Test production (be careful!)curl https://your-domain.com/api/cron/remove-expired
Testing Precautions:Be cautious when testing in production as this endpoint will actually remove users and send notifications. Consider:
Testing in a staging environment first
Using a test Telegram channel
Temporarily modifying the query to only process specific test subscriptions
Checking the processed count before actual removal