Fetch live data from a third-party API through the platform proxy. Add "proxy_domains_requested": ["api.coingecko.com"] to your manifest (the upload scan usually detects it from the URL literal, but declaring it is your final say); proxy:http is auto-added. For APIs that need a key, store it with ctx.secrets and pass secret_auth= — see secret-backed auth.
import json
from yourbot_sdk import SdkError
@plugin.on_slash_command("price")
def price(ctx: Context, event: dict):
opts = {o["name"]: o["value"] for o in event.get("options", [])}
coin = (opts.get("coin") or "bitcoin").strip().lower()
try:
resp = ctx.http.get(
"https://api.coingecko.com/api/v3/simple/price",
params={"ids": coin, "vs_currencies": "usd"},
)
except SdkError as exc:
ctx.interaction.respond(content=f"Price lookup failed: {exc.code}")
return
if resp["status"] != 200:
ctx.interaction.respond(content="Price service is unavailable right now.")
return
data = json.loads(resp["body_bytes"]) or {}
usd = (data.get(coin) or {}).get("usd")
if usd is None:
ctx.interaction.respond(content=f"Unknown coin: {coin}")
return
ctx.interaction.respond(content=f"**{coin}**: ${usd:,}")
Responses are capped at 200 KB (check resp["truncated"] on big payloads) and the proxy allows 30 requests/minute per server — cache slow-moving data in ctx.kv with a ttl_seconds if you expect chatty usage.