🔔 push

Send push notifications from val.town to your device!

demo

Setup

  • 🔀 Remix this val
  • Open HTTP Endpoint (optionally set a custom subdomain)
  • Create an API key with Users: Read-only permission
  • Paste your API key into the password field
  • Subscribe and allow push notification permissions
  • You should receive a 👋 notification!

Usage

Calling push notifications in another val:

import { sendNotification } from "https://esm.town/v/YOUR_PUSH_REMIX_HERE/pushSendNotification.tsx"; console.log( await sendNotification("Example notification", { data: { url: "https://example.com" }, }), );

Sending a push notification from outside of Val Town using an API call:

fetch("https://YOUR_ENDPOINT_HERE/push", { method: "POST", headers: { "Content-Type": "application/json", Authorization: "Bearer YOUR_API_TOKEN_HERE", }, body: JSON.stringify([ "Example notification", { data: { url: "https://example.com" } }, ]), });

Sending a push notification from outside of Val Town using cURL:

curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_TOKEN_HERE" \ -d '["Example notification",{"data":{"url":"https://example.com"}}]' \ "https://YOUR_ENDPOINT_HERE/push"

Caveats

  • The service currently only supports sending notifications to one device at a time, but could be extended to work with multiple devices/users.
  • For instant configuration, the service stores (a) crypto keys used to encrypt notifications and (b) the device currently subscribed to notifications in blob storage. It is the user's responsibility to secure these blobs from being exposed by other vals.