Send push notifications from val.town to your device!
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"