A lightweight Cloudflare Worker that forwards Adapty subscription events to Telegram in real-time
Features • Quick Start • Configuration • Documentation • Support
|
|
|
|
| Emoji | Event Type | Description | Use Case |
|---|---|---|---|
| 🎉 | subscription_started |
New subscription started | Track new customers |
| 🔄 | subscription_renewed |
Subscription renewed | Monitor retention |
subscription_renewal_cancelled |
Auto-renewal cancelled | Identify churn risk | |
| ✅ | subscription_renewal_reactivated |
Auto-renewal reactivated | Track win-backs |
| 💰 | non_subscription_purchase |
One-time purchase (credits, IAPs) | Monitor transactions |
See what you'll receive in Telegram:
🎉 New Subscription |
🔄 Subscription Renewed |
|
Rich, detailed notifications with pricing, revenue, location, and more!
|
Required
|
Knowledge
|
git clone https://github.com/egebese/Adapty-Notifications-for-Telegram.git
cd Adapty-Notifications-for-Telegram
npm install- Open Telegram and search for @BotFather
- Send
/newbotcommand - Follow the instructions to create your bot
- Save the Bot Token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
Option A: Personal notifications
- Search for @userinfobot on Telegram
- Start a chat with it
- It will reply with your Chat ID (looks like
123456789)
Option B: Group notifications
- Create a group and add your bot to it
- Send a message in the group
- Visit
https://api.telegram.org/bot<BOT_TOKEN>/getUpdates - Find the
chat.idin the response (negative number for groups)
# macOS/Linux
openssl rand -base64 32
# Windows (PowerShell)
[Convert]::ToBase64String((1..32 | ForEach-Object { Get-Random -Maximum 256 }))Save this token - you'll need it for both the worker and Adapty.
Set your secrets in Cloudflare Workers (they'll be prompted):
npx wrangler secret put TELEGRAM_BOT_TOKEN
# Paste your bot token from BotFather
npx wrangler secret put TELEGRAM_CHAT_ID
# Paste your chat ID
npx wrangler secret put WEBHOOK_AUTH_TOKEN
# Paste the auth token you generatednpm run deployAfter deployment, you'll get a URL like:
https://adapty-telegram-webhook.your-subdomain.workers.dev
Save this URL! You'll need it for Adapty configuration.
Now connect your Cloudflare Worker to Adapty.
Step-by-step:
-
Open Adapty Dashboard
- Go to app.adapty.io
- Navigate to Integrations → Webhook
-
Toggle Webhook On
- Enable the webhook integration
-
Configure Production Endpoint
- Production endpoint URL:
https://your-worker.workers.dev/webhook- Replace with your actual worker URL from step 6
- Authorization header value:
Bearer YOUR_AUTH_TOKEN- Use the same token you set with
wrangler secret put
- Use the same token you set with
- Production endpoint URL:
-
Configure Sandbox Endpoint (Optional but recommended)
- Sandbox endpoint URL:
https://your-worker.workers.dev/webhook(same URL) - Authorization header value:
Bearer YOUR_AUTH_TOKEN(same token) - Note: Sandbox events will be filtered by the worker (no Telegram notifications)
- Sandbox endpoint URL:
-
Select Event Types
- Under Events names section, enable the events you want to track:
- ✅
subscription_started- New subscriptions - ✅
subscription_renewed- Renewals - ✅
subscription_renewal_cancelled- Cancellations - ✅
subscription_renewal_reactivated- Reactivations - ✅
non_subscription_purchase- One-time purchases (if applicable)
- ✅
- Under Events names section, enable the events you want to track:
-
Additional Options (Optional)
- ✅ Exclude historical events - Recommended to avoid sending old events
- You can leave other options unchecked unless you need them
-
Save Configuration
- Click Save at the bottom
📝 Example Configuration
Production endpoint URL:
https://adapty-telegram-webhook.your-subdomain.workers.dev/webhook
Authorization header value for production endpoint:
Bearer ABC123YourSecretTokenHere
Sandbox endpoint URL:
https://adapty-telegram-webhook.your-subdomain.workers.dev/webhook
Authorization header value for sandbox endpoint:
Bearer ABC123YourSecretTokenHere
Events enabled:
✓ subscription_started
✓ subscription_renewed
✓ subscription_renewal_cancelled
✓ subscription_renewal_reactivated
✓ non_subscription_purchase
⚠️ Important: Make sure the Bearer token in Adapty exactly matches theWEBHOOK_AUTH_TOKENyou set in Cloudflare Workers!
Set your worker URL and auth token:
export WEBHOOK_URL=https://your-worker.workers.dev/webhook
export WEBHOOK_AUTH_TOKEN=your-auth-token-hereThen run the test:
# Quick test (single event)
./test-webhook-simple.sh
# Full test suite (all events + security tests)
./test-webhook.shYou should receive notifications in your Telegram chat! 🎉
To use a custom domain instead of *.workers.dev:
- Add your domain to Cloudflare
- Edit
wrangler.toml:
[[routes]]
pattern = "webhook.yourdomain.com/*"
zone_name = "yourdomain.com"- Deploy:
npm run deploy - Update Adapty webhook URL to your custom domain
By default, sandbox events are automatically filtered and won't send Telegram notifications. This prevents test transactions from cluttering your notifications.
To receive sandbox notifications, edit src/index.js around line 103:
if (environment === 'Sandbox') {
// Comment out this entire block to receive sandbox notifications
}To track different events, edit the TRACKED_EVENTS array in src/index.js:
const TRACKED_EVENTS = [
'subscription_started',
'subscription_renewed',
'subscription_renewal_cancelled',
'subscription_renewal_reactivated',
'non_subscription_purchase'
];See Adapty Event Types for all available events.
Edit the formatTelegramMessage() function in src/index.js to customize notification formatting.
| Command | Description |
|---|---|
npm run dev |
🔥 Run locally with hot reload |
npm run tail |
📊 View live production logs |
npm run deploy |
🚀 Deploy to Cloudflare Workers |
./test-webhook-simple.sh |
✅ Quick single event test |
./test-webhook.sh |
🧪 Full test suite (8 tests) |
Each notification includes comprehensive data from Adapty webhooks, beautifully formatted in HTML:
|
📊 Subscription Details
|
💰 Financial Data
|
|
⏰ Timing Information
|
🎯 Analytics
|
Note: Not all fields may be present in every webhook - only available data is shown.
| Endpoint | Method | Auth Required | Description |
|---|---|---|---|
/health |
GET |
❌ No | Health check with configuration status |
/webhook |
POST |
✅ Yes (Bearer) | Main webhook endpoint for Adapty events |
/* |
OPTIONS |
❌ No | CORS preflight handling |
- Check Adapty Event Feed: Dashboard → Event Feed to see if events are being sent
- View worker logs:
npm run tail - Test health endpoint:
curl https://your-worker.workers.dev/health - Verify secrets: Health endpoint shows boolean flags for each secret
- Check bot permissions: Make sure you've sent
/startto your bot
- Token mismatch: Ensure Adapty's Bearer token matches your
WEBHOOK_AUTH_TOKEN - Check logs:
npm run tailshows received vs. expected token (first 10 chars) - Verify format: Header must be
Authorization: Bearer YOUR_TOKEN
- Start conversation: Send
/startto your bot first - Verify token: Check
TELEGRAM_BOT_TOKENis correct - Check chat ID: Ensure
TELEGRAM_CHAT_IDis correct (use @userinfobot) - Group permissions: If using a group, ensure bot has send message permissions
Make a test purchase in your app to trigger real events. Remember:
- Sandbox purchases won't send notifications (by design)
- Production purchases will send notifications
- Check worker logs with
npm run tailto see what's happening
| Service | Free Tier | Paid Tier | Typical Usage |
|---|---|---|---|
| Cloudflare Workers | 100,000 requests/day | $5/month for 10M requests | ~1,000-5,000/day |
| Telegram Bot API | Unlimited messages | Always free | Unlimited |
| Total | $0/month for most apps 🎉 | ||
|
✅ Implemented
|
|
|
📖 Documentation |
🔗 Related Projects |
Contributions are welcome! Here's how you can help:
|
🐛 Report Bugs Found a bug? Open an issue with:
|
💡 Suggest Features Have an idea? Create a feature request with:
|
🔧 Submit PRs Want to contribute code?
|
MIT License - see LICENSE file for details
| Type | Channel |
|---|---|
| 🐛 Bug Reports | GitHub Issues |
| 💡 Feature Requests | GitHub Issues |
| 📖 Adapty Support | Adapty Help Center |
| ☁️ Cloudflare Support | Cloudflare Community |


