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

Turn large ntfy messages into a attachments #1136

Merged
merged 2 commits into from
Jun 2, 2024

Conversation

caronc
Copy link
Owner

@caronc caronc commented Jun 2, 2024

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

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

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

@caronc caronc force-pushed the attach-large-ntfy-messages branch 2 times, most recently from 2252581 to bf0a25d Compare June 2, 2024 01:22
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

Additional details and impacted files
@@           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           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@caronc caronc force-pushed the attach-large-ntfy-messages branch 2 times, most recently from 04afa94 to 322bc68 Compare June 2, 2024 01:38
@caronc caronc force-pushed the attach-large-ntfy-messages branch from 322bc68 to d3a2d7b Compare June 2, 2024 01:40
@caronc caronc merged commit de3acaf into master Jun 2, 2024
13 checks passed
@joergschultzelutter
Copy link
Contributor

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

Cheers @caronc - and: thank you!
Joerg

@caronc caronc deleted the attach-large-ntfy-messages branch July 26, 2024 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants