Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public class TelegramNotifier extends AbstractContentNotifier {
*/
@Nullable private String chatId;

/**
* 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.


/**
* The token identifying und authorizing your Telegram bot (e.g.
* `123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11`)
Expand Down Expand Up @@ -83,6 +89,7 @@ protected String buildUrl() {
private Map<String, Object> createMessage(InstanceEvent event, Instance instance) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("chat_id", this.chatId);
parameters.put("message_thread_id", this.messageThreadId);
parameters.put("parse_mode", this.parseMode);
parameters.put("disable_notification", this.disableNotify);
parameters.put("text", createContent(event, instance));
Expand Down Expand Up @@ -114,6 +121,14 @@ public void setChatId(@Nullable String chatId) {
this.chatId = chatId;
}

public String getMessageThreadId() {
return messageThreadId;
}

public void setMessageThreadId(String messageThreadId) {
this.messageThreadId = messageThreadId;
}

@Nullable public String getAuthToken() {
return authToken;
}
Expand Down