alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Supported reply_to_message_id for Telegram topics.

Open VadimRezvov opened this issue 1 year ago • 24 comments

This PR brings support to sending messages to specific Telegram topic, see https://telegram.org/blog/topics-in-groups-collectible-usernames

Topic is identified by id of the first message in this topic. In order to find out the id of the first message in a topic, in the Telegram desktop client, right-click on the first message in the topic, select "Copy Message Link". Get a link like: https://t.me/c/1234567890/1234/1235 The second part of the link is the id of the first message in the topic: 1234

VadimRezvov avatar Oct 16 '23 21:10 VadimRezvov

Dear maintainers, I supported this for my project, but I think that it will be useful for Telegram users. If you have some comments, write me and I will definitely take them into account.

VadimRezvov avatar Oct 16 '23 22:10 VadimRezvov

+1

alexunderboots avatar Oct 23 '23 03:10 alexunderboots

Make some changes as the result of review. Replace reply_to_message_id with message_thread_id.

VadimRezvov avatar Nov 05 '23 21:11 VadimRezvov

Hi @gotjosh, just checking in on the status of this PR. Looking forward to any updates, as it seems quite useful. Thanks!

asonnleitner avatar Nov 24 '23 16:11 asonnleitner

@simonpasquier, @w0rm, @gotjosh Hello friends, could you please review this PR? Its will be very helpful for telegram users

iishabakaev avatar Dec 04 '23 15:12 iishabakaev

hello friends it will be so good if you review this PR, i need send alerts to my telegram thread

formorter avatar Dec 04 '23 15:12 formorter

Hi all, this very good function, @simonpasquier, @w0rm. @gotjosh please review it.

nicknamenotknown avatar Dec 04 '23 15:12 nicknamenotknown

@nicknamenotknown I'm not a reviewer or maintainer in this repository

sbueringer avatar Dec 04 '23 15:12 sbueringer

@nicknamenotknown I'm not a reviewer or maintainer in this repository

Sorry, it's my mistake.

nicknamenotknown avatar Dec 04 '23 15:12 nicknamenotknown

@grobinson-grafana, why are your PRs getting reviewed and merged almost instantly, while this one has been languishing here for three months?

asonnleitner avatar Jan 19 '24 15:01 asonnleitner

@simonpasquier hello! I see your PRs was merged last time. Can you help with this PR and communicate with repository maintainers, please? This is a very small feature but very helpful

iishabakaev avatar Jan 19 '24 22:01 iishabakaev

+1

Brukkil avatar Jan 21 '24 13:01 Brukkil

+1

Hitman95 avatar Feb 07 '24 12:02 Hitman95

This change is trivial and will not affect anything. Why not accept it?

Grafana already have this feature https://github.com/grafana/alerting/pull/143

pavlozt avatar Mar 18 '24 10:03 pavlozt

This MR adds very useful feature, please accept it. :)

vrevkov avatar Mar 22 '24 16:03 vrevkov

@VadimRezvov as a non Telegram user, what is the difference between reply_to_message_id and message_thread_id? I read the Telegram Bot API docs, and I'm still not sure I understand the difference.

We also have this PR here that uses the same configuration option message_thread_id as the ThreadID, instead of as ReplyTo as done in this PR.

grobinson-grafana avatar Mar 23 '24 13:03 grobinson-grafana

@VadimRezvov what is the difference between reply_to_message_id and message_thread_id?

We also have this PR here that uses the same configuration option message_thread_id as the ThreadID, instead of as ReplyTo as done in this PR.

@grobinson-grafana, as user @raphielscape said in the PR you linked, when answering the same question:

If you mean https://github.com/prometheus/alertmanager/pull/3560, this is not duplicate, message_thread_id inclusion is different compared to reply_to_message_id, even though the idea is the same (sending message to a certain topic), message_thread is the intended way to sending a message to a certain topic, reply_to_message, as the fields name says, are more targeted to replying to a certain message ID rather than sending messages.

So, though it serves the same purpose of sending a message to a telegram supergroup thread, it could also reply to a message on any chat, channel or group.

TheArturthur avatar Mar 23 '24 15:03 TheArturthur

@VadimRezvov what is the difference between reply_to_message_id and message_thread_id? We also have this PR here that uses the same configuration option message_thread_id as the ThreadID, instead of as ReplyTo as done in this PR.

@grobinson-grafana, as user @raphielscape said in the PR you linked, when answering the same question:

If you mean #3560, this is not duplicate, message_thread_id inclusion is different compared to reply_to_message_id, even though the idea is the same (sending message to a certain topic), message_thread is the intended way to sending a message to a certain topic, reply_to_message, as the fields name says, are more targeted to replying to a certain message ID rather than sending messages.

So, though it serves the same purpose of sending a message to a telegram supergroup thread, it could also reply to a message on any chat, channel or group.

OK. It sounds like there might be a use case for both? I think #3638 can be reviewed once the author has signed their commits (https://github.com/prometheus/alertmanager/pull/3638#issuecomment-2008694648).

R.E this PR, the choice of message_thread_id to set the reply_to_message_id field seems incorrect, and it will also conflict with #3638. I think the author of this PR should update the PR to add a separate field just for reply_to_message_id and then we can review that too.

grobinson-grafana avatar Mar 23 '24 15:03 grobinson-grafana

To be short the message_thread_id replies to the first message of Telegram group ONLY in supergroups, and the reply_to_message_id (now it is reply_to_message https://core.telegram.org/bots/api#message) replies to the certain message id in the chat for any group type, so that its more multipurpose. So that, reply_to_message is more suitable for the purpose of sending message to certain Telegram topic.

VadimRezvov avatar Mar 23 '24 18:03 VadimRezvov

OK! I think we need to coordinate the two PRs (this and #3638).

Have you also tested this change to make sure it works? The reason I ask is the version of the telebot package used in Alertmanager uses reply_to_message_id not reply_to_message:

if opt.ReplyTo != nil && opt.ReplyTo.ID != 0 {
	params["reply_to_message_id"] = strconv.Itoa(opt.ReplyTo.ID)
}

You might also need to update the telebot package in go.mod too if it doesn't work. I'll also set aside time next week to test it.

grobinson-grafana avatar Mar 23 '24 19:03 grobinson-grafana

Ok, I will take this task, and will be back with results in nearest time.

VadimRezvov avatar Mar 23 '24 21:03 VadimRezvov

To be short the message_thread_id replies to the first message of Telegram group ONLY in supergroups, and the reply_to_message_id (now it is reply_to_message https://core.telegram.org/bots/api#message) replies to the certain message id in the chat for any group type, so that its more multipurpose. So that, reply_to_message is more suitable for the purpose of sending message to certain Telegram topic.

Topics is only available for Supergroups, that's what the documentation conveys, you can't enable Topics in chat that are not supergroup to begin with, so message_thread_id is the proper way to send a message to a Topic as the intended MR is for replying to a Topic rather than message, and that message thread starter ID might be changed if the chat has gone beyond 1 million, so this might not be sustainable to use reply to message as the message it replied might be lost if you have a lot of messages on the chat

raphielscape avatar Mar 24 '24 01:03 raphielscape

Hi! 👋 https://github.com/prometheus/alertmanager/pull/3638 has been merged to main. I would appreciate it if you could test it and make sure it works as I cannot seem to create a Telegram supergroup or topics (perhaps I just don't know how to do it?).

grobinson-grafana avatar Apr 30 '24 11:04 grobinson-grafana

Привет! 👋 #3638 был объединен с основным. Я был бы признателен, если бы вы могли протестировать его и убедиться, что он работает, так как я не могу создать супергруппу или темы Telegram (возможно, я просто не знаю, как это сделать?).

Hi, grobinson-grafana! I'm new to GitHub, can you tell me if I can download the latest version of AlertManager and test this functionality? I'd like to test the ability to send a message to a supergroup with message_thread_id.

veselov-v avatar Aug 16 '24 17:08 veselov-v