Skip to content

Vapid/WebPush Support#1323

Merged
caronc merged 19 commits intomasterfrom
1009-webpush-support
Jun 30, 2025
Merged

Vapid/WebPush Support#1323
caronc merged 19 commits intomasterfrom
1009-webpush-support

Conversation

@caronc
Copy link
Owner

@caronc caronc commented Apr 26, 2025

Description:

Related issue (if applicable): #1009

This is very much a work in progress

Account Setup

Vapid/WebPush requires a subscriptions.json file that identifies all of the users you wish to notify and a private_key.pem

Syntax:

  • vapid://subscription_id/
  • vapid://subscription_id/target
  • vapid://subscription_id/target1/target2/targetN/

Parameter Breakdown

Variable Required Description
keyfile Yes A private key in PEM format belonging to the account associated with the subscription_id
subfile Yes A subscriptions.json file identifying the configuration you wish to reference.
mode No The mode to use (default chrome). Possible values are chrome, firefox, edge, and opera. This just simplifies the upstream source that is used when the notification is sent.

Mode Table:
You will see a lot of duplication (many modes pointing to the same location). The idea is if the end points change, we will update it inside Apprise so your code/URL will not have to change later.

Mode URL
chrome https://fcm.googleapis.com/fcm/send
forefpx https://updates.push.services.mozilla.com/wpush/v1
edge https://fcm.googleapis.com/fcm/send
opera https://fcm.googleapis.com/fcm/send
apple https://web.push.apple.com'
brave https://fcm.googleapis.com/fcm/send
samsung https://fcm.googleapis.com/fcm/send
generic https://fcm.googleapis.com/fcm/send

subscriptions.json Setup

In order to use Vapid, you must have a subscriptions.json file that it can point to. The Vapid plugin supports the 2 following formats:

  1. standalone; in the below example, the target would be abc123
    {
        "endpoint": "https://fcm.googleapis.com/fcm/send/abc123",
        "keys": {
            "p256dh": "BNcW4oA7zq5H9TKIrA3XfKclN2fX9P_7NR...",
            "auth": "k9Xzm43nBGo=",
        }
    }
  2. multiple target support; in the below example, 2 targets are created called name1 and name2
    {
        "name1": {
            "endpoint": "https://fcm.googleapis.com/fcm/send/...",
            "keys": {
                "p256dh": "BNcW4oA7zq5H9TKIrA3XfKclN2fX9P_7NR...",
                "auth": "k9Xzm43nBGo=",
            }
        },
        "name2": {
            "endpoint": "https://fcm.googleapis.com/fcm/send/...",
            "keys": {
                "p256dh": "BNcW4oA7zq5H9TKIrA3XfKclN2fX9P_7NR...",
                "auth": "k9Xzm43nBGo=",
            }
        }

It is though targets that you notify one or more endpoints. If you're using persistent storage with Apprise, you can simply manage your subscription.json file located here and your URL can stay clean. Alternatively, you can specify ?subfile= on your URL and point it to a subscription file you wish to load. The location can be local to the filesystem as well as a remote location (such as subfile=https://user:pass@myhost/special/location/subscription.json

If no target is specified on your URL, then a target that matches your own subscriberid is looked up in the subcriptions.json file

Private Key (PEM) Setup

Similar to the subscription.json, you need to point to a private_key.pem file. If you are using Apprise persisent storage, you can place the file here. Alternatively you can specify ?keyfile= on the URL and point it to a local or remote file you wish to use.

Persistent Storage Tips

The following command will list all of the persistent storage locations associated with your configuration:

apprise storage list

Simply locate the ID associated with the Vapid account you wish to update; consider that the directory ID's can be found as:

  1. Microsoft Windows: %APPDATA%/Apprise/cache
  2. Linux: ~/.local/share/apprise/cache

For more details on this; see here.

Apprise URL Construction

This is a more complicated plugin to work with since it requires a binary PEM private key and a subscription.json file as well. It would be advised to use a Apprise Configuration YAML file that looks like this:

urls:
   - vapid://:
       mode: apple
       keyfile: /path/to/keyfile
       subfile: /path/to/subscription.json

Remember that both the keyfile and subfile can be URLs as well (even ones protected behind user/passwords such as:

urls:
   - vapid://:
       mode: apple
       keyfile: https://user:pass123@example.com/private_key.pem
       subfile: https://user:pass123@example.com/subscriptions.json

If you do not define a keyfile and/or a subfile, the rules above apply as documented above and default ones are looked upon in your persistent storage directory.

New Service Completion Status

  • apprise/plugins/vapid
  • KEYWORDS
    • add new service into this file (alphabetically).
  • README.md
    • add entry for new service to table (as a quick reference)
  • packaging/redhat/python-apprise.spec
    • add new service into the %global common_description

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@1009-webpush-support

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  "vapid://subscriber_id"

@caronc caronc force-pushed the 1009-webpush-support branch from 9567ce4 to 78711a8 Compare May 24, 2025 22:39
@codecov
Copy link

codecov bot commented May 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.40%. Comparing base (ce90151) to head (e8b8d76).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1323      +/-   ##
==========================================
+ Coverage   99.38%   99.40%   +0.01%     
==========================================
  Files         162      165       +3     
  Lines       21160    21848     +688     
  Branches     3804     3901      +97     
==========================================
+ Hits        21029    21717     +688     
  Misses        121      121              
  Partials       10       10              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@caronc caronc force-pushed the 1009-webpush-support branch 2 times, most recently from e17d37f to aa64c02 Compare June 7, 2025 16:23
@caronc caronc linked an issue Jun 7, 2025 that may be closed by this pull request
@caronc caronc force-pushed the 1009-webpush-support branch from f2cdbd3 to ca27daf Compare June 12, 2025 16:10
@caronc caronc force-pushed the 1009-webpush-support branch from ca27daf to e8b8d76 Compare June 24, 2025 00:54
@caronc caronc merged commit b2e4b92 into master Jun 30, 2025
13 checks passed
@slavaGanzin
Copy link
Contributor

@caronc Nice work thanks!

@caronc caronc deleted the 1009-webpush-support branch July 6, 2025 17:15
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.

support for WebPush and VAPID

2 participants