Skip to content

feat(server): Add messageThreadId handling in super groups for Telegram notifications#5409

Open
AliArtukov wants to merge 5 commits into
codecentric:masterfrom
AliArtukov:patch-1
Open

feat(server): Add messageThreadId handling in super groups for Telegram notifications#5409
AliArtukov wants to merge 5 commits into
codecentric:masterfrom
AliArtukov:patch-1

Conversation

@AliArtukov
Copy link
Copy Markdown

No description provided.

Add messageThreadId for sending alerts to specific topic of telegram group.
Updated messageThreadId to default to '0' and removed nullable annotations.
@AliArtukov AliArtukov requested a review from a team as a code owner June 2, 2026 11:43
@AliArtukov
Copy link
Copy Markdown
Author

Hi guys.
This PR adds support for sending Telegram notifications to specific topics in Telegram supergroups by introducing a new configuration attribute: messageThreadId.

Changes

  • Added new attribute: messageThreadId
  • The attribute value is used to populate the message_thread_id parameter for every Telegram message sent
  • Default value is set to 0

Why

Telegram supergroups support topic-based discussions, where messages can be posted into specific topics using the message_thread_id parameter. Without this parameter, notifications cannot be routed to dedicated topics.

Backward Compatibility

  • Default value 0 preserves existing behavior and supports posting to the default General topic in supergroups
  • For regular groups and private chats, including message_thread_id does not break message delivery
  • Existing configurations continue to work without changes

Use Case

This allows users to route notifications into dedicated topics inside Telegram supergroups (for example, separate topics for environments, services, or alert categories and our company is real case).

* Unique identifier for the target topic of the target super group
* 0 is an ID of general topic
*/
private String messageThreadId = "0";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

According to https://core.telegram.org/bots/api, this should be an Integer and not a String.

Moreover, I can't find anywhere stated that 0 is the default value. On the contrary, many implementations use 1 instead.

Finally, the parameter is optional, so not passing it at all if not provided is way safer than relying on some not really documented default value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree with you.
Currently changed attribute type to Integer and added message_thread_id to request param.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The way you changed the things may break.

If no value is set it may either fail with NPE (if toString is called on it) or pass null as value (if valueOf is called with it).
Both the cases are wrong.

/**
* Unique identifier for the target topic of the target super group
*/
private Integer messageThreadId;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please mark it with @Nullable for consistency.

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