Get OpenCode notifications via Telegram.
Disclaimer: This project is not affiliated with, endorsed by, or sponsored by OpenCode, SST, or any of their affiliates. OpenCode is a trademark of SST.
- π Task Completion Notifications: Get notified when OpenCode agent finishes tasks
- β Question Alerts: Receive notifications when OpenCode asks questions
- π Secure: Whitelist-based user access control
- π¬ Simple Setup: Automatic chat discovery and configuration
- Node.js 18+
- OpenCode CLI installed
- Telegram Bot (from @BotFather)
- Talk to @BotFather
- Create a new bot with
/newbot - Save the bot token
- Open your bot in Telegram
- Tap Start
- Send any message to establish the chat
- Send any message to @userinfobot
- Save your numeric user ID
Clone and build:
git clone https://github.com/YOUR_USERNAME/opencoder-telegram-plugin.git
cd opencoder-telegram-plugin/plugin
npm install
npm run buildCreate .env file in the plugin directory:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_ALLOWED_USER_IDS=123456789,987654321
# Optional: Pre-configure your chat_id (or let the bot discover it automatically)
# TELEGRAM_CHAT_ID=your_chat_id_hereAdd to your ~/.config/opencode/opencode.json:
{
"plugins": [
{
"name": "telegram-notification",
"path": "/path/to/opencoder-telegram-plugin/plugin/dist/telegram-remote.js"
}
]
}Or copy the built file:
cp dist/telegram-remote.js ~/.config/opencode/plugin/Then reference it:
{
"plugins": [
{
"name": "telegram-notification",
"path": "~/.config/opencode/plugin/telegram-remote.js"
}
]
}- Start OpenCode with the plugin enabled
- Open your Telegram bot and send any message (e.g., "Hello")
- The bot will reply with your chat_id and confirm the connection
- You're ready to receive notifications!
The plugin automatically sends notifications to your Telegram chat when:
-
Agent finishes: When OpenCode completes a task, you'll receive a message like:
Agent has finished: [Session Title] -
Questions asked: When OpenCode needs clarification, you'll receive:
π [Session Title] β Questions: 1. [Question text]
If you prefer, add your chat_id to the .env file to skip the initial setup:
TELEGRAM_CHAT_ID=your_chat_id_hereYou can get your chat_id by messaging the bot once, or using @userinfobot.
- Only whitelisted user IDs can interact with the bot
- User whitelist is comma-separated in
.env - Non-whitelisted users are silently ignored
- Use a private chat with the bot
- Keep the bot token secret
- Only add trusted users to whitelist
- Review
.envfile permissions (should be readable only by you)
| Variable | Required | Description | Example |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
β | Bot token from @BotFather | 123456:ABC-DEF... |
TELEGRAM_ALLOWED_USER_IDS |
β | Comma-separated user IDs | 123456789,987654321 |
TELEGRAM_CHAT_ID |
β | Optional pre-configured chat ID | 123456789 |
{
"plugins": [
{
"name": "telegram-notification",
"path": "/absolute/path/to/telegram-remote.js"
}
]
}- Verify bot token is correct in
.env - Confirm your user ID is in the whitelist
- Ensure you've established a chat (send any message to the bot first)
- Check OpenCode logs for errors
- Make sure you're using a private chat (not a group)
- Send any message to the bot to trigger chat discovery
- If using
TELEGRAM_CHAT_IDin.env, verify the ID is correct
- Your user ID must be in
TELEGRAM_ALLOWED_USER_IDS - Check you copied the correct numeric ID (not username)
- Use @userinfobot to verify your user ID
plugin/
βββ src/
β βββ telegram-remote.ts # Main plugin entry
β βββ bot.ts # Grammy bot setup
β βββ config.ts # Environment config
β βββ events/ # Event handlers
β β βββ session-status.ts # Handles idle/active status
β β βββ session-updated.ts # Tracks session titles
β β βββ question-asked.ts # Forwards questions
β β βββ types.ts # TypeScript types
β β βββ index.ts
β βββ services/
β βββ session-title-service.ts # Session title storage
βββ dist/ # Built output
βββ package.json
βββ tsconfig.json
βββ tsup.config.ts
cd plugin
npm run build # Production build
npm run dev # Watch mode
npm run typecheck # Type checking only- Build the plugin
- Configure
.envwith test bot credentials - Point OpenCode to the built file
- Start OpenCode and message the bot to establish connection
- Trigger OpenCode tasks to test notifications
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Run
npm run lintandnpm run build - Submit a pull request
MIT