Come costruire un bot Telegram per gli alert
Collega lo stream WebSocket a un bot Telegram in meno di 40 righe. L'esempio manda un messaggio in chat ogni volta che un round di Stake Crash supera 10×. Sostituisci la regola con qualsiasi condizione ti interessi — segment landings, soglie moltiplicatore, vincite grandi.
1. Crea il bot Telegram
Apri @BotFather su Telegram, /newbot, segui i prompt, salva il token HTTP API. Aggiungi il bot a un canale o gruppo e prendi il chat_id (usa @RawDataBot per dump info chat).
2. Definisci il trigger
Un trigger è una funzione booleana (round) → devo notificare? Tienilo piccolo; un bot per regola è più semplice di un bot con DSL di configurazione.
def should_alert(round):
return (
round["game_id"] == "stake-crash"
and float(round["multiplier"]) >= 10.0
)3. Lo script completo
import asyncio, json, os, httpx, websockets
TS_KEY = os.environ['TS_KEY']
BOT_TOKEN = os.environ['BOT_TOKEN']
CHAT_ID = os.environ['CHAT_ID']
TG_URL = f'https://api.telegram.org/bot{BOT_TOKEN}/sendMessage'
WS_URL = 'wss://api.trackersino.com/v1-beta/stream?games=stake-crash'
def should_alert(r):
return float(r['multiplier']) >= 10.0
def msg(r):
m = r['multiplier']; ts = r['finalized_at']
return f"🚀 Stake Crash hit <b>{m}×</b> at {ts}"
async def main():
async with httpx.AsyncClient() as http:
async for ws in websockets.connect(
WS_URL,
extra_headers=[('Authorization', f'Bearer {TS_KEY}')],
ping_interval=20,
):
try:
async for raw in ws:
r = json.loads(raw)
if should_alert(r):
await http.post(TG_URL, json={
'chat_id': CHAT_ID,
'text': msg(r),
'parse_mode': 'HTML',
})
except websockets.ConnectionClosed:
continue
asyncio.run(main())4. Eseguilo
pip install websockets httpx — poi `TS_KEY=… BOT_TOKEN=… CHAT_ID=… python bot.py`. Il bot si riconnette automaticamente quando lo stream cade.
5. Idee di trigger
Oltre a "multiplier > X": solo bonus di Crazy Time (segment ∈ {cf,pa,ch,ct}); solo Storm Bonus di Lightning Storm (segment == "stb"); solo round con total_amount > €N; solo round per uno specifico gioco; serie consecutive di perdite su una finestra (stato in localStorage).
Suggerimento hosting
Eseguilo su un VPS economico (DigitalOcean droplet €4/mese, Hetzner €3/mese) o Cloudflare Worker per il path no-server. Scrivici su Telegram se vuoi un Dockerfile.
Apri Telegram →