feat(channels): complete Telegram Managed DM flow and realtime sync (#288)#322
Conversation
Move FALLBACK_DEFINITIONS, STATUS_STYLES, and AUTH_MODE_LABELS from MessagingPanel into a shared module so both the settings panel and the upcoming Channels page can reuse them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…abilities Reusable UI primitives for the Channels page: status pill badge, credential form input, and capability chip list. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Shared hook that loads channel definitions and status from the core RPC, falls back to local definitions, and syncs Redux state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tab bar component showing Web / Telegram / Discord with connection status badges and active route summary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…flow Channel-specific config panels with per-auth-mode credential fields, connect/disconnect, status badges, and error handling. TelegramConfig includes the managed DM deep link initiation flow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ChannelConfigPanel switches between Telegram/Discord/Web configs based on selection. WebChannelConfig shows a simple always-connected card. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Top-level /channels page with ChannelSelector + ChannelConfigPanel. Updates sidebar nav to point to /channels instead of /settings/messaging. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…onents Replace inline loading logic with useChannelDefinitions hook, inline status badges with ChannelStatusBadge, and inline capability chips with ChannelCapabilities. Reduces duplication with the new Channels page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdded a managed DM connection flow for Telegram authentication. Implemented Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TelegramConfig as TelegramConfig
participant ManagedDmApi as managedDmApi
participant Backend as Backend
participant TelegramDeepLink as Telegram Deep Link
participant SocketService as Socket Service
User->>TelegramConfig: Click Connect (Managed DM)
TelegramConfig->>ManagedDmApi: initiateManagedDm()
ManagedDmApi->>Backend: POST /telegram/managed-dm/initiate
Backend-->>ManagedDmApi: {token, deepLink, expiresAt}
ManagedDmApi-->>TelegramConfig: {token, deepLink, expiresAt}
TelegramConfig->>TelegramDeepLink: openUrl(deepLink)
User->>TelegramDeepLink: Complete verification
TelegramConfig->>ManagedDmApi: pollManagedDmStatusUntilVerified(token, {signal})
loop Poll until verified (interval: 3s, timeout: 5min)
ManagedDmApi->>Backend: GET /telegram/managed-dm/status/{token}
alt Verified
Backend-->>ManagedDmApi: {verified: true, telegramUsername}
ManagedDmApi-->>TelegramConfig: {verified: true, ...}
else Not yet verified
Backend-->>ManagedDmApi: {verified: false}
ManagedDmApi->>ManagedDmApi: Sleep 3s
else Timeout/Error
ManagedDmApi-->>TelegramConfig: null
end
end
Backend->>SocketService: channel:managed-dm-verified event
SocketService->>SocketService: upsertChannelConnection(telegram, managed_dm, connected)
TelegramConfig->>TelegramConfig: Update UI: Connected
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
app/src/services/api/__tests__/managedDmApi.test.ts (1)
30-39: Good polling test, but consider adding timeout and abort coverage.The test validates the happy path where polling succeeds on the second attempt. Consider adding tests for:
- Timeout expiration (returns
null)- AbortSignal cancellation (returns
nullearly)Example test for timeout behavior
it('returns null when polling times out', async () => { apiClient.get.mockResolvedValue({ data: { verified: false, telegramUsername: null } }); await expect( managedDmApi.pollManagedDmStatusUntilVerified('dm-token', { intervalMs: 10, timeoutMs: 25 }) ).resolves.toBeNull(); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/src/services/api/__tests__/managedDmApi.test.ts` around lines 30 - 39, Add unit tests for pollManagedDmStatusUntilVerified to cover timeout and AbortSignal cancellation: create one test where apiClient.get always returns { verified: false } and call managedDmApi.pollManagedDmStatusUntilVerified with a short timeoutMs (e.g., intervalMs small, timeoutMs small) and assert it resolves to null; create another test that passes an AbortSignal which is aborted early and assert the function resolves to null immediately, using apiClient.get mocks and referencing managedDmApi.pollManagedDmStatusUntilVerified and apiClient.get to locate the code under test.app/src/services/api/managedDmApi.ts (1)
86-88: Consider adding debug logging for polling errors.The empty catch block silently swallows network errors during polling. While "best-effort polling" is the right strategy, adding debug logging would help diagnose issues in production:
Suggested enhancement
+import debug from 'debug'; +const log = debug('api:managedDm'); } catch { - // Best-effort polling: keep trying until timeout or cancellation. + // Best-effort polling: keep trying until timeout or cancellation. + log('poll attempt failed, retrying...'); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/src/services/api/managedDmApi.ts` around lines 86 - 88, The empty catch that follows the "Best-effort polling: keep trying until timeout or cancellation." comment should log caught errors at debug/trace level rather than silently swallow them; inside that catch in the polling routine, call the project's logger (e.g., logger.debug or this.logger.debug) and include the error object and minimal context (operation name, attempt count or timeout info) but keep the current behavior of not rethrowing so polling remains best-effort.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/src/services/api/__tests__/managedDmApi.test.ts`:
- Around line 30-39: Add unit tests for pollManagedDmStatusUntilVerified to
cover timeout and AbortSignal cancellation: create one test where apiClient.get
always returns { verified: false } and call
managedDmApi.pollManagedDmStatusUntilVerified with a short timeoutMs (e.g.,
intervalMs small, timeoutMs small) and assert it resolves to null; create
another test that passes an AbortSignal which is aborted early and assert the
function resolves to null immediately, using apiClient.get mocks and referencing
managedDmApi.pollManagedDmStatusUntilVerified and apiClient.get to locate the
code under test.
In `@app/src/services/api/managedDmApi.ts`:
- Around line 86-88: The empty catch that follows the "Best-effort polling: keep
trying until timeout or cancellation." comment should log caught errors at
debug/trace level rather than silently swallow them; inside that catch in the
polling routine, call the project's logger (e.g., logger.debug or
this.logger.debug) and include the error object and minimal context (operation
name, attempt count or timeout info) but keep the current behavior of not
rethrowing so polling remains best-effort.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5f8f0653-dc76-4ba5-8c97-be2b270439fb
📒 Files selected for processing (5)
app/src/components/channels/TelegramConfig.tsxapp/src/components/channels/__tests__/TelegramConfig.test.tsxapp/src/services/api/__tests__/managedDmApi.test.tsapp/src/services/api/managedDmApi.tsapp/src/services/socketService.ts
Summary
Problem
Solution
Submission Checklist
Impact
Related
Summary by CodeRabbit
Release Notes
New Features
Tests