caronc / apprise

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

Turn large ntfy messages into a attachments #1136

Closed caronc closed 1 month ago

caronc commented 1 month ago

Description:

Related issue (if applicable): n/a

It was requested on Discord to avoid passing along large ntfy messages since the upstream blocks them. However to simulate what the ntfy cli does, it takes large body/title content and creates an attachment from it. It specifically targets the JSON body too large Error message the ntfy server sends back if your message is to large for it.

image

The largest feature introduced into this PR is the introduction of a memory based Attachment file. @joergschultzelutter may appreciate this as he asked for it earlier.

from apprise.attachment.memory import AttachMemory

# Initialize
attach = AttachMemory(content="attachment-content-here")

# Now it behaves like other attachments in apprise and is transparent to
# alike calls that utilize `http` and `file` based ones.  

The use case for the memory attachment is so you don't have to write a temporary file to disk and then reference the content as an AttachFile

Checklist

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@attach-large-ntfy-message

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" ntfy://topic
codecov-commenter commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.28%. Comparing base (e289279) to head (d3a2d7b).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1136 +/- ## ======================================= Coverage 99.28% 99.28% ======================================= Files 140 141 +1 Lines 18234 18331 +97 Branches 3729 3750 +21 ======================================= + Hits 18103 18200 +97 Misses 121 121 Partials 10 10 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

joergschultzelutter commented 1 month ago

Definitely appreciated as your code enhancement removes my need for juggling with temporary files.

Cheers @caronc - and: thank you! Joerg