Add Carapace to Telegram (webhook mode)
Outcome
Connect Carapace to Telegram for inbound and outbound bot messaging using a webhook endpoint.
Prerequisites
carainstalled.ANTHROPIC_API_KEYorOPENAI_API_KEY.- Telegram bot token from BotFather
(
TELEGRAM_BOT_TOKEN). - Public HTTPS URL that can reach your Carapace server.
- Webhook secret token (
TELEGRAM_WEBHOOK_SECRET).
1) Create config
Generate a gateway token:
export CARAPACE_GATEWAY_TOKEN="$(openssl rand -hex 32)"Windows (PowerShell) alternative:
$bytes = [byte[]]::new(32)
[System.Security.Cryptography.RandomNumberGenerator]::Fill($bytes)
$env:CARAPACE_GATEWAY_TOKEN = [System.BitConverter]::ToString($bytes).Replace('-', '').ToLower(){
"gateway": {
"bind": "all",
"port": 18789,
"auth": {
"mode": "token",
"token": "${CARAPACE_GATEWAY_TOKEN}"
}
},
"anthropic": {
"apiKey": "${ANTHROPIC_API_KEY}"
},
"telegram": {
"botToken": "${TELEGRAM_BOT_TOKEN}",
"webhookSecret": "${TELEGRAM_WEBHOOK_SECRET}"
}
}
2) Run commands
Start Carapace:
CARAPACE_CONFIG_PATH=./carapace.json5 caraOptional local auth check:
curl -H "Authorization: Bearer ${CARAPACE_GATEWAY_TOKEN}" http://127.0.0.1:18789/healthRegister webhook with Telegram:
curl -sS \
-X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook" \
-d "url=https://YOUR_PUBLIC_HOST/channels/telegram/webhook" \
-d "secret_token=${TELEGRAM_WEBHOOK_SECRET}"Check webhook status:
curl -sS "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getWebhookInfo"3) Verify
- Send a message to your bot in Telegram.
- Confirm Carapace receives it and returns a reply.
Common failures and fixes
- Symptom: Telegram webhook set succeeds, but inbound messages do not
arrive.
- Fix: Verify public HTTPS reachability to
/channels/telegram/webhook.
- Fix: Verify public HTTPS reachability to
- Symptom: Inbound requests return unauthorized/ignored.
- Fix: Ensure
webhookSecretmatches Telegramsecret_token.
- Fix: Ensure
- Symptom: Local status or health checks return
401 Unauthorized.- Fix: Use
Authorization: Bearer ${CARAPACE_GATEWAY_TOKEN}and confirm it matchesgateway.auth.token.
- Fix: Use
- Symptom: Telegram shows webhook error status.
- Fix: Check
getWebhookInfolast error message and Carapace logs.
- Fix: Check
Note
Current Telegram inbound support is webhook-based. Local-only inbound
without a public webhook requires long-polling support, which is
planned. When gateway.bind is all, keep
gateway.auth enabled and use a strong token.