Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML is always escaped for Telegram #203

Closed
zzeneg opened this issue Feb 7, 2020 · 5 comments
Closed

HTML is always escaped for Telegram #203

zzeneg opened this issue Feb 7, 2020 · 5 comments
Labels

Comments

@zzeneg
Copy link

zzeneg commented Feb 7, 2020

📣 Notification Service(s) Impacted
Telegram

🪲 Describe the bug
HTML is always escaped even if format=html is passed, so it's not possible send a notification with any HTML formatting. Currently I switched to Markdown as a workaround, but I'd have to escape a lot of symbols to make it work correctly. I think the data should be passed as-is if html format is specified.

💡 Screenshots and Logs
I have apprise-api in Docker with
APPRISE_STATELESS_URLS: tgram://${TELEGRAM_LOGGER_TOKEN}/${TELEGRAM_LOGGER_CHATID}/?format=html
and testing with curl -X POST -d '{"body":"<b>not bold</b>"}' -H "Content-Type: application/json" http://localhost:8000/notify
Result:
image

🔮 Additional context
Looking at NotifyTelegram.py I think

                # HTML
                title = NotifyTelegram.escape_html(title, whitespace=False)

            # HTML
            body = NotifyTelegram.escape_html(body, whitespace=False)

        if title and self.notify_format == NotifyFormat.TEXT:
            # Text HTML Formatting
            payload['text'] = '<b>%s</b>\r\n%s' % (
                title,
                body,
            )

should be changed to

            # HTML
            if self.notify_format == NotifyFormat.TEXT:
                body = NotifyTelegram.escape_html(body, whitespace=False)

        if title and self.notify_format == NotifyFormat.TEXT:
            # Text HTML Formatting
            title = NotifyTelegram.escape_html(title, whitespace=False)
            payload['text'] = '<b>%s</b>\r\n%s' % (
                title,
                body,
            )

but I'm not a python developer so I won't risk changing it myself :)

@caronc
Copy link
Owner

caronc commented Feb 9, 2020

Great find on your part; this is definitely a bug.

I'll merge the new pull request (that will fix this) into the master as soon as all tests pass. By chance are you okay to just use the master branch for now in your environment (as a work around?) once things are merged? I just put out a brand new (Apprise) release a few days ago. I don't intend to put out another until I wrap up a few more fixes (should they come along) and/or new notification services.

Thoughts?

@zzeneg
Copy link
Author

zzeneg commented Feb 9, 2020

I use Docker with caronc/apprise image, as far as I understand it's not possible to use apprise from github there, right? But I can wait, no worries.

@caronc
Copy link
Owner

caronc commented Feb 10, 2020

Actually, you might be able to cheat and still pull it off. However, if you blow away the docker container and re-create it this suggestion will be lost (and need to be repeated). But you should be able to:

# get the container id first:
docker ps --filter=name=apprise

# in my case it was 1cdfa2136a27  - So now i can connect up to it:
docker exec -it 1cdfa2136a27 /bin/bash

# Now inside the container, install git:
apt-get update
apt-get install git -y

# Now update your copy of apprise using the master branch:
pip3 install --upgrade git+https://github.com/caronc/apprise@master

I think that should work; it will still identify itself as v0.8.4, but you should receive all the perks recently pushed for Telegram.

Let me know how it goes!

@zzeneg
Copy link
Author

zzeneg commented Feb 10, 2020

Thanks for the idea, I ended up with forking and changing your Docker image. I'll use it until the official one is updated.
Everything looks good, I'm able to send HTML to Telegram. Thanks!

@caronc
Copy link
Owner

caronc commented Feb 10, 2020

Glad you figured it all out! 🙂

I'm going to close off this ticket now then. But if you do have any more issues, please don't hesitate to open up another!

@caronc caronc closed this as completed Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants