Most families on Discord or Slack have a private family channel. MathNet’s webhook can post directly into it.

Discord

Discord webhooks accept JSON but with a specific schema. You’ll need a tiny relay (Cloudflare Worker, Lambda, Home Assistant rest_command, etc.) to reformat MathNet’s payload into Discord’s:

// Cloudflare Worker
addEventListener('fetch', event => event.respondWith(handle(event.request)))

async function handle(req) {
  const data = await req.json()
  return fetch('https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_TOKEN', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      content: `🎉 **${data.device_name}** redeemed a credit! (${data.balance_after} left)`,
      username: 'MathNet',
      avatar_url: 'https://mathnet.app/images/logo.png'
    })
  })
}

Get the Discord webhook URL from Server Settings → Integrations → Webhooks → New Webhook. Treat it as a secret.

Slack

Slack’s “Incoming Webhooks” app takes a similar shape:

// Cloudflare Worker
addEventListener('fetch', event => event.respondWith(handle(event.request)))

async function handle(req) {
  const data = await req.json()
  return fetch('https://hooks.slack.com/services/YOUR/WEBHOOK/URL', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      text: `🎉 *${data.device_name}* redeemed a credit (${data.balance_after} left)`,
      username: 'MathNet',
      icon_emoji: ':abacus:'
    })
  })
}

Quick setup with Cloudflare Workers

If you don’t already have somewhere to run the relay, Cloudflare Workers is free for low traffic, easy to set up, and gives you a stable *.workers.dev URL to point MathNet at.

  1. Create a Worker
  2. Paste either script above (with your Discord/Slack webhook filled in)
  3. Copy the Worker URL into MathNet’s Webhook URL field
  4. Test