Telegram Bot Setup
Get the Loyalteez Telegram bot running in your group.
Step 1: Add Bot to Your Group
- Open your Telegram group
- Click group name → Add Members
- Search for the bot username (e.g.,
@LoyalteezBot) - Add as administrator (required for commands)
The bot needs admin permission to:
- Read messages for GM/GN detection
- Respond to commands
- Track activity
Step 2: Get Your Security Key
- Go to Partner Portal → Settings → Security
- Click the copy icon next to your Security Key
- Copy the entire key (it's a long hex string)
You must provide your Security Key when connecting your group. This authenticates your group and enables secure communication with the Loyalteez API.
Step 3: Start Secure Setup (DM Flow)
Unlike Discord where admins can use private channels, Telegram groups don't have private admin-only spaces. To protect your Security Key from being exposed in public chat, the setup process uses a secure DM flow.
3a. Start a DM with the Bot
- Find the bot in your group members list
- Click the bot's name → "Send Message"
- In the private chat, send:
/setup
3b. Provide Your Brand ID
The bot will ask for your Brand ID. Send:
0xYOUR_BRAND_ADDRESS
Your Brand ID is your wallet address shown in Partner Portal → Settings → Account. It starts with 0x and is 42 characters long.
3c. Provide Your Security Key
The bot will then ask for your Security Key. Send:
YOUR_SECURITY_KEY_HERE
Your Security Key is a long hexadecimal string. Make sure you copy the entire key from Partner Portal → Settings → Security. If you don't have one, click "Regenerate" to create a new Security Key.
3d. Receive Activation Token
After validating your credentials, the bot will respond with:
✅ Registration successful!
Your activation token: abc123xyz
Go to your Telegram group and use:
/activate abc123xyz
The token expires in 1 hour.
Copy this token - you'll need it for the next step.
Step 4: Activate in Your Group
Return to your Telegram group and send:
/activate abc123xyz
(Replace abc123xyz with your actual token)
You should see:
✅ Community activated!
Your group is now connected to [Brand Name].
Members can start earning LTZ immediately!
Try /daily to get started.
Default Configuration
When activation completes, the bot automatically creates default events:
telegram_daily_checkin: 10 LTZ, 24h cooldowngm_checkin: 25 LTZ, 24h cooldowngn_checkin: 15 LTZ, 24h cooldowntelegram_join: 50 LTZ, one-timemessage_quality: 10 LTZ (disabled by default)telegram_admin_reward: For manual rewards
These events are stored in monitoring_rules and can be fully customized via /config events or the Partner Portal.
Step 5: Verify Setup
Test the daily check-in:
/daily
You should see:
✅ Daily check-in complete!
💰 Earned: 10 LTZ
🔥 Streak: 1 day
Step 6: Configure Events (Optional)
View All Events
/config events
Change Reward Amount
/config reward telegram_daily_checkin 25
Configure Daily Event
/config daily-event telegram_daily_checkin
Available Commands
User Commands
| Command | Description |
|---|---|
/daily | Daily check-in for LTZ |
/balance | Check your LTZ balance |
/streak | View your current streak |
/join | Claim welcome bonus (if not auto-claimed) |
/help | Show available commands |
Admin Commands
| Command | Description |
|---|---|
/setup | Start secure setup flow (DM only) |
/activate <token> | Activate community in group |
/config | View/modify community settings |
/stats | View community analytics |
/test | Run diagnostic checks |
/reward <user> <amount> | Manually reward a user |
/disconnect | Deactivate community |
Disconnecting a Community
If you need to disconnect your group from Loyalteez:
/disconnect
The bot will ask for confirmation:
⚠️ Are you sure you want to disconnect this group?
This will:
- Stop all rewards
- Deactivate the community
- Require re-setup to restore
Type /disconnect confirm to proceed.
Then confirm with:
/disconnect confirm
Self-Hosted Deployment
If you're deploying your own instance of the Telegram bot:
Prerequisites
- Cloudflare account with Workers access
- Telegram Bot Token (from BotFather)
- Supabase credentials
- Wrangler CLI installed
Get a Bot Token
- Open Telegram and search for
@BotFather - Send
/newbot - Choose a name and username
- Copy the token
Deploy the Worker
# Clone the repository
git clone https://github.com/Alpha4-Labs/loyalteez-official-telegram-bot.git
cd loyalteez-official-telegram-bot
# Install dependencies
npm install
# Configure secrets
wrangler secret put TELEGRAM_BOT_TOKEN
wrangler secret put SUPABASE_PUBLISH_KEY
wrangler secret put SUPABASE_SECRET_KEY
wrangler secret put ENCRYPTION_KEY
wrangler secret put TEST_API_KEY # Optional: for E2E testing
# Create KV namespace
wrangler kv:namespace create "TELEGRAM_KV"
# Update wrangler.toml with the namespace ID
# Deploy
npm run deploy
Set Webhook
curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook?url=https://your-worker.workers.dev"
Environment Variables
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN | Yes | Bot token from BotFather |
SUPABASE_URL | Yes | Supabase project URL |
SUPABASE_PUBLISH_KEY | Yes | Supabase anon key |
SUPABASE_SECRET_KEY | Yes | Supabase service role key |
ENCRYPTION_KEY | Yes | AES-256 key for security key encryption |
SHARED_SERVICES_URL | Yes | URL to Shared Services worker |
LOYALTEEZ_API_URL | Yes | URL to Event Handler |
TEST_API_KEY | No | API key for E2E test endpoint |
Security Configuration
Configure rate limiting via environment variables:
# wrangler.toml
[vars]
RATE_LIMIT_ENABLED = "true"
RATE_LIMIT_MODE = "soft" # monitor | soft | full
RATE_LIMIT_USER_BURST = "30"
RATE_LIMIT_USER_SUSTAINED = "100"
RATE_LIMIT_COMMUNITY_BURST = "1000"
RATE_LIMIT_ADMIN_BURST = "10"
RATE_LIMIT_BAN_DURATION = "300"
MAX_SINGLE_REWARD = "10000"
MAX_DAILY_ADMIN_REWARD = "100000"
MAX_PAYLOAD_SIZE = "51200"
Database Requirements
The bot requires these Supabase tables:
- brand_communities - Cross-platform community configurations
- monitoring_rules - Event configurations (shared with Discord)
- perk_collections - Perk data (shared with Discord)
See Shared Services - Community Service for schema details.
Troubleshooting Setup
"Brand not found"
- Verify Brand ID is correct (42 characters, starts with
0x) - Ensure you have an active Partner Portal subscription
"Security Key Required" or "Security Key Validation Failed"
- Get your Security Key from Partner Portal → Settings → Security
- Make sure you copied the entire Security Key (it's a long hex string)
- Verify the Security Key matches the Brand ID you're using
- If you don't have a Security Key, click "Regenerate" in Partner Portal
- Try
/setupagain in a DM with the bot
"Invalid activation token"
- Activation tokens expire after 1 hour
- Start the setup flow again with
/setupin a DM - Make sure you're using the token in the correct group
"Not an admin"
- Add the bot as a group administrator
- Check group settings → Administrators
Bot not responding
- Verify webhook is set correctly
- Check Cloudflare Worker logs
- Ensure bot has admin permission in group
"Rate limited"
If you're seeing rate limit messages:
- Wait a few moments before trying again
- The bot uses behavior-based rate limiting
- Excessive rapid requests will temporarily restrict access
Next Steps
- Admin Guides - Configure your program
- Commands Reference - Learn all commands
- Community Service API - API reference for self-hosting