A tool that automatically summarizes messages from specified Telegram channels and sends the summary to a target chat. Uses OpenAI's GPT model for summarization.
- Fetches messages from multiple Telegram channels
- Summarizes content using OpenAI's GPT model
- Generates a separate weekly joke based on the news summary
- Sends summary and joke as separate messages to a specified chat
- Runs automatically via GitHub Actions on a weekly schedule
- Configurable time period for message collection
- Node.js 18 or later
- Telegram account
- OpenAI API key
- GitHub account (for automated runs)
-
Clone the repository
git clone https://github.com/yourusername/TelegramChannelsSummarizer.git cd TelegramChannelsSummarizer -
Install dependencies
npm install
-
Get Telegram API credentials
- Go to https://my.telegram.org/auth
- Log in with your phone number
- Click on "API development tools"
- Create a new application
- Note down your
api_idandapi_hash
-
Generate Telegram session string
npm run generate-session
- Enter your phone number when prompted
- Enter the verification code sent to your Telegram
- If you have 2FA enabled, enter your password
- Copy the generated session string
-
Configure environment variables Create a
.envfile with:TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_STRING_SESSION=your_session_string TG_CHANNELS=channel1,channel2 # Comma-separated list of channel usernames TG_TARGET_CHAT_ID=your_chat_id # ID of the chat to receive summaries OPENAI_API_KEY=your_openai_api_key DAYS=7 # Number of days to look back for messages (weekly summary) -
Find chat ID (if needed)
npm run find-chat-id -- "chat name"Or use Telegram Web:
- Open https://web.telegram.org
- Open the target chat
- The URL will contain the chat ID after
p=u
-
Fork the repository
-
Add repository secrets Go to Settings > Secrets and variables > Actions Add the following secrets:
TELEGRAM_API_IDTELEGRAM_API_HASHTELEGRAM_STRING_SESSIONTG_CHANNELSTG_TARGET_CHAT_IDOPENAI_API_KEY
-
Configure schedule Edit
.github/workflows/summary.ymlto change the schedule:schedule: - cron: '0 6 * * 1' # Runs every Monday at 06:00 UTC
npm run build
npm startThe workflow runs automatically based on the schedule in .github/workflows/summary.yml.
You can also trigger it manually from the GitHub Actions tab.
- Change channels: Update
TG_CHANNELSin.envor repository secrets - Change schedule: Edit the cron expression in
.github/workflows/summary.yml - Change summary language: Modify the system prompt in
src/telegram-summary.ts - Change model: Update the model name in
src/telegram-summary.ts - Customize joke style: Edit the joke generation prompt in the
generateJokefunction
-
Session expired
- Run
npm run generate-sessionto get a new session string - Update the session string in
.envand repository secrets
- Run
-
API limits
- Check OpenAI API usage
- Check Telegram API limits
-
Authentication issues
- Verify API credentials
- Regenerate session string if needed
MIT License - feel free to modify and use as needed.