[Question] Sending messages to Telegram groups/channels
Question
Will it be realized to send messages to Telegram channels/groups and specific topics of Telegram groups, as for example it is realized in Grafana?. The current functionality of sending messages to one specific user is obviously less demanded than sending to a Telegram group
Hi, I believe Telegram uses the same type of ID for individuals, groups, and channels. So, from the sender's POV, the process for sending a message is the same for all three. In Telegram parlance, it's typically called the "chat ID" or "peer ID."
The peer id is a unique 64-bit ID used to identify a specific user, chat or channel.
https://core.telegram.org/api/peers#peer-id
It seems has supported.
I apologize, I was trying to post to a closed thread, so I assumed that posting was only available on USER_ID. Checked again, yes, sending does work to both channels and Telegram groups, but it is still not available to send to specific Telegram topics. I suggest adding the "message_thread_id" option to allow sending messages to a specific Telegram group topic.
@tomsun28
Hello, I believe I can handle this task effectively. Would you be able to assign it to me?
After reviewing the code, I propose the following modifications to support this feature:
Backend:
- Add a
messageThreadIdproperty to theTelegramBotNotifyDTOclass
Frontend:
- Add an optional input field for entering the
message_thread_id
I've completed the code implementation, but I'm encountering an issue during testing.
According to the Telegram Bot API documentation:
Unique identifier for the target message thread (topic) of the forum; for forum supergroups only
After researching, I discovered that message threads (topics) are only supported in supergroups, which requires a group with more than 200 members to be converted to a supergroup format.
Would anyone be willing to help me test this functionality? I have a Telegram bot ready for testing. Perhaps you could add me to a group with topics enabled so I can conduct my tests. Alternatively, if you have any other suggestions for testing this feature, I'd appreciate your input.
Hi. No problem, I can add your bot to my test supergroup, please send me the nickname.
Hi. No problem, I can add your bot to my test supergroup, please send me the nickname.
Thank you! My bot's username is @cy_demo123_bot. To function properly in your supergroup, it needs permission to send messages.
Next, I’ll first search on Google to find out how to obtain the message_thread_id. If you already know how to get it and could share the information with me, I would really appreciate it!
Bot added
supergroup ID is: -1002352333424
and two different topics: message_thread_id=2 message_thread_id=4
Example of sending
curl --location 'https://api.telegram.org/<bot_token>/sendMessage'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'chat_id=-1002352333424'
--data-urlencode 'text=test'
--data-urlencode 'message_thread_id=2'
Messages came first in message_thread_id=2 then message_thread_id=4 in turn
Also the message came in the General topic, probably when message_thread_id was not set
Messages came first in message_thread_id=2 then message_thread_id=4 in turn
Thank you! 😊
Thank you for that)
I’ll be submitting a PR soon.