Monitor Facebook post safety with Apify, Google Gemini and Telegram alerts
Install Guide
Draft — community verifyingGenerated by claude-sonnet-auto · 5/26/2026
Prerequisites
Before you begin, ensure you have the following:
- n8n (self-hosted or cloud) — version 1.0 or later recommended
- An Apify account for scraping Facebook posts (apify.com)
- A Google Gemini API-enabled Google Cloud account
- A Telegram account to receive alerts
- A Telegram bot created via @BotFather
- Basic familiarity with n8n workflows and JSON
Get Your API Keys
1. Apify API Token
- Sign in at console.apify.com
- Click your profile avatar → Settings → Integrations
- Under API tokens, click + Create new token
- Name it (e.g.,
n8n-facebook-monitor) and copy the token immediately
2. Google Gemini API Key
- Go to Google AI Studio
- Sign in with your Google account
- Click Create API key
- Select an existing Google Cloud project or create a new one
- Copy the generated API key and store it securely
Note: Ensure the Generative Language API is enabled in your Google Cloud Console.
3. Telegram Bot Token
- Open Telegram and search for @BotFather
- Send
/newbotand follow the prompts (provide a name and username) - Copy the bot token (format:
123456789:ABCdefGhIJKlmNoPQRstuVWXyz) - To get your Chat ID:
- Start a conversation with your bot
- Send
/start - Visit
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdatesin your browser - Find the
"chat": {"id": ...}value in the response
Installation
Option A: n8n Cloud
- Log in at app.n8n.cloud
- Navigate to Workflows → Import
- Paste the workflow JSON or upload the
.jsonfile
Option B: Self-Hosted n8n (Docker)
# Pull and run n8n with Docker
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
Option C: Self-Hosted n8n (npm)
# Install n8n globally
npm install -g n8n
# Start n8n
n8n start
Once n8n is running, import the workflow:
# If you have the workflow JSON file locally
# Go to http://localhost:5678 → Workflows → Import from file
Configuration
Set up credentials inside n8n for each service. Navigate to Settings → Credentials in the n8n UI.
| Variable / Credential | Description | Where to get it |
|-----------------------|-------------|-----------------|
| APIFY_API_TOKEN | Authenticates requests to Apify scrapers | Apify Console → Settings → Integrations |
| GEMINI_API_KEY | Authenticates requests to Google Gemini | Google AI Studio → API Keys |
| TELEGRAM_BOT_TOKEN | Identifies your Telegram bot | @BotFather on Telegram |
| TELEGRAM_CHAT_ID | Target chat/user to receive safety alerts | getUpdates API call (see above) |
| FACEBOOK_PAGE_URL | The Facebook page or post URL(s) to monitor | The target Facebook page/post |
| APIFY_ACTOR_ID | The Apify Actor used for Facebook scraping (e.g., apify/facebook-posts-scraper) | Apify Store |
Within n8n, create credentials as follows:
- Apify: Use the HTTP Header Auth credential type, with header
Authorizationand valueBearer <YOUR_APIFY_TOKEN> - Google Gemini: Use the Google Gemini(PaLM) Api built-in credential type and paste your API key
- Telegram: Use the built-in Telegram credential type and paste your bot token
Running the Bot
Development / Manual Testing
- Open n8n at
http://localhost:5678 - Open the imported workflow
- Click Execute Workflow to trigger a manual run
- Check the execution log on the right-hand panel for each node's output
Production / Scheduled Mode
- In the workflow, locate the Schedule Trigger node (or Cron node)
- Set your desired interval (e.g., every 30 minutes)
- Click the Activate toggle (top-right of the workflow editor) to switch it ON
- n8n will now run the workflow automatically on schedule
# If running self-hosted, ensure n8n stays alive with a process manager
npm install -g pm2
pm2 start n8n -- start
pm2 save
pm2 startup
Testing
Smoke Test
- Trigger manually: With the workflow open, click Execute Workflow
- Check Apify node: Verify the Facebook scraper node returns post data (green check, non-empty output)
- Check Gemini node: Confirm the AI analysis node returns a safety classification in its output panel
- Check Telegram node: You should receive a test message in your Telegram chat within a few seconds
Verify Telegram delivery
Send a test message directly to confirm your bot token and chat ID are correct:
curl -s -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage" \
-d chat_id="<YOUR_CHAT_ID>" \
-d text="n8n test message — bot is connected"
You should see the message appear in your Telegram chat immediately.
Troubleshooting
| Problem | Likely cause | Fix |
|---------|-------------|-----|
| Apify node returns empty results or 401 error | Invalid or missing Apify API token | Re-check the token in n8n Credentials; ensure it has not expired and the Actor ID is correct |
| Gemini node returns 403 Forbidden | Generative Language API not enabled or wrong API key | Visit the Google Cloud Console and enable the API; verify the key matches the correct project |
| Telegram message not delivered | Incorrect CHAT_ID or bot has never been messaged by the user | Visit https://api.telegram.org/bot<TOKEN>/getUpdates to confirm the chat ID; send /start to your bot first to initiate the conversation |
| Workflow activates but never runs on schedule | n8n process was restarted and workflow was deactivated | Re-open the workflow in the editor and toggle Active back on; if using Docker/npm, ensure the container/process is persistent |
| Facebook scraper returns rate-limit or access errors | Apify Actor hit Facebook's rate limits or the page is private | Increase the scraper interval, use a different Apify Actor, or verify the target Facebook page is publicly accessible |
| Gemini returns unexpected safety classifications | Prompt or post content is ambiguous | Review and refine the Gemini prompt in the AI node; add explicit instructions for edge cases |
Sign in to leave feedback on this guide.