Skip to content

feat: add Telegram topicId for forum group support notification#2405

Merged
yohamta0 merged 1 commit into
dagucloud:mainfrom
dodyirawan85:feat/telegram-topic-id
Jul 23, 2026
Merged

feat: add Telegram topicId for forum group support notification#2405
yohamta0 merged 1 commit into
dagucloud:mainfrom
dodyirawan85:feat/telegram-topic-id

Conversation

@dodyirawan85

@dodyirawan85 dodyirawan85 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Add optional topicId field to Telegram notification targets for forum group message thread support.

Changes

  • Add topicId to Telegram target model and storage schemas
  • Add API request/response mapping for topicId in notification channels and targets
  • Add message_thread_id to Telegram send payload when topicId is set
  • Add frontend type, draft, and form input for topicId
  • Update tests for store round-trip and service send

Checklist

  • Code follows the project style guidelines
  • Self-review of the code has been performed
  • Tests have been added or updated as needed
  • Documentation has been updated as needed
  • Changes have been tested locally

Summary by cubic

Adds optional topicId to Telegram notification targets and channels to post into specific forum topics. When set to a positive integer, we send Telegram’s message_thread_id so messages go to the selected thread.

  • New Features
    • Add topicId across Telegram models, storage, and public API (server and UI schemas); map in api/v1 channel/target requests and responses; UI form/drafts include it.
    • Validate topicId as a trimmed, positive integer during normalize; reject invalid values with tests for bad inputs.
    • Include message_thread_id in send payload when valid; update storage round‑trip and send tests to cover thread ID.

Written for commit ee41ae8. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added optional Telegram Topic ID support for forum groups.
    • Configure a message thread when creating or editing Telegram notification targets.
    • Topic IDs are displayed in notification details and preserved across saves.
    • Telegram notifications are delivered to the specified topic when configured.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Telegram notification targets now support an optional topic ID across OpenAPI contracts, generated API types, internal models, file persistence, frontend mappings, notification drafts, and the Telegram sendMessage payload. The UI exposes a topic field for forum groups.

Telegram topic support

Layer / File(s) Summary
Extend Telegram target contracts
api/v1/api.yaml, api/v1/api.gen.go, ui/src/api/v1/schema.ts
Adds optional topicId fields to Telegram target input and output schemas and generated declarations.
Propagate topic IDs through models and storage
internal/notification/model.go, internal/persis/file/notification/store.go, internal/persis/file/notification/store_test.go
Carries TopicID through internal/public models and persists it in notification storage with retrieval assertions.
Map and deliver Telegram topic IDs
internal/service/frontend/api/v1/notifications.go, internal/service/notification/service.go, internal/service/notification/service_test.go
Maps topic IDs between API and internal targets and conditionally sends message_thread_id to Telegram.
Edit and serialize topic IDs in the UI
ui/src/features/dags/components/dag-details/notifications/notificationDrafts.ts, ui/src/features/dags/components/dag-details/notifications/NotificationSections.tsx
Adds topic ID draft state, form input, API loading, and trimmed optional serialization.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NotificationUI
  participant NotificationAPI
  participant NotificationService
  participant TelegramBotAPI
  NotificationUI->>NotificationAPI: submit optional topicId
  NotificationAPI->>NotificationService: map topicId to TopicID
  NotificationService->>TelegramBotAPI: send message_thread_id when configured
  TelegramBotAPI-->>NotificationService: return delivery response
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: adding Telegram topicId support for forum group threads.
Description check ✅ Passed The description matches the template with Summary, Changes, and Checklist sections filled out; Related Issues is optional and may be omitted.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/notification/service.go`:
- Around line 1336-1343: Update the Telegram payload construction around the
payload map and json.Marshal call so message_thread_id is serialized as a JSON
number rather than a string. Replace the all-string payload with a typed
structure or parse target.Telegram.TopicID into an integer before marshaling,
while preserving omission when TopicID is empty; update the related test
assertion to expect a numeric JSON value.

In
`@ui/src/features/dags/components/dag-details/notifications/NotificationSections.tsx`:
- Around line 325-333: Add an accessible name to the Topic ID Input in
NotificationSections by setting aria-label to “Telegram topic ID” or associating
it with a visible label, while preserving its existing value and onChange
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6b71d550-0fb0-4bb6-9686-6104e7a084fe

📥 Commits

Reviewing files that changed from the base of the PR and between 3fca3b5 and 9e15dd9.

📒 Files selected for processing (11)
  • api/v1/api.gen.go
  • api/v1/api.yaml
  • internal/notification/model.go
  • internal/persis/file/notification/store.go
  • internal/persis/file/notification/store_test.go
  • internal/service/frontend/api/v1/notifications.go
  • internal/service/notification/service.go
  • internal/service/notification/service_test.go
  • ui/src/api/v1/schema.ts
  • ui/src/features/dags/components/dag-details/notifications/NotificationSections.tsx
  • ui/src/features/dags/components/dag-details/notifications/notificationDrafts.ts

Comment on lines +1336 to +1343
payload := map[string]string{
"chat_id": target.Telegram.ChatID,
"text": messageForEvents(target.Telegram.MessageTemplate, events, s.publicURL()),
})
}
if target.Telegram.TopicID != "" {
payload["message_thread_id"] = target.Telegram.TopicID
}
body, err := json.Marshal(payload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

if rg -n -F 'map[string]string' \
  internal/service/notification/service.go; then
  echo "Telegram payload still forces message_thread_id to a JSON string" >&2
  exit 1
fi

python3 - <<'PY'
import json

payload = json.loads(
    '{"chat_id":"12345","text":"test","message_thread_id":67890}'
)
assert isinstance(payload["message_thread_id"], int)
PY

Repository: dagucloud/dagu

Length of output: 450


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '\n== service.go around payload ==\n'
sed -n '1300,1365p' internal/service/notification/service.go

printf '\n== tests mentioning Telegram notification payload ==\n'
rg -n -A 3 -B 3 'message_thread_id|TopicID|sendMessage|Telegram' internal/service -g '*_test.go'

Repository: dagucloud/dagu

Length of output: 4803


🌐 Web query:

Telegram Bot API sendMessage message_thread_id Integer JSON string accepted

💡 Result:

In the Telegram Bot API, the message_thread_id parameter used in methods like sendMessage is defined as an Integer [1][2]. When sending data via JSON (such as in an HTTP POST request with application/json), this value should be represented as a standard JSON number (e.g., {"message_thread_id": 123}), not as a string [1][2]. While some Telegram client libraries may handle type conversion automatically, the official API specification strictly requires the Integer type [1][2][3].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '\n== notification service references ==\n'
rg -n -A 2 -B 2 'message_thread_id|TopicID|sendMessage|json.Marshal\(map\[string\]string\)' internal/service/notification

printf '\n== tests in notification package ==\n'
rg -n -A 3 -B 3 'message_thread_id|TopicID|sendMessage|Telegram' internal/service/notification -g '*_test.go'

Repository: dagucloud/dagu

Length of output: 4341


Serialize message_thread_id as a number

payload is a map[string]string, so message_thread_id is sent as a JSON string. Telegram’s sendMessage API expects this field as an integer, so topic replies can fail. Use a typed payload (or parse TopicID before marshaling) and update the test to assert the JSON number.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/service/notification/service.go` around lines 1336 - 1343, Update
the Telegram payload construction around the payload map and json.Marshal call
so message_thread_id is serialized as a JSON number rather than a string.
Replace the all-string payload with a typed structure or parse
target.Telegram.TopicID into an integer before marshaling, while preserving
omission when TopicID is empty; update the related test assertion to expect a
numeric JSON value.

Comment on lines +325 to +333
<Input
value={draft.telegram.topicId}
placeholder="Topic ID (optional, for forum groups)"
onChange={(event) =>
update({
telegram: { ...draft.telegram, topicId: event.target.value },
})
}
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add an accessible name to the Topic ID field.

This new input relies only on placeholder text, which is not a durable label for screen-reader users. Add aria-label="Telegram topic ID" or a visible <label>.

Proposed fix
       <Input
+        aria-label="Telegram topic ID"
         value={draft.telegram.topicId}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Input
value={draft.telegram.topicId}
placeholder="Topic ID (optional, for forum groups)"
onChange={(event) =>
update({
telegram: { ...draft.telegram, topicId: event.target.value },
})
}
/>
<Input
aria-label="Telegram topic ID"
value={draft.telegram.topicId}
placeholder="Topic ID (optional, for forum groups)"
onChange={(event) =>
update({
telegram: { ...draft.telegram, topicId: event.target.value },
})
}
/>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@ui/src/features/dags/components/dag-details/notifications/NotificationSections.tsx`
around lines 325 - 333, Add an accessible name to the Topic ID Input in
NotificationSections by setting aria-label to “Telegram topic ID” or associating
it with a visible label, while preserving its existing value and onChange
behavior.

@dodyirawan85
dodyirawan85 force-pushed the feat/telegram-topic-id branch from 9e15dd9 to 57af24f Compare July 22, 2026 13:21
}
if target.Telegram.TopicID != "" {
if topicID, err := strconv.Atoi(target.Telegram.TopicID); err == nil {
payload["message_thread_id"] = topicID

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return an error? An invalid TopicID sends to the default topic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the validation on notification channels input, instead of checking here

@dodyirawan85
dodyirawan85 force-pushed the feat/telegram-topic-id branch from 57af24f to ee41ae8 Compare July 23, 2026 06:56

@yohamta0 yohamta0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀🚀🚀 Thanks for adding topicId support for Telegram notification!

@yohamta0
yohamta0 merged commit f3a5175 into dagucloud:main Jul 23, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants