feat: add auto-start, AFK mode, and comprehensive cross-platform setup

Major Features:
- Auto-start: MCP server now automatically starts Telegram bridge on demand
- AFK Mode: Toggle notifications on/off with /afk slash command
- New telegram_toggle_afk MCP tool for controlling notification state
- Dynamic enable/disable via new /toggle and /status API endpoints

MCP Server Improvements:
- Auto-detects if bridge is running and starts it automatically
- Monitors bridge process health and logs output
- Clean shutdown handling for both MCP server and bridge
- Process spawning with proper environment variable passing

Telegram Bridge Updates:
- Runtime toggle for ENABLED state (was previously static)
- POST /toggle endpoint to toggle notifications with Telegram confirmation
- GET /status endpoint to check current notification state
- Telegram messages sent when state changes (🟢/🔴 indicators)

Documentation:
- Cross-platform setup instructions (Mac, Linux, Windows)
- Claude Code CLI setup guide with claude mcp add commands
- Global vs project-specific MCP configuration explained
- Troubleshooting section for fixing configuration scope issues
- Complete AFK mode usage documentation
- All new API endpoints documented

Slash Commands:
- Created /afk command in .claude/commands/afk.md
- Available in both InnerVoice and ESO-MCP projects

Files Changed:
- src/mcp-server.ts: Auto-start logic and telegram_toggle_afk tool
- src/index.ts: Dynamic ENABLED toggle and new API endpoints
- README.md: Comprehensive setup and troubleshooting guide
- mcp-config.json: Updated with correct absolute path
- .claude/commands/afk.md: New slash command for AFK mode

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
RichardDillman
2025-11-23 14:15:46 -05:00
parent c4cfcf6eb8
commit c45fe4d509
5 changed files with 338 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ const bot = new Telegraf(process.env.TELEGRAM_BOT_TOKEN!);
const app = express();
const PORT = parseInt(process.env.PORT || '3456');
const HOST = process.env.HOST || 'localhost';
const ENABLED = process.env.ENABLED !== 'false';
let ENABLED = process.env.ENABLED !== 'false'; // Now mutable for runtime toggling
let chatId: string | null = process.env.TELEGRAM_CHAT_ID || null;
const envPath = path.join(process.cwd(), '.env');
@@ -256,6 +256,40 @@ app.get('/health', (req, res) => {
});
});
// Toggle enabled state
app.post('/toggle', async (req, res) => {
const previousState = ENABLED;
ENABLED = !ENABLED;
const statusMessage = ENABLED
? '🟢 InnerVoice notifications ENABLED - You will receive messages'
: '🔴 InnerVoice notifications DISABLED - Messages paused';
// Notify via Telegram if chat ID is set
if (chatId) {
try {
await bot.telegram.sendMessage(chatId, statusMessage, { parse_mode: 'Markdown' });
} catch (error) {
console.error('Failed to send toggle notification:', error);
}
}
res.json({
success: true,
enabled: ENABLED,
previousState,
message: statusMessage
});
});
// Get current enabled state
app.get('/status', (req, res) => {
res.json({
enabled: ENABLED,
message: ENABLED ? 'Notifications are ON' : 'Notifications are OFF (AFK mode)'
});
});
// Start bot
bot.launch().then(() => {
console.log('🤖 Telegram bot started');