Add Carapace to Telegram (webhook mode)

Outcome

Connect Carapace to Telegram for inbound and outbound bot messaging using a webhook endpoint.

Prerequisites

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 cara

Optional local auth check:

curl -H "Authorization: Bearer ${CARAPACE_GATEWAY_TOKEN}" http://127.0.0.1:18789/health

Register 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

  1. Send a message to your bot in Telegram.
  2. Confirm Carapace receives it and returns a reply.

Common failures and fixes

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.

Need a recipe for your use case?

Tell us what outcome you want and we can prioritize a walkthrough.

Request a cookbook recipe