# A Telegram bot that sends a daily horoscope

> A Telegram bot in plain Node: a user picks their zodiac sign, asks for today's horoscope whenever they like, and gets it pushed once a day. A thousand Leo subscribers still cost one API call a day.

Source: https://astronode.dev/templates/telegram-horoscope-bot · Updated: 2026-12-05

## What it does

- Commands: `/start`, `/sign <sign>` to subscribe (any spelling or case), `/today`, and `/stop`.
- Pushes today's horoscope to every subscriber once a UTC day at `PUSH_HOUR_UTC`; a bot that was down at that hour catches up on start, and never sends twice.
- Caches one horoscope per sign per day and shares in-flight requests, so the cost is at most twelve calls a day whatever the audience.
- Unsubscribes a chat when Telegram says the user blocked the bot. If the API fails during a push, that sign is skipped and logged rather than sending apologies.
- Uses long polling, so it needs no public URL - only an always-on process.

## Endpoints and plan

*API calls the template makes*

| Endpoint | Used for | Plan |
| --- | --- | --- |
| `GET /v1/horoscope/daily/{sign}` | Today's horoscope for a sign (`?date=YYYY-MM-DD`) | Free |

Everything it calls is on the Free plan, so a Free test key runs the whole template.

## Where things live

| File | What it holds |
| --- | --- |
| `src/bot.js` | Command parsing, the four commands, the daily push |
| `src/horoscope.js` | Sign normalisation, the per-sign-per-day cache, message formatting |
| `src/astronode.js` | The API client; turns the error envelope into an `AstroNodeError` |
| `src/store.js` | Subscriptions in a JSON file, written atomically |
| `src/telegram.js` | `getUpdates`, `sendMessage`, `deleteWebhook` |

## Keys and deployment

- The API key is read from the server's environment and sent as `Authorization: Bearer <key>`; it never reaches a browser or an app bundle.
- `npm run check` runs the tests against API responses recorded in `test/fixtures/` - no key and no network, so it can run in your CI.
- Any always-on Node host: a small VPS with systemd or pm2, or a worker on a platform such as Railway, Render or Fly - no HTTP port needed.
- Put `SUBSCRIPTIONS_FILE` on a persistent volume; on an ephemeral filesystem the subscriptions vanish on every deploy.
- For serverless, switch to Telegram's `setWebhook`, call `bot.handleUpdate()` from your handler and `bot.pushDaily()` from a scheduled job.

## Questions

**How many API calls does the Telegram horoscope bot make?**

At most one per zodiac sign per day - twelve - because each day's horoscope is cached per sign and shared by every subscriber.

**Can the bot send horoscopes in Hindi?**

The endpoint takes `language=hi`; the template sends English. Pass `language` in `src/horoscope.js` and keep a language per subscriber to offer both.

**Does it need a server with a public URL?**

No. It uses long polling, so any always-on process works. A webhook variant is described in the README for serverless hosts.

## Related pages

- [Use case: messaging bots](https://astronode.dev/use-cases/messaging-bot)
- [Recipe: a daily horoscope newsletter](https://astronode.dev/recipes/daily-horoscope-newsletter)
- [WhatsApp panchang bot](https://astronode.dev/templates/whatsapp-panchang-bot)
- [All templates](https://astronode.dev/templates)
