# Phase 4: Friendly Chat Names + Test Message for Bots **Status:** ⬜ Not Started **Parent plan:** [PLAN.md](./PLAN.md) **Domain:** fullstack ## Objective Two Telegram UX improvements: (a) show friendly chat names instead of raw IDs on target cards, (b) add a "Send Test Message" button to each chat item on the bots page. ## Tasks ### 4a: Friendly Chat Names on Target Cards - [ ] Task 1: Update GET /api/targets in targets.py to resolve chat_id → friendly name by looking up TelegramChat table (match on bot token's bot_id + chat_id) - [ ] Task 2: Include `chat_name` field in target API response alongside chat_id - [ ] Task 3: Update target cards in targets/+page.svelte to display "Chat Name (chat_id)" instead of raw chat_id ### 4b: Test Message Button for Bot Chats - [ ] Task 4: Add POST /api/telegram-bots/{bot_id}/chats/{chat_id}/test endpoint in telegram_bots.py that sends a simple test message via the bot - [ ] Task 5: Add "Send Test" button to each chat item in telegram-bots/+page.svelte with loading/success/error feedback - [ ] Task 6: Handle edge cases (bot can't reach chat, chat deleted, etc.) with proper error messages ## Files to Modify/Create - `packages/server/src/notify_bridge_server/api/targets.py` — resolve chat names - `packages/server/src/notify_bridge_server/api/telegram_bots.py` — test message endpoint - `frontend/src/routes/targets/+page.svelte` — display friendly names - `frontend/src/routes/telegram-bots/+page.svelte` — test message button ## Acceptance Criteria - Target cards show "Chat Title (chat_id)" for telegram targets where chat name is known - Falls back to just chat_id when no matching TelegramChat record exists - Test message button sends a simple "Test message from Notify Bridge" to the chat - Button shows loading state, then success/error feedback - Error messages are user-friendly (not raw API errors) ## Notes - TelegramChat stores: chat_id (string), title, chat_type, username, bot_id (FK) - NotificationTarget.config stores: bot_token, chat_id - To resolve: need to find TelegramBot by token → get bot_id → lookup TelegramChat by (bot_id, chat_id) - For test message: use TelegramClient directly with bot token from TelegramBot record - The test endpoint on targets already exists (POST /api/targets/{id}/test) — this is a NEW endpoint specifically for bot chat items ## Review Checklist - [ ] All tasks completed - [ ] Code follows project conventions - [ ] No unintended side effects - [ ] Build passes - [ ] Tests pass (new + existing) ## Handoff to Next Phase