| .. | ||
| lib | ||
| .gitignore | ||
| bun.lock | ||
| notify.ts | ||
| package.json | ||
| README.md | ||
| telegram-notify.ts | ||
| tsconfig.json | ||
OpenCode Telegram Plugin
Simple Telegram notifications for OpenCode sessions.
Files
telegram-notify.ts- OpenCode plugin for session eventsnotify.ts- Simple system notification plugin (usessay)telegram-bot.ts- Telegram bot implementationpackage.json- Dependencies and scriptstsconfig.json- TypeScript configuration
Features
- 🕐 Session idle detection and notifications
- 📱 Telegram messages for session events
- 📝 Last message capture and forwarding
- 🚀 Session start/end tracking
- ✅ Task completion notifications
- ❌ Error notifications
- 🛡️ Automatic .env file loading
- 💬 Commands:
/send-last,/send-to-phone
Usage
As OpenCode Plugin
// The plugin automatically responds to session events
import { TelegramNotify } from "./telegram-notify.js"
Commands you can use in OpenCode:
/send-last- Send the last message to Telegram/send-to-phone- Send the last message to your phone/last- Same as/send-last/phone- Same as/send-to-phone
Standalone Bot
# Run the bot directly
bun telegram-bot.ts
# Test the plugin
bun telegram-notify.ts
Setup
-
Create a Telegram Bot
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Save the bot token
-
Get Your Chat ID
- Start a chat with your bot
- Send a message to the bot
- Visit:
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates - Find your
chat_idin the response
-
Configure Environment Variables
export TELEGRAM_BOT_TOKEN="your_bot_token_here" export TELEGRAM_CHAT_ID="your_chat_id_here" -
Or Update Configuration Edit
.opencode/plugin/telegram-config.json:{ "telegramIdle": { "enabled": true, "botToken": "your_bot_token_here", "chatId": "your_chat_id_here" } }
Usage
The plugin automatically initializes when OpenCode starts. It will:
- Monitor session activity
- Send idle notifications after 5 minutes of inactivity
- Send resume notifications when activity resumes
- Clean up resources on session end
Customization
You can customize the plugin behavior by modifying the configuration:
idleTimeout: Time in milliseconds before considering session idlecheckInterval: How often to check for idle statemessages: Customize notification messages
Integration with OpenCode
To integrate this plugin with OpenCode's event system, you would need to:
- Hook into OpenCode's activity tracking events
- Call
handleActivity()when user interacts with OpenCode - Call
init()when OpenCode session starts - Call
cleanup()when OpenCode session ends
Testing
Test the plugin independently:
node .opencode/plugin/telegram-idle.js
Troubleshooting
- "Bot token not configured": Set
TELEGRAM_BOT_TOKENenvironment variable - "Chat ID not configured": Set
TELEGRAM_CHAT_IDenvironment variable - "Failed to send message": Check bot token and chat ID are correct
- No notifications: Ensure bot is started and chat is active