Quick Overview
This workflow powers a Telegram astrology bot that manages chat sessions in Supabase, calculates natal or synastry charts via AstrologyAPI using location and timezone lookups, and uses Google Gemini (via an n8n AI Agent) plus reference text from Google Drive to craft responses back to Telegram.
How it works
- Receives incoming Telegram messages and callback queries from users.
- Looks up the user’s session in Supabase by chat ID and routes the conversation through a state machine to collect either natal or synastry birth details.
- Inserts or updates the session state and collected inputs in Supabase, and sends the next prompt/status message back to the user in Telegram.
- When enough birth data is provided, parses the intake text, geocodes the city with OpenStreetMap Nominatim, and fetches a timezone offset from the GeoNames Timezone API.
- Calls AstrologyAPI (western_horoscope or synastry_horoscope) with the computed coordinates and timezone to generate chart data.
- Downloads a JSON reference file from Google Drive and merges it with the live chart output to build an analysis context.
- Sends the user prompt plus context to a Google Gemini chat model through an AI Agent with memory, logs the reading metadata to Supabase, and posts the final formatted response to Telegram.
Setup
- Add Telegram bot credentials and set the bot webhook in n8n so Telegram can deliver updates to the Telegram Trigger.
- Add Supabase credentials and create the required tables/fields (sessions with chat_id, state, mode, p1_data, p2_data; and astrology_readings for logging).
- Add HTTP Basic Auth credentials for AstrologyAPI and confirm the endpoint URLs match your AstrologyAPI plan (western_horoscope and synastry_horoscope).
- Provide a valid GeoNames username in the timezone request, and ensure outbound HTTP access to OpenStreetMap Nominatim and GeoNames from your n8n instance.
- Add Google Drive OAuth credentials and update the Google Drive file ID for the reference JSON (synastry.json) if you use a different file.
- Add Google Gemini (PaLM) API credentials for the chat model used by the AI Agent.