Skip to content

WhatsApp

Build a WhatsApp bot that responds to astrology queries using Occult API.

Overview

Use the WhatsApp Business API or a framework like whatsapp-web.js to receive messages and call Occult API. The webhook receives incoming messages, parses the query, and returns astrology data as a reply.

Node.js Example

A simple Express webhook handler that responds to horoscope requests:

webhook.js
app.post('/webhook', async (req, res) => {
  const message = req.body.entry?.[0]?.changes?.[0]?.value?.messages?.[0];
  if (message?.text?.body?.toLowerCase().startsWith('horoscope')) {
    const sign = message.text.body.split(' ')[1] || 'aries';
    const apiRes = await fetch('https://api.occultapi.com/api/astro/rashifal/daily/', {
      method: 'POST',
      headers: { 'X-API-Key': process.env.OCCULT_API_KEY, 'Content-Type': 'application/json' },
      body: JSON.stringify({ rashi: sign }),
    });
    const data = await apiRes.json();
    await sendWhatsAppMessage(message.from, data.get_daily_rashifal.general_prediction);
  }
  res.sendStatus(200);
});

Supported Queries

Users can send messages like:

  • horoscope aries — daily horoscope for Aries
  • today tithi — current tithi information
  • manglik check — manglik dosha analysis