Telegram
Occult API से चलने वाला Telegram बॉट बनाएँ, जो ज्योतिष के जवाब दे।
बॉट सेटअप
Telegram में BotFather खोलें, /newbot से बॉट बनाएँ और API टोकन कॉपी करें। उसे TELEGRAM_TOKEN एनवायरनमेंट वेरिएबल में रखें।
Python उदाहरण
कमांड सँभालने और Occult API को कॉल करने के लिए python-telegram-bot इस्तेमाल करें:
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
import requests, os
async def horoscope(update: Update, context: ContextTypes.DEFAULT_TYPE):
sign = context.args[0] if context.args else 'aries'
response = requests.post(
f'https://api.occultapi.com/api/astro/rashifal/daily/',
headers={'X-API-Key': os.environ['OCCULT_API_KEY'], 'Content-Type': 'application/json'},
json={'rashi': sign},
)
data = response.json()
await update.message.reply_text(data['data']['get_daily_rashifal']['general_prediction'])
app = ApplicationBuilder().token(os.environ['TELEGRAM_TOKEN']).build()
app.add_handler(CommandHandler('horoscope', horoscope))
app.run_polling()कमांड
ये कमांड BotFather में दर्ज करें, ताकि उपयोगकर्ताओं को ये मेन्यू में दिखें:
/horoscope aries— आज का राशिफल/panchang— आज का पंचांग/natal— जन्म कुंडली देखें