{"id":28477050,"url":"https://github.com/evmts/telegram-bot","last_synced_at":"2025-07-02T16:31:20.882Z","repository":{"id":288371631,"uuid":"967817243","full_name":"evmts/telegram-bot","owner":"evmts","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-17T04:15:18.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-07T15:48:48.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evmts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-17T03:46:35.000Z","updated_at":"2025-04-17T04:15:22.000Z","dependencies_parsed_at":"2025-04-17T18:25:00.145Z","dependency_job_id":"3ba72161-0b4e-4973-a1e1-c4d19b523504","html_url":"https://github.com/evmts/telegram-bot","commit_stats":null,"previous_names":["evmts/telegram-bot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/evmts/telegram-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmts%2Ftelegram-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmts%2Ftelegram-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmts%2Ftelegram-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmts%2Ftelegram-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evmts","download_url":"https://codeload.github.com/evmts/telegram-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evmts%2Ftelegram-bot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263175434,"owners_count":23425568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-07T15:40:27.774Z","updated_at":"2025-07-02T16:31:20.862Z","avatar_url":"https://github.com/evmts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AI Telegram Monitor\n\nA Telegram channel monitoring application built with:\n- Hono.js - Fast, lightweight API framework\n- GramJS - Telegram client library for Node.js\n- Effect-TS - Functional effect system for TypeScript\n- Astro - Fast frontend framework\n- SQLite - Embedded database\n- SST - Infrastructure as code for Cloudflare deployment\n\n## Project Structure\n\n- `src/` - Astro frontend files and library code\n  - `lib/` - Core functionality modules\n    - `telegram/` - Telegram API interaction services\n    - `db/` - Database services\n- `api/` - Hono backend API endpoints\n- `data/` - SQLite database storage\n- `public/` - Static assets\n- `stacks/` - SST infrastructure stacks for Cloudflare deployment\n\n## Features\n\n- ✅ Monitor multiple Telegram channels for new messages\n- ✅ Store messages in a local SQLite database\n- ✅ Generate activity reports using basic message analysis\n- ✅ Scheduled scraping via cron job\n- ✅ REST API endpoints for triggering scrapes and generating reports\n- ✅ TypeScript support\n- ✅ Scheduled cron jobs\n\n## Setup\n\n### Requirements\n\n- Node.js 18+\n- Telegram API credentials\n\n### Configuration\n\n1. **Get Telegram API Credentials**:\n   - Visit [https://my.telegram.org/apps](https://my.telegram.org/apps)\n   - Create a new application\n   - Note your API ID and API Hash\n\n2. **Install Dependencies**:\n   ```bash\n   pnpm install\n   ```\n\n3. **Environment Variables**:\n   Create a `.env` file in the project root with:\n   ```\n   TELEGRAM_API_ID=your_api_id\n   TELEGRAM_API_HASH=your_api_hash\n   TELEGRAM_CHANNELS=channel1,channel2,channel3\n   # Optional: Add your saved session string after first run\n   TELEGRAM_SESSION=session_string\n   ```\n\n### First Run Authentication\n\nThe first time you run the application, you'll need to authenticate with Telegram:\n\n1. Start the API server:\n   ```bash\n   pnpm run api:dev\n   ```\n\n2. The console will prompt you for:\n   - Your phone number (with country code)\n   - The authentication code sent to your Telegram app\n   - Your 2FA password (if enabled)\n\n3. After successful authentication, a session string will be printed to the console.\n   Add this to your `.env` file as `TELEGRAM_SESSION` to avoid re-authentication.\n\n## Development\n\n### Local Development (without SST)\n\n1. Start the frontend development server:\n   ```bash\n   pnpm run dev\n   ```\n\n2. Start the API development server:\n   ```bash\n   pnpm run api:dev\n   ```\n\n3. Run the cron job manually:\n   ```bash\n   pnpm run cron\n   ```\n\n### SST Development and Deployment\n\nFor Cloudflare deployment using SST:\n\n1. Set up Cloudflare credentials:\n   ```bash\n   export CLOUDFLARE_API_TOKEN=your_token_here\n   export CLOUDFLARE_ACCOUNT_ID=your_account_id_here\n   ```\n\n2. For development with local changes and remote resources:\n   ```bash\n   pnpm sst:dev\n   ```\n\n3. For production deployment:\n   ```bash\n   pnpm sst:deploy --stage prod\n   ```\n\n4. To remove all deployed resources:\n   ```bash\n   pnpm sst:remove --stage prod\n   ```\n\n## API Endpoints\n\n### Scrape a Channel\n\n```http\nPOST /telegram/scrape\nContent-Type: application/json\n\n{\n  \"channel\": \"channelname\"\n}\n```\n\n### Generate a Report\n\n```http\nPOST /telegram/report\nContent-Type: application/json\n\n{\n  \"channel\": \"channelname\",\n  \"days\": 7\n}\n```\n\n## Cron Jobs\n\nThe application includes a scheduled cron job that runs daily at midnight. The cron job:\n\n1. Scrapes all configured channels for new messages\n2. Stores the messages in the SQLite database\n3. Generates daily activity reports\n\n## Architecture\n\nThis application uses a functional architecture with Effect-TS:\n\n- **Services** - Core functionality is implemented as Effect-TS services\n  - `TelegramClientService` - Handles Telegram API communication\n  - `DatabaseService` - Manages SQLite database operations\n  - `ScraperService` - Controls the scraping logic\n  - `ReportService` - Generates channel activity reports\n\n- **APIs** - Exposed via Hono.js HTTP endpoints\n  - `/telegram/scrape` - Trigger a manual scrape\n  - `/telegram/report` - Generate a custom report\n\n- **Infrastructure** - Managed via SST\n  - `Database` - Cloudflare D1 SQLite-compatible database\n  - `API` - Hono API deployed as a Cloudflare Worker\n  - `Cron` - Scheduled Cloudflare Worker for periodic tasks\n\n## References\n\n- [GramJS Documentation](https://gram.js.org/)\n- [Effect-TS Documentation](https://effect-ts.github.io/effect/docs/ai/ai)\n- [SST Documentation](https://sst.dev/docs/start/cloudflare/worker/)\n- [Cloudflare Workers](https://developers.cloudflare.com/workers/)\n- [Cloudflare D1 Database](https://developers.cloudflare.com/d1/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevmts%2Ftelegram-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevmts%2Ftelegram-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevmts%2Ftelegram-bot/lists"}