Skip to content

About

📰 Telegram bot that posts new hot stories from Hacker News to telegram channel

Topics

Resources

Stars

238 stars

Watchers

5 watching

Forks

Repository files navigation

hackernewsbot

The Read Hacker News directory and the Telegram bot behind @hacker_news_feed, built and served from one Bun/TypeScript project.

You can preview the directory without bot credentials or a database.

Backend

Bun/TypeScript with SQLite, targeting a small Hetzner cloud machine shared with designernewsbot.

The old Python version ran on Google App Engine.

Hacker News API

Uses the Hacker News API to check top stories every 10 minutes and post stories scoring 150 or more.

Telegram API

Uses the Telegram Bot API sendMessage method.

URL shortening

Uses an internal shortener at readhacker.news. /s/<id> redirects to articles; /c/<id> redirects to Hacker News discussions.

How to run your own hackernewsbot

  • Install Bun 1.4.4, clone this project, and run bun install --frozen-lockfile.
  • Register a bot with BotFather and make it an administrator of your channel.
  • Copy .env.example to .env. Set TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID, DATABASE_URL, and BASE_URL; adjust PORT as needed. External environment values override the project-root .env; local/mode env files are not loaded.
  • For a new installation, run bun run db:init once. It refuses to overwrite an existing database.
  • Run bun run build:prod, then bun run start for HTTP and schedule bun run cron every 10 minutes from the project root, using a non-overlap lock. There is no HTTP /cron endpoint.
  • Keep this bot's database on persistent storage, shared by HTTP and cron but separate from designernewsbot. Use SQLite-aware backups and exclude databases and .env from deployment copies. Serve public traffic through an HTTPS reverse proxy.

Local development

Use a separate database, BASE_URL=http://localhost:8080, and a test channel such as @hacker_news_feed_st.

Run bun run dev, bun run test for offline tests, and bun run check for typechecking.

Read Hacker News directory

Site source lives in app/ and builds into static/, served by the bot's HTTP server.

bun run site:dev    # preview on http://localhost:9000; rebuilds on edits
bun run build:prod  # build static/ before starting the HTTP server

For a different domain, set SITE_ORIGIN when building: SITE_ORIGIN=https://directory.example bun run build:prod. It sets the site's canonical URL and is separate from the bot's BASE_URL; builds do not read .env.

See also

About

📰 Telegram bot that posts new hot stories from Hacker News to telegram channel

Topics

Resources

Stars

238 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages