Bot for Telegram that gets, summarizes and posts news to a channel.
- Fetching articles from RSS feeds
- Article summaries powered by GPT
- Admin commands for managing sources
Click to view the demonstration
Here’s how the bot works in action:The bot publishes the title of the article, a summary and a link to the original article
- Programming Language: Go
- Database: PostgreSQL
- AI Summarization: OpenAI GPT-3.5 Turbo
- Configuration: HCL and environment variables
- Containerization: Docker and Docker Compose
git clone https://github.com/wta4i-ei/AI-RSS-Telegram-Bot
cd project
You can configure the bot using either environment variables (.env
file) or HCL configuration files.
Create a .env
file in the project root with the following variables:
PROXY_URL=your_proxy_url
NFB_TELEGRAM_BOT_TOKEN=your_telegram_bot_token
NFB_TELEGRAM_CHANNEL_ID=your_channel_id
NFB_DATABASE_DSN=postgres://user:password@host:port/dbname?sslmode=disable
NFB_FETCH_INTERVAL=10m
NFB_NOTIFICATION_INTERVAL=1m
NFB_OPENAI_KEY=your_openai_api_key
NFB_OPENAI_PROMPT="Summarize the article concisely in 3 sentences"
Alternatively, create an HCL config file in one of the following locations:
./config.hcl
./config.local.hcl
$HOME/.config/AI-RSS-Telegram-Bot/config.hcl
Example config.hcl
:
proxy_url = "your_proxy_url"
telegram_bot_token = "your_telegram_bot_token"
telegram_channel_id = "your_channel_id"
database_dsn = "postgres://user:password@host:port/dbname?sslmode=disable"
fetch_interval = "10m"
notification_interval = "1m"
openai_key = "your_openai_api_key"
openai_prompt = "Summarize the article concisely in 3 sentences"
Run the following command to build and start the bot:
docker-compose -f docker-compose.dev.yml up -d
Check that the containers are running:
docker ps
Install goose
, a database migration tool:
go install github.com/pressly/goose/v3/cmd/goose@latest
Navigate to the migrations directory and apply migrations to the database:
goose postgres "host=localhost user=postgres database=news_feed_bot password=postgres sslmode=disable" up
Navigate to the cmd
directory and run the bot:
cd cmd
go run main.go
Use the following commands in your Telegram bot to manage RSS sources:
-
Add a Source
/addsource 'name' 'url' 'priority'
Example:/addsource "Tech News" "https://example.com/rss" "1"
-
Set Priority for a Source
/setpriority 'id' 'priority'
Example:/setpriority 1 10
-
Delete a Source
/deletesource 'id'
Example:/deletesource 1
-
Get Information About a Source
/getsource 'id'
Example:/getsource 1
-
List All Sources
/listsources
The bot is now configured and running. It will fetch news articles based on the fetch_interval
and post them to your Telegram channel at the notification_interval
. 🎉