Skip to content

Telegram

Create a Telegram bot that provides astrology readings powered by Occult API.

Bot Setup

Open BotFather in Telegram, use /newbot to create a bot, and copy the API token. Set it as the TELEGRAM_TOKEN environment variable.

Python Example

Use python-telegram-bot to handle commands and call Occult API:

bot.py
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()

Commands

Register these commands with BotFather so users see them in the menu:

  • /horoscope aries — daily horoscope
  • /panchang — today's panchang
  • /natal — natal chart lookup