Quick overview
This workflow listens for a YouTube channel link sent to a Telegram bot, pulls the channel and latest upload metrics from the YouTube Data API, computes velocity and baseline benchmarks, logs a snapshot to Google Sheets, and generates a structured report using Google Gemini that it replies with in Telegram.
How it works
- Triggers when a new Telegram message arrives and extracts a YouTube channel ID or @handle from the text.
- Validates the link format and replies in Telegram with usage instructions if no channel identifier is found.
- Calls the YouTube Data API to resolve the channel details and replies in Telegram if the channel is not found or if the API call fails.
- Fetches the channel’s uploads playlist and retrieves the latest 20 uploads, then batches a YouTube Data API request to get each video’s stats and metadata.
- Calculates per-video metrics (such as views per hour, age, duration, chapters, and engagement per 1,000 views), ranks videos by velocity, and computes baseline and “fingerprint” benchmarks (cadence, format splits, title patterns, and trend).
- If there are fewer than five videos older than 48 hours, sends a “no baseline” message in Telegram; otherwise, appends a snapshot row to Google Sheets.
- Sends the computed metrics to Google Gemini to write a five-section analysis and posts the final channel report back to Telegram.
Setup
- Create a Telegram bot, add your Telegram credentials in n8n, and enable the Telegram Trigger webhook for the workflow.
- Add YouTube Data API credentials (API key via HTTP Query Auth) and ensure the key has access to the YouTube Data API v3.
- Add Google Gemini (Google PaLM) API credentials and keep the model set to
models/gemini-3.1-flash-lite.
- Add a Google Sheets service account credential, share the target spreadsheet with the service account email, and set the document ID and tab for the snapshot log.
- Replace the placeholder webhook IDs and any placeholder Sheet IDs/URLs in the workflow with your environment’s actual values.