# Events Everything that happens reaches the widget as the window event `onEventReceived`. Its `detail` has two keys: `listener` names what happened, `event` holds the data. ```js window.addEventListener('onEventReceived', (obj) => { const { listener, event } = obj.detail; switch (listener) { case 'follower-latest': /* … */ break; case 'message': /* … */ break; } }); ``` ## All listeners | Listener | When | Platforms | |---|---|---| | `follower-latest` | Someone followed | Twitch | | `subscriber-latest` | Twitch: a subscription (new, resub, gifted). YouTube: someone subscribed to the channel | Twitch, YouTube | | `sponsor-latest` | Someone became or stays a member (also gifted memberships) | YouTube | | `cheer-latest` | Someone cheered bits | Twitch | | `raid-latest` | A raid came in | Twitch | | `tip-latest` | A tip | Ko-fi | | `superchat-latest` | A Super Chat or Super Sticker | YouTube | | `message` | A chat message | Twitch, YouTube | | `delete-message` | A moderator deleted a message | Twitch, YouTube | | `delete-messages` | Someone was timed out or banned: remove all of their messages | Twitch, YouTube | | `bot:counter` | A [variable](https://streamed.hu/docs/variables.md) changed | Streamed | | `kvstore:update` | A [store](https://streamed.hu/docs/store.md) value changed | Streamed | | `widget-button` | A button field was clicked in the settings | Streamed | The listeners that end in `-latest` are **alerts**. Only they wait in the [event queue](https://streamed.hu/docs/lifecycle.md#the-event-queue), and only they change the [session data](https://streamed.hu/docs/session-data.md). A widget only gets the events of the accounts and event kinds its overlay is connected to (the **Accounts** button of the overlay editor). Other listeners of StreamElements (`host-latest`, `merch-latest`, …) never fire here. ## What alerts have in common | Key | Value | |---|---| | `type` | `follower`, `subscriber`, `sponsor`, `cheer`, `raid`, `tip` or `superchat`: the listener without `-latest` | | `name` | Who did it. **Untrusted text**: insert it with `textContent`, never `innerHTML`. | | `amount` | A number; what it counts depends on the type (below). | | `message` | Their message, or `""`. **Untrusted text**, like `name`. | | `createdAt` | When, as an ISO 8601 text | | `_id` | A unique id of this delivery | | `provider`, `platform` | `twitch`, `youtube` or `kofi` | | `streamedEventType` | Streamed's own name of the event, e.g. `twitch:follow` | What `amount` means: | Type | `amount` | |---|---| | `follower` | always `0` | | `subscriber` (Twitch), `sponsor` | months in total (`1`: new). A gift bundle: the number of gifts. | | `subscriber` (YouTube) | always `1` | | `cheer` | bits | | `raid` | viewers | | `tip`, `superchat` | money, in `event.currency` | ## follower-latest A follow on Twitch. ```json { "listener": "follower-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "follower", "name": "PixelPanda", "amount": 0, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:follow" } } ``` ## subscriber-latest On **Twitch**: a subscription. Extra keys: | Key | Value | |---|---| | `tier` | `"1000"`, `"2000"` or `"3000"` (Prime counts as `"1000"`) | | `gifted` | It was a gift. `name` is the recipient, `sender` the gifter. | | `sender` | Who gifted it, or `""`. On Twitch `"AnAnonymousGifter"` for an anonymous gift; YouTube has no anonymous gifts, but `sender` is `""` when Streamed did not see who gave it (for example, it started listening in the middle of a bundle). | | `bulkGifted` | A gift bundle as a whole: `name` and `sender` are the gifter, `amount` the number of gifts | | `isCommunityGift` | One of the gifts of a bundle | | `playedAsCommunityGift` | always `false` | A new subscriber has no message (Twitch sends none); a resub has `amount` > 1 and, if they wrote one, a message. New subscriber: ```json { "listener": "subscriber-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "subscriber", "name": "PixelPanda", "amount": 1, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:subscribe", "tier": "1000", "gifted": false, "sender": "", "bulkGifted": false, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` Resub: ```json { "listener": "subscriber-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "subscriber", "name": "PixelPanda", "amount": 14, "message": "14 months already!", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:subscribe", "tier": "2000", "gifted": false, "sender": "", "bulkGifted": false, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` A gift to one viewer: ```json { "listener": "subscriber-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "subscriber", "name": "LuckyViewer", "amount": 1, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:subscribe", "tier": "1000", "gifted": true, "sender": "GenerousGiraffe", "bulkGifted": false, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` **Gift bundles.** When someone gifts 2 or more subscriptions at once, the widget first gets one event for the bundle (`bulkGifted: true`, `amount`: how many), then one for each recipient (`gifted: true`, `isCommunityGift: true`). To show a bundle once, alert on the bundle and skip the recipients: ```js if (listener === 'subscriber-latest' && event.isCommunityGift) { SE_API.resumeQueue(); // a recipient of a bundle that was already shown return; } ``` The bundle: ```json { "listener": "subscriber-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "subscriber", "name": "GenerousGiraffe", "amount": 5, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:subscribe", "tier": "1000", "gifted": true, "sender": "GenerousGiraffe", "bulkGifted": true, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` The dashboard's test event "Bundle of gifted subscriptions" sends only the bundle event. On **YouTube**, `subscriber-latest` is a new subscriber of the channel, which is what StreamElements calls it, too: `amount` is `1`, `tier` is `"1000"`, and there are no gifts. YouTube only tells about subscribers whose subscriptions are public, and only while the channel is live does Streamed ask for new ones, once a minute, so they can arrive a minute late and several at once. ```json { "listener": "subscriber-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "subscriber", "name": "PixelPanda", "amount": 1, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "youtube", "platform": "youtube", "streamedEventType": "youtube:follow", "tier": "1000", "gifted": false, "sender": "", "bulkGifted": false, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` ## sponsor-latest A YouTube membership: a new member, a milestone (`amount`: months, with their message), or a gift. `tier` is the name of the membership level (`"1000"` when it has none). Gifts work like Twitch's: - A single gift arrives as one event for its recipient: `gifted: true`, `name` is the recipient, `sender` the gifter. - A bundle of 2 or more arrives as one `bulkGifted` event (`name` and `sender` are the gifter, `amount` the number of gifts), then one event per recipient with `isCommunityGift: true`. - `amount` of a gifted membership is `1`. ```json { "listener": "sponsor-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "sponsor", "name": "PixelPanda", "amount": 3, "message": "Three months!", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "youtube", "platform": "youtube", "streamedEventType": "youtube:subscribe", "tier": "Gold", "gifted": false, "sender": "", "bulkGifted": false, "isCommunityGift": false, "playedAsCommunityGift": false } } ``` ## cheer-latest Bits on Twitch. `name` is `"Anonymous"` for an anonymous cheer. The message still contains the cheermotes (`Cheer500`); [`SE_API.cheerFilter(message)`](https://streamed.hu/docs/api-reference.md#cheerfilter) removes them. ```json { "listener": "cheer-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "cheer", "name": "PixelPanda", "amount": 500, "message": "Cheer500 Great play!", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:bits" } } ``` ## raid-latest A raid on Twitch. `name` is the raiding channel, `amount` the number of viewers. ```json { "listener": "raid-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "raid", "name": "FriendlyStreamer", "amount": 42, "message": "", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "twitch", "platform": "twitch", "streamedEventType": "twitch:raid" } } ``` ## tip-latest A tip through Ko-fi (only the payments set as tips on the dashboard). `currency` is a three-letter code. `message` is empty unless the tipper made it public. `name` is `"Anonymous"` when they gave none. ```json { "listener": "tip-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "tip", "name": "PixelPanda", "amount": 5, "message": "Coffee is on me!", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "kofi", "platform": "kofi", "streamedEventType": "kofi:tip", "currency": "EUR" } } ``` Tips also add up in the built-in [tip variables](https://streamed.hu/docs/variables.md#built-in-tip-variables). ## superchat-latest A Super Chat or Super Sticker on YouTube. `message` is the comment, or the sticker's description. Super Chats are counted in the tip variables, too. ```json { "listener": "superchat-latest", "event": { "_id": "streamed-mi3k2x9c-1", "type": "superchat", "name": "PixelPanda", "amount": 10, "message": "Love the stream!", "createdAt": "2026-12-01T18:30:00.000Z", "provider": "youtube", "platform": "youtube", "streamedEventType": "youtube:tip", "currency": "USD" } } ``` ## message A chat message. `event.data` has the details, `event.renderedText` the message as safe HTML. | Key | Value | |---|---| | `data.displayName` | The chatter's name. **Untrusted text.** | | `data.nick` | Lowercase login name (YouTube: the lowercase display name) | | `data.userId` | The chatter's id: compare it with `delete-messages` | | `data.msgId` | The message's id: compare it with `delete-message` | | `data.text` | The message as written. **Untrusted text**: use `textContent`. | | `renderedText` | The message HTML-escaped, with emotes as ``. **Safe** to use with `innerHTML`. | | `data.displayColor` | `"#rrggbb"`, or `""` when they have not picked one (always `""` on YouTube) | | `data.badges` | `[{ type, version, url, description }]`, e.g. `moderator`, `subscriber`, `broadcaster`. On YouTube `url` is empty. | | `data.emotes` | `[{ type, name, id, gif, urls: { "1", "2", "4" }, start, end }]`; positions count characters (code points). Empty on YouTube: its emoji stay as text like `:wave:`. | | `data.isAction` | A `/me` message | | `data.tags` | Twitch's raw chat tags, all texts (e.g. `mod: "1"`); `{}` on YouTube | | `data.time` | When, in milliseconds since 1970 | | `data.channel` | The channel's name | | `service`, `platform` | `twitch` or `youtube` | Twitch: ```json { "listener": "message", "event": { "service": "twitch", "data": { "time": 1764613800000, "tags": { "display-name": "PixelPanda", "mod": "0", "subscriber": "1", "badges": "subscriber/12", "user-id": "123456789" }, "nick": "pixelpanda", "userId": "123456789", "displayName": "PixelPanda", "displayColor": "#1E90FF", "badges": [ { "type": "subscriber", "version": "12", "url": "https://static-cdn.jtvnw.net/badges/v1/5d9f2208-5dd8-11e7-8513-2ff4adfae661/1", "description": "1-Year Subscriber" } ], "channel": "yourchannel", "text": "Hello chat Kappa", "isAction": false, "emotes": [ { "type": "twitch", "name": "Kappa", "id": "25", "gif": false, "urls": { "1": "https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/1.0", "2": "https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/2.0", "4": "https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/3.0" }, "start": 18, "end": 22 } ], "msgId": "b9f4c1e2-5d7a-4c3e-9a51-2f0e8d6b7c10" }, "renderedText": "Hello <b>chat</b> \"Kappa\"", "platform": "twitch", "streamedEventType": "twitch:message" } } ``` YouTube: ```json { "listener": "message", "event": { "service": "youtube", "data": { "time": 1764613800000, "tags": {}, "nick": "pixel panda", "userId": "UCa1b2c3d4e5f6g7h8i9j0", "displayName": "Pixel Panda", "displayColor": "", "badges": [ { "type": "member", "version": "1", "url": "", "description": "Member" } ], "channel": "Your Channel", "text": "Hi from YouTube :wave:", "isAction": false, "emotes": [], "msgId": "LCC.Cg8KDQoLYWJjZGVmZ2hpams" }, "renderedText": "Hi from YouTube :wave:", "platform": "youtube", "streamedEventType": "youtube:message" } } ``` Showing a message safely: ```js function addMessage(event) { const row = document.createElement('div'); row.dataset.msgId = event.data.msgId; row.dataset.userId = event.data.userId; const name = document.createElement('strong'); name.textContent = event.data.displayName; // untrusted: text only name.style.color = event.data.displayColor || '#bf94ff'; const text = document.createElement('span'); text.innerHTML = ' ' + event.renderedText; // safe: escaped by Streamed row.append(name, text); document.getElementById('chat').appendChild(row); } ``` Chat messages are never stored: a widget only sees those that arrive while it is open. ## delete-message A moderator deleted one message. ```json { "listener": "delete-message", "event": { "msgId": "b9f4c1e2-5d7a-4c3e-9a51-2f0e8d6b7c10" } } ``` ```js if (listener === 'delete-message') { document.querySelector(`[data-msg-id="${CSS.escape(event.msgId)}"]`)?.remove(); } ``` ## delete-messages Someone was timed out or banned: remove all of their messages. ```json { "listener": "delete-messages", "event": { "userId": "123456789" } } ``` ```js if (listener === 'delete-messages') { document.querySelectorAll(`[data-user-id="${CSS.escape(event.userId)}"]`).forEach((el) => el.remove()); } ``` ## bot:counter A [variable](https://streamed.hu/docs/variables.md) was created, changed or deleted. `value` is a number, unless the variable holds a text; a deleted variable reads `0`. ```json { "listener": "bot:counter", "event": { "counter": "deaths", "value": 12 } } ``` ## kvstore:update A value of the [store](https://streamed.hu/docs/store.md) was saved, by this or another custom widget of yours. The key has the prefix `customWidget.`. ```json { "listener": "kvstore:update", "event": { "data": { "key": "customWidget.tally", "value": { "count": 3 } } } } ``` ## widget-button A `button` field was clicked in the widget's settings. `value` is the field's `value`. ```json { "listener": "widget-button", "event": { "field": "testAlert", "value": "test" } } ``` ## Telling platforms apart `event.platform` (or, in a chat message, `event.service`) says where an event came from, when the overlay is connected to several platforms: ```js if (listener === 'subscriber-latest' && event.platform === 'youtube') { // a new YouTube subscriber, not a Twitch subscription } ```