Add authenticated ntfy

This commit is contained in:
SkyfallWasTaken 2024-07-20 19:22:43 +01:00
parent 34e3ab948b
commit ed62cc90de
3 changed files with 6 additions and 2 deletions

View file

@ -5,10 +5,11 @@
## Environment variables
### Secrets
- `SLACK_WEBHOOK_URL` - Slack webhook to call on updates
- `NTFY_URL` - URL for ntfy
- `NTFY_AUTH_TOKEN` - Auth token for ntfy
### Variables
- `ARCADE_SHOP_URL` - Shop URL to fetch
- `NTFY_URL` - URL for ntfy
## Tech Stack
- **Cloudflare Workers** for running the monitor on the edge.

View file

@ -36,7 +36,8 @@ pub async fn scheduled(event: ScheduledEvent, env: Env, _ctx: ScheduleContext) {
async fn run_scrape(env: Env) -> Result<String> {
let shop_url = Url::parse(&env.var("ARCADE_SHOP_URL")?.to_string())?;
let slack_webhook_url = env.secret("SLACK_WEBHOOK_URL")?.to_string();
let ntfy_url = env.secret("NTFY_URL")?.to_string();
let ntfy_url = env.var("NTFY_URL")?.to_string();
let ntfy_auth_token = env.secret("NTFY_AUTH_TOKEN")?.to_string();
let client = Client::new();
let kv = env.kv("SHOP_ITEMS")?;
@ -77,6 +78,7 @@ async fn run_scrape(env: Env) -> Result<String> {
// ntfy webhook
client
.post(ntfy_url)
.bearer_auth(ntfy_auth_token)
.header("X-Title", "Changes detected in Arcade Shop")
.header("X-Priority", "high")
.body(changes)

View file

@ -12,6 +12,7 @@ crons = ["*/20 * * * *"] # Run every twenty minutes
mode = "smart"
[vars]
NTFY_URL = "https://ntfy.hackclub.app/arcade-monitor"
ARCADE_SHOP_URL = "https://hackclub.com/arcade/shop/"
[[kv_namespaces]]