सीधे सामग्री पर जाएँ

WhatsApp

Occult API से ज्योतिष के सवालों का जवाब देने वाला WhatsApp बॉट बनाएँ।

सारांश

संदेश पाने और Occult API को कॉल करने के लिए WhatsApp Business API या whatsapp-web.js जैसा कोई फ़्रेमवर्क इस्तेमाल करें। webhook आने वाले संदेश लेता है, सवाल पढ़ता है, और ज्योतिष का डेटा जवाब में भेजता है।

Node.js उदाहरण

एक सादा Express webhook हैंडलर, जो राशिफल के अनुरोधों का जवाब देता है:

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);
});

कौन-से सवाल चलते हैं

उपयोगकर्ता ऐसे संदेश भेज सकते हैं:

  • horoscope aries — मेष राशि का आज का राशिफल
  • today tithi — आज की तिथि की जानकारी
  • manglik check — मांगलिक दोष की जाँच