FrayBot (@fray_holy_bot) answers as a digital Catholic priest using the Magisterium AI API. It only addresses religious topics and responds in the user's language with a calm, friendly tone.
- Python 3.10+
- Magisterium AI account and API key
- Telegram bot token
- Install dependencies:
pip install -r requirements.txt
- Copy the example env file and fill in your credentials:
cp env.example .env
Set in .env:
MAGISTERIUM_API_KEY: your Magisterium key (keep it secret, do not commit).TELEGRAM_BOT_TOKEN: your Telegram bot token.
- Run the bot:
python bot.py
The bot will start polling for messages.
There is a Cloudflare Worker version under cloudflare_worker/ for webhook-based operation (recommended for production).
- Cloudflare account with a
workers.devsubdomain (e.g.,fraybot-worker.e1digital.workers.dev). - A KV namespace for conversation context.
- Install dependencies
cd cloudflare_worker
npm install- Create KV namespace and set IDs in
wrangler.toml
npx wrangler kv namespace create CONTEXT_KV
# copy id/preview_id into wrangler.toml- Add secrets (per account)
npx wrangler secret put TELEGRAM_BOT_TOKEN
npx wrangler secret put MAGISTERIUM_API_KEY
# optional if you want webhook auth:
npx wrangler secret put TELEGRAM_SECRET_TOKEN- Deploy
npx wrangler deployThe Worker should respond ready at https://<your-subdomain>.workers.dev/.
- Register Telegram webhook (replace with your token and URL)
https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/setWebhook?url=https://<your-subdomain>.workers.dev/telegram
# if you set TELEGRAM_SECRET_TOKEN, append: &secret_token=<same_value>- Check webhook status
https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/getWebhookInfoLogs are enabled via wrangler.toml ([observability.logs]). Tail logs with:
npx wrangler tail- Never hardcode or commit your real keys.
- Keep secrets in environment variables or
.env(and keep the file untracked).
- Responds only about Catholic faith, morality, prayer, and spiritual guidance.
- Tone: calm, empathetic, and respectful.
- Language: replies in the language detected from the user.
- Includes related questions if Magisterium returns them and shows citations when available.