AI Automation System

BTC Price Alert → Telegram

A scheduled monitoring system that alerts only on meaningful state changes (anti-spam logic).
n8n CoinGecko API Telegram Bot Schedule (15m) State Machine

Context & Problem

No spam alerts

Price tracking often becomes noisy: bots send the same alert repeatedly every time the workflow runs, even if nothing important changed.

Solution: track BTC price on a schedule and send a Telegram message only when the price crosses a defined threshold and the state changes (normal → above / normal → below). Uses persisted state to prevent duplicates.

Goal: Monitor BTC via CoinGecko and alert only on meaningful state changes, not on every run.

Implementation

Nodes & logic
  • Schedule (15m): runs every 15 minutes (Europe/Prague)
  • Set Thresholds: currency + upper_threshold + lower_threshold
  • HTTP Request: fetch BTC price from CoinGecko
  • Code: determine state (above/below/normal), compare with prev_state, set should_alert, build message
  • IF (state changed): pass only when should_alert == true
  • Send Telegram: deliver formatted alert message
Schedule → Set Thresholds → HTTP Request → Code → IF → Telegram
Fig 1. Workflow structure in n8n
HTTP Response Example (CoinGecko)
{ "bitcoin": { "usd": 68823 } }
Set Thresholds config
Fig 2. Threshold configuration
Code node - determine state & anti-spam
Fig 3. Core anti-spam logic in Code node
Pseudo-Logic (State Machine)
state =
  price >= upper_threshold ? "above" :
  price <= lower_threshold ? "below" :
  "normal"

should_alert =
  state !== prev_state
  AND state !== "normal"

if should_alert:
  send message
  save prev_state = state
Telegram alert message example
Fig 4. Example Telegram alert message
Example Telegram Message
🚀 BTC above threshold!
Price: 68,823 USD
Threshold: 68,000 USD
Time: 2026-02-13 21:15:52

Results & Impact

Why it matters
Quantitative
  • Checks every 15 minutes automatically
  • 0 duplicate alerts (state-based)
  • Near real-time monitoring
Qualitative
  • Noise-free notifications
  • Clear message formatting
  • Easy threshold tuning
Business Use Cases
  • Crypto risk monitoring
  • Portfolio alerting
  • Automated trading signals

Export Workflow

Download the n8n workflow JSON export and import it directly into your n8n instance.