A Telegram channel monitoring application built with:
- Hono.js - Fast, lightweight API framework
- GramJS - Telegram client library for Node.js
- Effect-TS - Functional effect system for TypeScript
- Astro - Fast frontend framework
- SQLite - Embedded database
- SST - Infrastructure as code for Cloudflare deployment
src/
- Astro frontend files and library codelib/
- Core functionality modulestelegram/
- Telegram API interaction servicesdb/
- Database services
api/
- Hono backend API endpointsdata/
- SQLite database storagepublic/
- Static assetsstacks/
- SST infrastructure stacks for Cloudflare deployment
- ✅ Monitor multiple Telegram channels for new messages
- ✅ Store messages in a local SQLite database
- ✅ Generate activity reports using basic message analysis
- ✅ Scheduled scraping via cron job
- ✅ REST API endpoints for triggering scrapes and generating reports
- ✅ TypeScript support
- ✅ Scheduled cron jobs
- Node.js 18+
- Telegram API credentials
-
Get Telegram API Credentials:
- Visit https://my.telegram.org/apps
- Create a new application
- Note your API ID and API Hash
-
Install Dependencies:
pnpm install
-
Environment Variables: Create a
.env
file in the project root with:TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_CHANNELS=channel1,channel2,channel3 # Optional: Add your saved session string after first run TELEGRAM_SESSION=session_string
The first time you run the application, you'll need to authenticate with Telegram:
-
Start the API server:
pnpm run api:dev
-
The console will prompt you for:
- Your phone number (with country code)
- The authentication code sent to your Telegram app
- Your 2FA password (if enabled)
-
After successful authentication, a session string will be printed to the console. Add this to your
.env
file asTELEGRAM_SESSION
to avoid re-authentication.
-
Start the frontend development server:
pnpm run dev
-
Start the API development server:
pnpm run api:dev
-
Run the cron job manually:
pnpm run cron
For Cloudflare deployment using SST:
-
Set up Cloudflare credentials:
export CLOUDFLARE_API_TOKEN=your_token_here export CLOUDFLARE_ACCOUNT_ID=your_account_id_here
-
For development with local changes and remote resources:
pnpm sst:dev
-
For production deployment:
pnpm sst:deploy --stage prod
-
To remove all deployed resources:
pnpm sst:remove --stage prod
POST /telegram/scrape
Content-Type: application/json
{
"channel": "channelname"
}
POST /telegram/report
Content-Type: application/json
{
"channel": "channelname",
"days": 7
}
The application includes a scheduled cron job that runs daily at midnight. The cron job:
- Scrapes all configured channels for new messages
- Stores the messages in the SQLite database
- Generates daily activity reports
This application uses a functional architecture with Effect-TS:
-
Services - Core functionality is implemented as Effect-TS services
TelegramClientService
- Handles Telegram API communicationDatabaseService
- Manages SQLite database operationsScraperService
- Controls the scraping logicReportService
- Generates channel activity reports
-
APIs - Exposed via Hono.js HTTP endpoints
/telegram/scrape
- Trigger a manual scrape/telegram/report
- Generate a custom report
-
Infrastructure - Managed via SST
Database
- Cloudflare D1 SQLite-compatible databaseAPI
- Hono API deployed as a Cloudflare WorkerCron
- Scheduled Cloudflare Worker for periodic tasks