opencode-router
v0.11.126
Published
opencode-router: Slack + Telegram bridge + directory routing for a running opencode server
Maintainers
Readme
opencode-router
Simple Slack + Telegram bridge + directory router for a running opencode server.
Runtime requirement: Bun 1.3+ (bun --version).
Install + Run
One-command install (recommended):
curl -fsSL https://raw.githubusercontent.com/different-ai/openwork/dev/packages/opencode-router/install.sh | bashInstall from npm:
npm install -g opencode-routerQuick run without global install:
npx --yes opencode-router --helpThen configure identities and start.
- One-command setup (installs deps, builds, creates
.envif missing):
pnpm -C packages/opencode-router setup- (Optional) Fill in
packages/opencode-router/.env(see.env.example).
Required:
OPENCODE_URLOPENCODE_DIRECTORY
Recommended:
OPENCODE_SERVER_USERNAMEOPENCODE_SERVER_PASSWORD
- Run the router:
opencode-router startTelegram
Telegram support is configured via identities. You can either:
- Use env vars for a single bot:
TELEGRAM_BOT_TOKEN=...- Or add multiple bots to the config file (
opencode-router.json) using the CLI:
- Or add multiple bots to the config file (
opencode-router telegram add <token> --id default
opencode-router telegram listImportant for direct sends and bindings:
- Telegram targets must use numeric
chat_idvalues. @usernamevalues are not valid directpeerIdtargets for router sends.- If a user has not started a chat with the bot yet, Telegram may return
chat not found. - Private Telegram identities can require first-chat pairing with
/pair <code>before commands are accepted.
Slack (Socket Mode)
Slack support uses Socket Mode and replies in threads when @mentioned in channels.
- Create a Slack app.
- Enable Socket Mode and generate an app token (
xapp-...). - Add bot token scopes:
chat:writeapp_mentions:readim:history
- Subscribe to events (bot events):
app_mentionmessage.im
- Set env vars (or save via
opencode-router slack add ...):SLACK_BOT_TOKEN=xoxb-...SLACK_APP_TOKEN=xapp-...SLACK_ENABLED=true
To add multiple Slack apps:
opencode-router slack add <xoxb> <xapp> --id default
opencode-router slack listIdentity-Scoped Routing
The router routes messages based on (channel, identityId, peerId) -> directory bindings.
opencode-router bindings set --channel telegram --identity default --peer <chatId> --dir /path/to/workdir
opencode-router bindings listHealth Server (Local HTTP)
The router can expose a small local HTTP server for health/config and simple message dispatch.
OPENCODE_ROUTER_HEALTH_PORTcontrols the port (OpenWork defaults to a random free port when usingopenwork).PORTis also accepted as a convenience if the above are unset.OPENCODE_ROUTER_HEALTH_HOSTcontrols bind host (default:127.0.0.1).
Send a message to all peers bound to a directory:
curl -sS "http://127.0.0.1:${OPENCODE_ROUTER_HEALTH_PORT:-3005}/send" \
-H 'Content-Type: application/json' \
-d '{"channel":"telegram","directory":"/path/to/workdir","text":"hello"}'Commands
opencode-router start
opencode-router status
opencode-router telegram list
opencode-router telegram add <token> --id default
opencode-router slack list
opencode-router slack add <xoxb> <xapp> --id default
opencode-router bindings list
opencode-router bindings set --channel telegram --identity default --peer <chatId> --dir /path/to/workdirDefaults
- SQLite at
~/.openwork/opencode-router/opencode-router.dbunless overridden. - Config stored at
~/.openwork/opencode-router/opencode-router.json(created byopencode-routerorpnpm -C packages/opencode-router setup). - Group chats are disabled unless
GROUPS_ENABLED=true.
Tests
test:smoke requires a running opencode server (default: http://127.0.0.1:4096).
opencode serve --port 4096 --hostname 127.0.0.1
pnpm -C packages/opencode-router test:smokeOther test suites:
pnpm -C packages/opencode-router test:unit
pnpm -C packages/opencode-router test:cli
pnpm -C packages/opencode-router test:npx