push
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v417View latest version
Send push notifications from val.town to your device!
- π 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!
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 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" } },
]),
});