İçeriğe atla

WhatsApp

Occult API ile astroloji sorularını yanıtlayan bir WhatsApp botu oluşturun.

Genel bakış

Mesajları almak ve Occult API'yi çağırmak için WhatsApp Business API'yi ya da whatsapp-web.js gibi bir çatıyı kullanın. Webhook gelen mesajları alır, sorguyu ayrıştırır ve astroloji verilerini yanıt olarak döndürür.

Node.js örneği

Burç yorumu isteklerini yanıtlayan basit bir Express webhook işleyicisi:

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

Desteklenen sorgular

Kullanıcılar şu gibi mesajlar gönderebilir:

  • horoscope aries — Koç burcu için günlük yorum
  • today tithi — geçerli tithi bilgisi
  • manglik check — manglik dosha analizi