headway-news-bot

by selivandj

Not rated
GitHub

About

1 Browse Headway News Bot MCP Server for Claude, Cursor, VS Code, and other AI agents.

Details

Author
selivandj
Categories
Communication, Other

Setup

Install headway-news-bot in your MCP client (Claude Desktop, Cursor, Windsurf, and others).

Repository: https://github.com/selivandj/headway-news-bot

Follow the installation instructions in the repository README, then restart your MCP client.

Telegram approval bot and news monitor for the EV charging channel@headway74.

The project searches EV charging news, creates Russian Telegram drafts, attaches relevant media when possible, sends drafts to the owner for review, and publishes only after an explicit approval command.

- Human-gated publishing: draft first, channel publish only afterпубликуй.
- Channel voice is provider-independent and defined invps/channel_agent_rules.md.
- The bot writes for EV drivers, charger buyers, site owners, operators, installers, and EV infrastructure readers.
- The bot must not publish template filler or misleading media.
- Original article media is preferred. If no original media exists, exact entity search is preferred. AI image generation is allowed only after an explicit owner command.

- vps/monitor.py- scheduled news monitor, source parsing, LLM drafting, China reporting.
- vps/bot.py- Telegram approval bot, publish/rewrite/media commands.
- vps/channel_agent_rules.md- mandatory editorial rules for every model/provider.
- vps/database/history.py- SQLite history, quality statistics, owner feedback memory.
- vps/media/precise_image_search.py- precise image search for draft media corrections.
- vps/media/media_status.py- media status messages and owner guidance.
- vps/keyboards.py- inline keyboards with draft-bound callback data.
- vps/media/image_dedup.py- ImageHash-based media duplicate detection.
- vps/backup.py- SQLite gzip backups.
- vps/security/rate_limit.py- simple in-memory command rate limiter.
- vps/datasette-metadata.json- local-only Datasette metadata.
- vps/smoke_check.py- fast deployment sanity check.
- vps/tests/test_static_guards.py- static guard tests for critical behavior.

./.venv/bin/python vps/smoke_check.py ./.venv/bin/python -m unittest discover -s tests -p "test_.py" ./.venv/bin/python -m pytest tests systemctl status headway-news-bot.service --no-pager systemctl list-timers --all | grep headway

Main runtime configuration should live in the project root.env:/opt/headway-news-bot/.env.

For compatibility, the bot also checks/opt/headway-news-bot/vps/.env. Load order is root.envfirst, thenvps/.envfor missing values. The bot does not fail if either file is absent.

Бот ловит необработанные ошибки, пишет их в лог и может отправлять владельцу короткое Telegram-уведомление без токенов и API-ключей.

ADMIN_TELEGRAM_ID=117574226 ERROR_NOTIFICATIONS_ENABLED=1

ЕслиADMIN_TELEGRAM_IDне задан, бот используетTELEGRAM_REVIEW_CHAT_ID.

Под каждым черновиком появляется панель действий:

- ✅ Публиковать- публикует только выбранный черновик.
- 🖼 Найти фото- запускает точный поиск фото по сущностям черновика.
- 🎨 Сгенерировать- запускает существующий сценарий генерации по явной команде владельца.
- ✏️ Переделать текст- отправляет черновик на переписывание.
- ❌ Отклонить- снимает черновик с публикации и записывает решение в историю.
- ℹ️ Почему подходит?- показывает короткое объяснение источника, темы, медиа и причины отбора.

Старые reply-команды остаются рабочими:публикуй,найди фото ...,сгенерируй,переделай,отклонить,статистика.

Команда/daily_reportпоказывает сводку за последние 24 часа: источники, найденные новости, прошедшие фильтр материалы, созданные черновики, отклонения, ошибки источников, топ источников и темы дня.

Если данных еще нет, бот отвечает:Статистика за сутки пока не накоплена.

Для ежедневной автоматической отправки владельцу:

DAILY_REPORT_ENABLED=1 DAILY_REPORT_TIME=09:00 SCHEDULER_ENABLED=1 SCHEDULER_TIMEZONE=Asia/Yekaterinburg

APScheduler использует постоянные id задач и не дублирует их при перезапуске.

Root smoke-тесты лежат вtests/и не требуют реального Telegram token, платных API или публикации в канал.

Этап 2: управление черновиками и защита медиа

Клавиатуры вынесены вvps/keyboards.py. Каждая кнопка содержит короткийdraft_id, поэтому действие привязано к конкретному черновику:

- publish:{draft_id}- сначала показывает подтверждение публикации.
- confirm_publish:{draft_id}- публикует после второго клика владельца.
- find_photo:{draft_id}- запускает точный поиск фото.
- generate_image:{draft_id}- запускает генерацию только по явной команде владельца.
- rewrite:{draft_id}- отправляет черновик на переписывание.
- reject:{draft_id}- показывает причины отклонения.
- reject_reason:{draft_id}:{reason}- сохраняет причину и снимает черновик.
- why:{draft_id}- объясняет релевантность новости.

vps/media/image_dedup.pyсчитает perceptual hash изображения и хранит его вvps/database/image_hashes.db.

IMAGE_HASH_ENABLED=1 IMAGE_HASH_THRESHOLD=10

Точный поиск фото черезvps/media/precise_image_search.pyпроверяет найденное изображение через ImageHash. Если фото похоже на уже использованное, бот не подставляет его автоматически и пишет это в лог.

Это не веб-админка, а локальный просмотр SQLite. Порт наружу не открывать.

pip install datasette datasette vps/database/history.db \ --host=127.0.0.1 \ --port=8001 \ --metadata=vps/datasette-metadata.json

Потом открытьhttp://127.0.0.1:8001. Пример systemd unit:deploy/headway-datasette.service.example.

vps/backup.pyделает gzip-бэкап всех SQLite-баз изvps/database/.dbи хранит последние архивы.

- history.db
- image_hashes.db, если база уже создана ImageHash-дедупликацией

BACKUP_ENABLED=1 BACKUP_KEEP_DAYS=14 BACKUP_DIR=backups

Команда доступна только владельцу. Если базы еще нет, бот не падает и отвечает, что бэкап не создан.

- публикация;
- отклонение;
- генерация изображения;
- поиск изображения;
- бэкап.

OWNER_CHAT_ID=117574226 ADMIN_TELEGRAM_ID=117574226

Если команду вызывает не владелец, бот отвечает:Команда доступна только владельцу.

RATE_LIMIT_ENABLED=1 RATE_LIMIT_REQUESTS=30 RATE_LIMIT_WINDOW_SECONDS=60 RATE_LIMIT_OWNER_BYPASS=1

По умолчанию владелец не ограничивается rate limit.

При превышении лимита бот отвечает:Слишком много команд. Попробуйте позже.

python -m compileall vps python -m pytest tests -v ./.venv/bin/python vps/smoke_check.py systemctl restart headway-news-bot.service systemctl status headway-news-bot.service --no-pager

This temporary mode is used when the channel is being tuned again with owner feedback. It does not publish automatically. It only sends drafts to the owner for review.

- collect enough candidates every day;
- keep at least 2 strong publishable drafts per day in the review flow;
- save owner comments, rejects, media notes, and publish decisions intohistory.db;
- let future prompts use recent rejection feedback so provider swaps do not change the channel voice.

- vps/headway-news-monitor-training7d.timer
- vps/headway-news-monitor-training7d.service
- vps/run_training_monitor.sh

TRAINING_DURATION_HOURS=168 TRAINING_LOOKBACK_HOURS=24 TRAINING_TARGET_DRAFTS_PER_DAY=2
sudo cp vps/headway-news-monitor-training7d.service /etc/systemd/system/ sudo cp vps/headway-news-monitor-training7d.timer /etc/systemd/system/ sudo chmod +x vps/run_training_monitor.sh sudo systemctl daemon-reload sudo systemctl enable --now headway-news-monitor-training7d.timer sudo systemctl start headway-news-monitor-training7d.service
/opt/headway-news-bot/.venv/bin/python /opt/headway-news-bot/vps/monitor.py --hours "$TRAINING_LOOKBACK_HOURS" --send-review

It does not call channel publishing code. Publishing still requires owner approval in Telegram.

Useful Telegram commands during training:

- /training_status- shows whether training mode is active, when it started, hours left, candidates, drafts, owner publishes/rejects, rewrites, and media errors.
- /source_quality- shows source quality for 7 days by default.
- /source_quality 30or/source_quality 90- shows a longer source-quality window.
- /bad_sources- shows sources with low approval, many rejects, weak facts, poor media, or off-topic drafts. The bot only recommends, it does not disable sources automatically.
- /good_topics- shows topics that more often reach publication, including charging infrastructure, fast charging, China, subsidies, hubs, battery swap, and standards.
- /daily_report- includes the "Обучение канала за 7 дней" block while the training state exists.
- /memoryor/update_memory- refresheseditorial_memory.mdfrom history.

editorial_memory.mdkeeps manual notes outside this generated block:

<!-- AUTO_HISTORY_START --> ... <!-- AUTO_HISTORY_END -->

The automatic block stores best sources, bad sources, good topics, frequent rejection reasons, media rules, and phrases to avoid.

sudo systemctl disable --now headway-news-monitor-training7d.timer

The timer disables itself after the configured duration.

Do not commit.env, API keys, Telegram tokens, SSH keys, runtime drafts, media storage, logs, or SQLite databases.

Use.env.exampleas the only committed environment template.

Fetch and interact with Hacker News content, including top stories, comments, and search functionality.

Access Hacker News stories, comments, and user profiles using the Hacker News API.

Integrate real-time Hacker News data and discussions into your applications and workflows.

Interact with Hacker News through the Model Context Protocol (MCP), designed for Claude Desktop.

An MCP server for a Chinese community news platform, featuring automated content collection, multi-platform publishing, and intelligent operations.

An MCP server for interacting with the Reddit API, enabling searches for posts, comments, and subreddits.

A news feed server for aggregating news from various sources.

Access Reddit's public API to browse frontpage posts, subreddit information, and read post comments.

A server for fetching and creating content on Reddit using its API.

Interact with the Reddit API to fetch saved posts, search, get comments, and reply.

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.