Aller au contenu

Telegram

Créez un bot Telegram qui propose des lectures astrologiques grâce à Occult API.

Configuration du bot

Ouvrez BotFather dans Telegram, utilisez /newbot pour créer un bot et copiez le jeton d’API. Placez-le dans la variable d’environnement TELEGRAM_TOKEN.

Exemple Python

Utilisez python-telegram-bot pour gérer les commandes et appeler 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()

Commandes

Enregistrez ces commandes auprès de BotFather pour que les utilisateurs les voient dans le menu :

  • /horoscope aries — horoscope du jour
  • /panchang — panchang du jour
  • /natal — consultation du thème natal