caronc / apprise

Apprise - Push Notifications that work with just about every platform!
https://hub.docker.com/r/caronc/apprise
BSD 2-Clause "Simplified" License
11.68k stars 409 forks source link

Query: Telegram: Send message to topic #1143

Closed schizovivek closed 2 months ago

schizovivek commented 3 months ago

:question: Question Have been using apprise for a couple weeks and using it to send notifications to one of my telegram groups. It's been working without a hitch but since yesterday I've been trying to get it to work with topics but am just not able to.

If I use the curl I'm able to send the message to the topic using the below command

curl --header "Content-Type: application/json" --request POST --data '{"chat_id": "${chat_id}","message_thread_id": "${message_thread_id}", "text": "Group test", "parse_mode": "MarkdownV2"}' https://api.telegram.org/bot${bot_id}

But with apprise when i use the below command it is sending the message to the general group and not to he specific group I'm targeting uptime | apprise -vv 'tgram://bot${bot_id}/${chat_id}/?topic=${message_thread_id}'

I tried the commands mentioned in link https://github.com/caronc/apprise/wiki/Notify_telegram#syntax uptime | apprise -vv 'tgram://bot${bot_id}/${chat_id}:${message_thread_id}' The above command gives a warning and nothing happens 2024-06-16 00:47:47,719 - WARNING - The specified chat_id 'None' is invalid; skipping

What I understand from this issue, it seems that the feature has been implemented but I'm not sure what I'm doing wrong here. When running in debug mode with -vvvv the payload is not showing the message_thread_id

Would someone be kind enough to show me what I could be doing wrong here.

madhusudansharma7 commented 3 months ago

import apprise

Initialize Apprise object with Telegram URL

apobj = apprise.Apprise() apobj.add('tgram://')

Send message

apobj.notify( title='Test Notification', body='This is a test notification from Apprise!' )

use api key and chat id of telegram

this bot provide api key; BotFather this bot provide chat id ; userinfobot

schizovivek commented 3 months ago

I wanted to use the cli but I still tried this. I'm able to send it to the supergroup but it pushes the information to the General topic and not the notification topic I set up This is the output of the getUpdates api. I'm using the highlighted id (missed to block the id in the chat section above but hopeuflly id without the supergroup id shouldn't cause any concerns for me) image

caronc commented 2 months ago

It looks like this is the commit where the thread_id was brought into play. It was passed in as a GET param where as in your example, and the reason for this is here

I know adding it as a parameter in the URL also resolved another bug where Attachments wouldn't appear in the thread, but the messages would.

Now... 2024... i wonder if this is broken or changed (and needs to work the way you're describing)?

schizovivek commented 2 months ago

Not sure if it was changed or not but i got the reference from below links https://core.telegram.org/bots/api#sendmessage https://stackoverflow.com/questions/76891340/send-messages-to-message-thread-id-with-telegram-bot/76892714#76892714

caronc commented 2 months ago

I want to appologize as i went wayyyyyyy of topic. You started a legitimate post about Telegram, and i started responding with Discord issues. I embarassingly enough kept trying to figure out why Discord worked so well for me and not for you.

naturally putting in telegram payload enties into a working discord payload didn't work :wink:

Okay... so i did reproduce your issue. It seems threads have been broken for a while and my inability to focus on the actual problem caused you to wait longer.

anyway, sorry (again) for all of th delays (seriously).

I'm confident I resolved everything and it works as it should (added some good test cases to back this up).

If you want to test the attached PR (instructions on how to inside), feel free! I'll likely do a few more tests and then merge it later.