First streamed donation
Show new donations in your browser or OBS through the live stream. A single HTML file uses the centrifuge-js library; you do not need your own server. The page displays received donations according to the moderation rules. Delivery time depends on payment processing and the source conditions.
1. Issue a secret key
Section titled “1. Issue a secret key”In the «Секретные ключи» (Secret keys) section, click «Выпустить секретный ключ» (Issue secret key). Enter a name, tick only «Донаты» (Donations, donations:read), choose an expiration period and click «Выпустить ключ» (Issue key). Copy the key now. It is shown only once.
2. Save the page
Section titled “2. Save the page”Save the code as live.html and replace dnt_pat_... with your key.
<!doctype html><meta charset="utf-8"><title>Live donations</title><style>body { font: 600 28px/1.3 system-ui, sans-serif; }</style><div id="donation">Waiting for a donation…</div><script src="https://unpkg.com/centrifuge@5.8.0/dist/centrifuge.js" integrity="sha384-Hc/rqOA60dxGHNnO+nCm7KQ1yc4I121B7eeuuZ9vJMHEq6vVV4onLLtrwG8L79xQ" crossorigin="anonymous"></script><script> const API = "https://api.donatty.com"; const KEY = "dnt_pat_..."; // a secret key: keep this file on your own computer only
const seen = new Set(); // event ids: one event can arrive twice const waiting = new Map(); // id → a donation moderation has not decided on yet
function show(d) { // textContent: the donor's name and message stay text even if they contain markup document.getElementById("donation").textContent = `${d.donorName}, ${d.amount.value} ${d.amount.currency}: ${d.message}`; }
const client = new Centrifuge(API.replace("http", "ws") + "/v1/realtime/websocket", { // https → wss headers: { Authorization: `Bearer ${KEY}` }, // the key goes in the first connection message, not in the address data: { channels: ["donations"] }, // donations only }); client.on("publication", ({ data: event }) => { if (seen.has(event.id)) return; seen.add(event.id); const d = event.data; if (event.type === "donation.created" || event.type === "donation.replayed") { const status = d.moderation.status; if (status === "NONE" || status === "PASSED") show(d); else if (status === "PENDING") waiting.set(d.id, d); // shown after the moderation decision } else if (event.type === "donation.moderated") { const pending = waiting.get(d.id); waiting.delete(d.id); if (pending && d.moderation.status === "PASSED") show(pending); } }); client.on("disconnected", ctx => console.error(`disconnected: ${ctx.code} ${ctx.reason}`)); // final refusal client.connect();</script>3. Open the page
Section titled “3. Open the page”Open live.html in your browser. For OBS, add a Browser source to your scene, tick “Local file” and choose live.html.
4. Check it
Section titled “4. Check it”Press «Тест на стриме» (Test on stream) in your dashboard: the test donation appears on the page.
If the donation does not appear, open the browser console. disconnected: 4501 invalid_token means the key was copied incorrectly or the code still has the dnt_pat_... placeholder; disconnected: 4504 insufficient_scope means that you used a public key or that your secret key does not have the donations:read scope. Other codes are in Stream close codes.
What the page shows
Section titled “What the page shows”The page shows NONE and PASSED donations right away, PENDING ones after donation.moderated with PASSED, and never shows BLOCKED or an unknown status: that is the Moderation and display rule. A test donation from the dashboard arrives as an event with isTest: true: Donation event formats. All fields of a donation are in the Donation structure.
- A donation queue and catch-up after a long disconnection: OBS donation overlay.
- What to do after a dropped connection: History and catch-up.
- Goals, Twitch and YouTube events over the same connection: Stream channels.