1) Create a Telegram bot
- Open Telegram and chat with
@BotFather. - Run
/newbotand follow prompts. - Copy the bot token (looks like
123456:ABCDEF...). - (Recommended) Set a bot username (used for the “Connect Telegram” link).
2) Configure environment variables
Add these to your environment (Docker:docker-compose.yml / production: your secret manager):
TELEGRAM_BOT_TOKENTELEGRAM_BOT_USERNAME(without the@)NEXT_PUBLIC_APP_URL(your public URL, used to compute the webhook URL)
.env (see env.example).
3) Set the Telegram webhook
Latch receives Telegram updates at:/api/telegram/webhook
Use the provided helper script:
setWebhook API and prints the webhook info.
Local development note
Telegram requires a publicly reachable HTTPS URL for webhooks. For local dev, use something like a tunnel (ngrok/cloudflared) and pass that URL into the script, then set:NEXT_PUBLIC_APP_URLto the same tunnel URL (so dashboard links match)
4) Link your user account in the dashboard
- Start Latch and open the dashboard.
- Go to Settings.
- Click “Connect Telegram”.
- Telegram will open a link to your bot with a
starttoken. - Press Start in the bot.
Troubleshooting
“Telegram bot not configured”
- Ensure
TELEGRAM_BOT_USERNAMEis set in the app environment.
“TELEGRAM_BOT_TOKEN not configured”
- Ensure
TELEGRAM_BOT_TOKENis set in the app environment.
Webhook seems set, but nothing arrives
- Confirm the webhook URL in Telegram matches your public base URL +
/api/telegram/webhook. - Check app logs for webhook errors.
- Ensure your deployment allows POSTs to
/api/telegram/webhook.