# A WhatsApp bot that answers with today's panchang

> A WhatsApp Cloud API webhook in plain Node: someone texts a city and gets today's panchang for it in the city's own time - tithi with its end time, nakshatra, yoga, karana, sunrise, sunset and Rahu Kaal - or texts a sign and gets today's horoscope.

Source: https://astronode.dev/templates/whatsapp-panchang-bot · Updated: 2026-12-05

## What it does

- Understands a city name (20 built in, with aliases such as Bombay and NYC), `panchang` (the user's last city), `panchang for <city>`, and `horoscope <sign>` or a bare sign.
- Works out each city's UTC offset at local noon, so daylight saving and offsets such as Kathmandu's +5:45 come out right, and shows every time in the city's own zone.
- Caches the panchang per city per local day, calling the two endpoints in parallel.
- Verifies `X-Hub-Signature-256` on the raw body with a constant-time compare, answers Meta's verification handshake, replies 200 at once and ignores retried message ids.
- With a Free key, `POST /v1/muhurta/inauspicious` answers `PLAN_REQUIRED`; the bot then sends the panchang without the Rahu Kaal line instead of failing.

## Endpoints and plan

*API calls the template makes*

| Endpoint | Used for | Plan |
| --- | --- | --- |
| `POST /v1/panchang` | Tithi, nakshatra, yoga, karana, sunrise, sunset | Free |
| `POST /v1/muhurta/inauspicious` | Rahu Kaal | Hobby |
| `GET /v1/horoscope/daily/{sign}` | Today's horoscope for a sign | Free |

It needs a Hobby key or above: at least one endpoint it calls is not on the Free plan. See [pricing](https://astronode.dev/pricing).

## Where things live

| File | What it holds |
| --- | --- |
| `src/bot.js` | Parses each message and picks the reply |
| `src/webhook.js` | Handshake, signature check, extracting text messages |
| `src/panchang.js` | The per-city-per-day cache and the message format |
| `src/time.js` | Local date, offset at local noon, time formatting |
| `src/cities.js` | The built-in city list - extend it or swap in a geocoder |
| `src/whatsapp.js` | Sends replies through the Graph API |

## 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.
- Meta needs a public HTTPS webhook URL. While developing, a tunnel such as cloudflared or ngrok in front of the local port works.
- Runs on any Node host that accepts HTTPS - a VPS behind a reverse proxy, or a web service on a platform such as Render or Fly.
- Keep the app secret set: without it the signature check cannot run.

## Questions

**Does the WhatsApp bot work on the Free plan?**

Partly. The panchang and horoscope endpoints are on Free; Rahu Kaal needs Hobby. With a Free key the bot sends the panchang without the Rahu Kaal line.

**Can users ask for any city?**

The template knows 20 cities with aliases. Add more to `src/cities.js`, or replace the lookup with a geocoder that returns coordinates and an IANA zone.

**Why is the panchang computed per city and not per user?**

The panchang depends only on the place and the local day, so every user asking for Delhi today shares one cached answer.

## Related pages

- [Use case: messaging bots](https://astronode.dev/use-cases/messaging-bot)
- [Recipe: daily panchang for a city](https://astronode.dev/recipes/daily-panchang-for-a-city)
- [Telegram horoscope bot](https://astronode.dev/templates/telegram-horoscope-bot)
- [All templates](https://astronode.dev/templates)
