EnergyVenom's picture
Patchwise Agent Studio: Oracle AI Agent Studio cycles
af1bee9 verified
|
Raw History Blame Contribute Delete
2.83 kB

Telegram relay (only if your host blocks Telegram)

Some hosts, Hugging Face Spaces among them, block connections to api.telegram.org. You can tell from the Space log: Patchwise prints notify: telegram delivery failed with a connection error, and the startup summary shows Telegram configured but nothing arrives.

The fix is a small free Cloudflare Worker that forwards Patchwise's Telegram calls.

Set it up (about 5 minutes)

  1. Sign in at https://dash.cloudflare.com (a free account is enough), then go to Workers & Pages → Create → Create Worker.
  2. Name it, for example patchwise-telegram, and select Deploy.
  3. Select Edit code, replace everything with the contents of worker.js, and select Deploy.
  4. Go to Settings → Variables and Secrets → Add. Name it BOT_ID, with the number before the colon in your bot token (for 9172594614:AA… it is 9172594614). Save. The relay refuses calls for any other bot.
  5. Copy the Worker's address, for example https://patchwise-telegram.<you>.workers.dev.
  6. In the Patchwise Space settings, add the variable FPT_TELEGRAM_API_BASE with that address, then restart the Space.

What the relay does and doesn't do

  • It forwards only the Bot API methods Patchwise uses (getMe, getUpdates, sendMessage, editMessageText, editMessageReplyMarkup, answerCallbackQuery, deleteWebhook), and only for your bot.
  • It stores nothing and logs nothing. It is about 30 lines; read it before you deploy it.
  • The bot token still travels in the request path, as Telegram requires. The relay runs in your own Cloudflare account, so the only party that sees it is your Worker, which the code shows does nothing with it.

On Hugging Face Spaces: use the Supabase relay

Hugging Face Spaces block api.telegram.org, and they also cut connections to *.workers.dev (the first request may get through, then every TLS handshake is dropped). supabase.co is reachable from Spaces, so for a Space use the Edge Function in supabase/index.ts, which has the same rules as the Worker:

  1. In your Supabase project, go to Edge Functions → Deploy a new function → Via Editor. Name it telegram-relay, paste supabase/index.ts, and select Deploy.
  2. In the function's details, turn off "Enforce JWT verification". The requests carry the bot token in their path, as Telegram requires, not a Supabase login.
  3. Go to Edge Functions → Secrets and add BOT_ID with the number before the colon in your bot token.
  4. In the Space, set FPT_TELEGRAM_API_BASE=https://<project-ref>.supabase.co/functions/v1/telegram-relay and restart it.

The Space log then shows getUpdates … 200 OK through …supabase.co/functions/v1/telegram-relay/bot(hidden)/….