This guide walks you through running the Commands.com Gateway locally and pairing a Telegram bot with Shep end-to-end.
Telegram bot webhook
│
▼
cloudflared / ngrok ──► Gateway (localhost:8080) ◄──ws── Shep daemon
(shep _serve)
cloudflared or ngrok.api.telegram.org for
replies and notifications — the gateway tunnel is only for inbound.cloudflared (brew install cloudflared) or ngrokThe Gateway is a separate project — the .env.example below belongs to that
repository, not to Shep. (Shep itself has no .env file: its settings live in
SQLite and are edited with shep settings ….)
git clone https://github.com/Commands-com/gateway.git
cd gateway
cp .env.example .env
cat >> .env <<EOF
JWT_SIGNING_KEY=$(openssl rand -base64 48)
AUTH_MODE=demo
OAUTH_DEFAULT_CLIENT_ID=commands-desktop-public
REDIRECT_ALLOWLIST=http://localhost:61696/callback,urn:ietf:wg:oauth:2.0:oob
EOF
go run ./cmd/server
Verify:
curl http://localhost:8080/healthz
# {"status":"ok"}
Open http://localhost:8080/console to see devices, sessions, and integration routes.
Pick one. Both support WebSocket upgrades, which is required because the Gateway’s built-in console uses them.
cloudflared tunnel --url http://localhost:8080
# => Your quick tunnel: https://random-slug.trycloudflare.com
ngrok http 8080
# => https://abcd-1234.ngrok-free.app
Export the URL for the next steps:
export SHEP_GATEWAY_PUBLIC_URL=https://random-slug.trycloudflare.com
Shep needs the bot token to make outbound sendMessage calls (the Gateway
does not proxy outbound traffic).
export SHEP_TELEGRAM_BOT_TOKEN=123456:ABCDEFG-your-token-here
_serve reads this from process.env when constructing the messaging
service — see container.ts.
Start the web UI so you can use the pairing dialog (the CLI wizard works identically):
pnpm dev:web # http://localhost:3000
# or
shep ui # http://localhost:4050
Navigate to Settings → Messaging Remote Control:
http://localhost:8080 (not the public URL — the daemon
connects to the Gateway on localhost)A dialog opens showing:
http://localhost:8080/integrations/{route_id}/{route_token}Because the daemon sees the Gateway on localhost but Telegram needs a public URL, rewrite the webhook URL host to your tunnel domain:
Copy the route_id and route_token out of the pairing dialog and build the
URL yourself:
# From the pairing dialog's webhook URL
ROUTE_ID=...
ROUTE_TOKEN=...
WEBHOOK_URL="${SHEP_GATEWAY_PUBLIC_URL}/integrations/${ROUTE_ID}/${ROUTE_TOKEN}"
Set the Telegram webhook:
curl -X POST "https://api.telegram.org/bot${SHEP_TELEGRAM_BOT_TOKEN}/setWebhook" \
-d "url=${WEBHOOK_URL}"
# {"ok":true,"result":true,"description":"Webhook was set"}
Verify:
curl -s "https://api.telegram.org/bot${SHEP_TELEGRAM_BOT_TOKEN}/getWebhookInfo" | jq
shep _serve
# or during development:
pnpm dev:cli _serve
pnpm dev:web does not start the messaging service by default — it opens a
persistent WebSocket tunnel to the gateway, which is not something every
developer wants running on every dev-server start. Opt in explicitly:
SHEP_ENABLE_MESSAGING=1 pnpm dev:web
If messaging is not configured yet, the dev server logs
SHEP_ENABLE_MESSAGING=1 but messaging is not configured yet — pair a platform
in Settings first and carries on.
The daemon:
IGatewayClient and calls fetchAccessToken (demo mode uses
the commands-desktop-public client, no secret required).MessagingService with the fetched token + your bot token.Authorization: Bearer <token> on the
upgrade headers.tunnel.activate for each paired platform’s route.tunnel.request frames.In your Telegram bot chat, send the 6-digit code:
/pair 482913
The daemon’s MessagingService.handleTunnelRequest:
tunnel.request frameUpdate/pair <code> via parsePairCommandpendingPairingCode for Telegram in settingsConfirmMessagingPairingUseCase → sets paired: true, stores your
chat IDThe web UI will show the row flip to Paired with your chat ID on the next render.
/list — list features
/status 42 — status of feature 42
/new add dark mode — create a new feature
/approve 42 — approve an agent run
/chat 42 — start an interactive agent relay for feature 42
<any text while relay> — forwarded to the agent as a user message
/end — end the active relay
/help — command reference
Replies come back through sendMessage directly to your chat.
/chat <feature_id> attaches your Telegram chat to a feature’s interactive
session. While a relay is active:
/end tears down the subscription and stops forwarding.The daemon will start a new session if none exists, and queue messages if the session is still booting. You can drive an entire conversation from Telegram without touching the web UI.
The daemon needs your Telegram bot token to call sendMessage. You have
two options:
~/.shep/data, column
messaging_telegram_bot_token) and loaded by DI on daemon start. Note that
it is stored as plaintext in that column — protect the file accordingly.SHEP_TELEGRAM_BOT_TOKEN before running shep _serve. Settings takes
precedence when both are set
(messagingConfig.telegram?.botToken ?? process.env.SHEP_TELEGRAM_BOT_TOKEN).The same pattern applies to the CLI wizard: after /confirm pairing, it
prompts for the bot token and stores it in settings via
UpdateSettingsUseCase.
Tunnel refuses the upgrade with 401. The daemon’s OAuth token fetch
failed. Check that OAUTH_DEFAULT_CLIENT_ID=commands-desktop-public is set
on the Gateway and that gatewayClientId in Shep settings matches (or is
unset — it defaults to the same value).
/pair <code> gets “Invalid or expired pairing code”. Codes expire
after 10 minutes. Start a new pairing from the UI.
Webhook POSTs return 503. Either the daemon isn’t running, the tunnel
is disconnected, or the route hasn’t been activated yet. Check
adapter.isRouteActivated(routeId) — in logs you’ll see tunnel.activate
followed by tunnel.activate.result ok:true when healthy.
Notifications don’t arrive in Telegram. Check that
SHEP_TELEGRAM_BOT_TOKEN is set in the environment the daemon runs in —
this is separate from the Gateway token. The TelegramMessageSender will
silently no-op if the bot token is missing.
/pair and /chat commands from
WhatsApp but cannot reply. Replies would need a dedicated WhatsApp Cloud
API client (separate Meta verified app + access token). Use Telegram
end-to-end for now.