Web Push API for Zotonic
The module needs 3 config variables.
Use mod_web_push_api
as module name and create the following config settings:
private_key
: The vapid private key to use.public_key
: The vapid public key to user.subject_email
: This email address will be sent to the endpoint servers which manage the push api subscriptions.
You can generate a new vapid key by running in the zotonic debug console:
> z_webpush_crypto:generate_vapid_key().
#{privateKey =>
<<"8E85ai4_********************">>,
publicKey =>
<<"BGgwFt8c_9-**************************">>}
The zotonic admin panel has a new side panel which can be used to subscribe the logged on user to web push subscriptions.
> mod_web_push_api:send(1, #{ type => notification, data => #{ title => <<"Hello">>, options => #{ body => <<"World">>, data => #{ url => <<"/page/123">>} }}}, #{ ttl => 3600 }, z:c(your_site)).
This will sent a notification to all currently setop subscriptions for user 1 (Admin). When a subscription has been setup the notification will be received by the service worker of the browser, which will display the notification.
- Queing notifications when the endpoint errors or is offline.
- Retry sending notifications.
- Add configuration panel to the admin.
- Setup ssl validation for the endpoint connections.