Skip to content

VanshSahay/Elist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

34 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Elist β€” Telegram Waitlist Bot

A powerful Telegram bot for managing multiple waitlists inside community groups, built with Telegraf, TypeScript, Prisma, and Vercel serverless functions.


πŸš€ What It Does

  • πŸ”§ Admin Management: Group admins can create and close waitlists for any user
  • πŸ‘₯ User Subscriptions: Members can easily subscribe/unsubscribe from waitlists
  • πŸ“’ Private Broadcasting: Waitlist owners broadcast messages via DM to keep groups clean
  • 🏠 Chat Isolation: Each group has completely separate waitlists and subscribers
  • πŸ€– Smart Context: Commands behave differently in groups vs DMs for optimal UX
  • πŸ“Š Easy Tracking: List all waitlists in a group or track personal subscriptions
  • πŸ›‘οΈ Secure: Only authorized users can perform sensitive operations

🧠 Architecture Overview

Layer Technology Purpose
Telegram Bot Telegraf Bot interface and command handling
ORM Prisma Database schema and querying
Analytics PostHog User behavior tracking and insights
Runtime ts-node Local dev via polling
DB PostgreSQL Persistent waitlist + subscriber storage
Hosting Vercel Production webhook hosting

πŸ“ Folder Structure

 elist/
β”œβ”€β”€ api/
β”‚   └── webhook.ts         # Vercel serverless function entry (webhook)
β”œβ”€β”€ prisma/
β”‚   └── schema.prisma      # Prisma data model
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ bot.ts             # Bot setup and command logic
β”‚   β”œβ”€β”€ index.ts           # Local development entrypoint
β”‚   └── lib/
β”‚       β”œβ”€β”€ analytics.ts   # PostHog analytics integration
β”‚       └── prisma.ts      # Prisma client setup
β”œβ”€β”€ .env                   # Secrets (BOT_TOKEN, DATABASE_URL, POSTHOG_API_KEY)
β”œβ”€β”€ tsconfig.json          # NodeNext TypeScript config
β”œβ”€β”€ README.md              # This file
└── package.json           # Scripts and dependencies


πŸ” Environment Variables

.env file contents:

# Required
BOT_TOKEN=your_telegram_bot_token
DATABASE_URL=your_postgres_connection_string

# Optional - Analytics (PostHog)
POSTHOG_API_KEY=your_posthog_api_key
POSTHOG_HOST=https://us.i.posthog.com

πŸ“Š Analytics (PostHog) Setup

The bot includes comprehensive analytics tracking via PostHog. To enable:

  1. Sign up for PostHog (free tier available)
  2. Create a project and get your API key
  3. Add to .env:
    POSTHOG_API_KEY=phc_your_project_api_key
  4. Choose your host (optional):
    • US Cloud: POSTHOG_HOST=https://us.i.posthog.com (default)
    • EU Cloud: POSTHOG_HOST=https://eu.i.posthog.com
    • Self-hosted: POSTHOG_HOST=https://your-instance.com

πŸ“ˆ Tracked Events:

  • Commands: All bot commands with user and chat context
  • Registrations: User DM registrations for notifications
  • Subscriptions: Subscribe/unsubscribe events with product details
  • Broadcasts: Message sends with delivery metrics
  • Waitlists: Creation and deletion events
  • Errors: Bot errors with context for debugging

πŸ”’ Privacy: Only user IDs, usernames, and usage metrics are tracked. No message content is logged.


πŸ’¬ Available Bot Commands

πŸ“Œ Basic Commands

Command Who Can Use Description
/start Anyone Welcome message with quick start guide
/ping Anyone Check if the bot is alive
/help Anyone Show all available commands with descriptions

πŸ“‹ Waitlist Management

Command Who Can Use Description
/openwaitlist <product> @username Group Admins Create a waitlist and assign ownership
/closewaitlist <product> Owner or Admins Close and delete a waitlist permanently
/list Anyone List all waitlists in the current group

πŸ‘₯ User Commands

Command Who Can Use Description
/subscribe <product> Anyone Join a waitlist for a product
/unsubscribe <product> Anyone Leave a waitlist
/mywaitlists Anyone Context-aware: Shows current group's subscriptions in groups, all subscriptions in DM

πŸ“’ Broadcasting

Command Who Can Use Description
/broadcast <product> <message> Waitlist Owner DM only - Send message to all subscribers (keeps groups clean)

🎯 Key Features

🏠 Complete Chat Isolation

  • Each group has completely separate waitlists
  • Same product names can exist in multiple groups
  • No cross-group interference

πŸ€– Smart Context Awareness

  • In Groups: /mywaitlists shows only current group's subscriptions
  • In DMs: /mywaitlists shows all subscriptions across all groups with group names
  • Broadcasting: Only works via DM to keep group chats clean

πŸ›‘οΈ Permission System

  • Group Admins: Can create and close any waitlist
  • Waitlist Owners: Can broadcast and close their own waitlists
  • Regular Users: Can subscribe/unsubscribe and view lists

πŸ“’ Clean Broadcasting

  • All broadcasts happen via DM to bot
  • Automatic message footer shows waitlist and owner info
  • Group chats stay focused on discussion

πŸ“– Example Usage Workflows

🎯 Creating a Waitlist

  1. Admin adds bot to group
  2. Admin runs: /openwaitlist FlowWeave @alice
  3. Users can now: /subscribe FlowWeave
  4. @alice can DM bot: /broadcast FlowWeave New feature coming soon!

πŸ‘₯ User Journey

  1. User runs: /list (sees all group waitlists)
  2. User runs: /subscribe FlowWeave
  3. User runs: /mywaitlists (sees their subscriptions)
  4. User receives broadcast: "New feature coming soon!\n\nYou are receiving this message because you are on the waitlist for FlowWeave by @alice"

πŸ”§ Admin Management

  1. Admin runs: /list (sees all waitlists with subscriber counts)
  2. Admin can: /closewaitlist FlowWeave (cleanup unused lists)
  3. Owners can also close their own waitlists

πŸ§‘β€πŸ’» Local Development

Run the bot using polling:

pnpm install
pnpm run dev

This runs src/index.ts using ts-node, and launches the bot via polling.


☁️ Deploying to Vercel

The bot uses a serverless webhook for production on Vercel.

api/webhook.ts

import { bot } from '../src/bot.js';

export default async function handler(req, res) {
  await bot.handleUpdate(req.body);
  res.status(200).send('ok');
}

Set the Telegram webhook:

curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://<your-vercel-app>.vercel.app/api/webhook"

You only need to do this once per deployed URL.


🧠 LLM Editing Guide

This repo is LLM-friendly. Follow these conventions:

βœ… Edit Commands

All commands are defined like this in src/bot.ts:

bot.command('commandName', async (ctx) => { ... });

You can add new commands similarly. Use ctx.chat, ctx.from, ctx.message.text for context.

βœ… Add Database Fields

  1. Edit prisma/schema.prisma

  2. Run:

    pnpm exec prisma migrate dev --name your_migration

βœ… Use Telegram APIs

Send DMs:

ctx.telegram.sendMessage(userId, message);

🧼 Conventions

  • βœ… ES Modules ("type": "module" + .js extensions)
  • βœ… NodeNext resolution for compatibility
  • βœ… Strict TypeScript mode
  • βœ… Explicit command logic in one place

βœ… Testing

Feature Status Notes
/start - Welcome guide βœ… Shows comprehensive quick start
/ping - Health check βœ… Simple pong response
/help - Command list βœ… Complete command documentation
/openwaitlist - Create waitlist βœ… Admin-only, assigns ownership
/closewaitlist - Delete waitlist βœ… Owner or admin permissions
/subscribe - Join waitlist βœ… Chat-specific, duplicate protection
/unsubscribe - Leave waitlist βœ… Safe removal, always succeeds
/broadcast - Send messages βœ… DM-only, automatic footer
/list - Show group waitlists βœ… Shows names, owners, subscriber counts
/mywaitlists - Personal view βœ… Context-aware behavior
Chat Isolation βœ… Complete separation between groups
Permission System βœ… Admin, owner, user roles working
Error Handling βœ… Graceful fallbacks and clear messages

πŸ‘₯ Credits

Built by Vansh Sahay
Open to collaboration.

About

A telegram bot for managing waitlists across groups!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published