Twitch
Twitch Moderation Toolkit — cross-channel moderation visibility for Twitch moderators.
This extension provides a model for interacting with the Twitch Helix API (chatters, bans, mod events, user lookups), a workflow that audits all your moderated channels in parallel, and a report that correlates findings cross-channel to surface suspicious users and ban overlap.
Quick Start
swamp extension pull @webframp/twitch
# Store the credentials first; see Authentication below.
# Create one model instance per channel you moderate
swamp model create @webframp/twitch mod-drongo \
--global-arg channel=drongo \
--global-arg moderatorId=YOUR_TWITCH_USER_ID \
--global-arg 'clientId=${{ vault.get("twitch", "CLIENT_ID") }}' \
--global-arg 'clientSecret=${{ vault.get("twitch", "CLIENT_SECRET") }}' \
--global-arg 'accessToken=${{ vault.get("twitch", "ACCESS_TOKEN") }}' \
--global-arg 'refreshToken=${{ vault.get("twitch", "REFRESH_TOKEN") }}'
# If the broadcaster has OAuth'd your app, also enable ban/mod-event reads
# by adding: --global-arg hasBroadcasterAuth=true
# Run the cross-channel audit
swamp workflow run @webframp/twitch-mod-auditAuthentication
Requires a Twitch application with OAuth2 user tokens. Register an app at
dev.twitch.tv/console/apps with redirect
URL http://localhost:3000 and category "Chat Bot".
Store every credential in a swamp vault and reference it with a vault.get
expression; never pass a literal value. Any vault type works —
local_encryption, or an extension such as @webframp/pass,
@webframp/gopass, @webframp/hashicorp-vault or @webframp/macos-keychain.
swamp vault create local_encryption twitch # once, if you have no vault yet
swamp vault put twitch CLIENT_ID # each put prompts; values never touch shell history
swamp vault put twitch CLIENT_SECRETObtain the user tokens
Open this URL in a browser, with your client ID in place of
YOUR_CLIENT_ID, and approve the app:https://id.twitch.tv/oauth2/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost:3000&response_type=code&scope=moderator:read:chatters+moderator:read:banned_users+moderator:manage:banned_users+user:write:chat+channel:read:editors+moderator:read:suspicious_users+moderator:read:warnings
Copy the
codeparameter from the redirect URL, then exchange it for tokens and store them straight into the vault. The client secret travels on stdin, never on thecurlcommand line, and the tokens are never printed:AUTH_CODE=paste-the-code-here TOKENS=$(printf 'client_id=%s&client_secret=%s&code=%s&grant_type=authorization_code&redirect_uri=http://localhost:3000' \ "$(swamp vault read-secret twitch CLIENT_ID --force)" \ "$(swamp vault read-secret twitch CLIENT_SECRET --force)" \ "$AUTH_CODE" | curl -sS -X POST 'https://id.twitch.tv/oauth2/token' \ -H 'Content-Type: application/x-www-form-urlencoded' --data @-) jq -r .access_token <<<"$TOKENS" | swamp vault put twitch ACCESS_TOKEN jq -r .refresh_token <<<"$TOKENS" | swamp vault put twitch REFRESH_TOKEN unset TOKENS AUTH_CODE
Look up your moderator user ID (the
idfield), sending the headers on stdin:printf 'Authorization: Bearer %s\nClient-Id: %s\n' \ "$(swamp vault read-secret twitch ACCESS_TOKEN --force)" \ "$(swamp vault read-secret twitch CLIENT_ID --force)" | curl -sS -H @- 'https://api.twitch.tv/helix/users'
swamp vault read-secret --force prints the plaintext secret. The commands
above only feed it into a pipe; do not run it bare in a shared terminal, and
never use it to wire a model — use vault.get for that.
The model refreshes expired access tokens automatically using the refresh token.
Jev moderation analysis
Run @webframp/twitch-character-analysis with an existing Twitch model and
a vault-backed @swamp/typesafe-ai model. The workflow scores observable
moderation signals only; it is not a personality or protected-trait profiler.
Methods by Auth Level
Moderator auth (works with any moderator token)
| Method | Scope | Purpose |
|---|---|---|
| get_channel | channel:read:editors | Channel metadata |
| get_chatters | moderator:read:chatters | List users in chat |
| get_user | (none) | User profile and account age |
| ban_user / unban_user | moderator:manage:banned_users | Issue/remove bans |
| send_message | user:write:chat | Send chat messages |
Broadcaster auth (broadcaster must have OAuth'd the app)
| Method | Scope | Purpose |
|---|---|---|
| get_banned_users | moderator:read:banned_users | Read full ban list |
| get_mod_events | moderator:read:banned_users | Mod add/remove events |
Set hasBroadcasterAuth=true on model instances where the broadcaster has
authorized your application. Methods that require broadcaster auth throw a
clear error when the flag is false.
Scopes
Request all scopes during app registration to avoid re-authorization later.
Note: the deprecated moderation:read scope has been replaced by the
granular moderator:read:banned_users scope.
| Scope | Used by | Purpose |
|---|---|---|
| moderator:read:chatters | get_chatters | List users in chat |
| moderator:read:banned_users | get_banned_users, get_mod_events | Read bans and mod activity |
| moderator:manage:banned_users | ban_user, unban_user | Issue bans/timeouts and unban |
| user:write:chat | send_message | Send chat messages as your user |
| channel:read:editors | get_channel | Read channel metadata |
| moderator:read:suspicious_users | (future) | Twitch-flagged suspicious users |
| moderator:read:warnings | (future) | Warnings issued to users |
2026.11.09.1
Added: Added get_user_context plus the
@webframp/twitch-character-analysis workflow, which combines observable
channel-scoped Twitch facts with typed Jev moderation rankings.
Added: Added a workflow report and optional outbound Discord webhook notification. Discord Gateway ingress remains the responsibility of a small adapter that posts signed webhook payloads to swamp.
Upgrade note: Configure an existing @swamp/typesafe-ai model with a
vault-backed TypeSafe API key. Ban status is available only when the Twitch
model has broadcaster authorization.
2026.11.03.1
Changed: Bump zod 4.6.5 → 4.6.7
2026.10.21.1
Fixed: The registry Quick Start created model instances without
clientId, clientSecret, accessToken, or refreshToken, which are required,
so the documented command failed. It also used swamp vault set, which does
not exist. Both Quick Starts now wire every credential with
${{ vault.get("twitch", "...") }}.
Changed: Documentation only otherwise. Credentials are stored with
swamp vault put twitch <KEY> at the interactive prompt instead of with the
value on the command line. The OAuth token exchange now sends the client secret
to curl on stdin rather than in argv, and stores the returned tokens straight
into the vault without printing them. The examples use a vault named twitch
with CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, and REFRESH_TOKEN keys;
existing instances that reference other vault or key names keep working. The
credential global argument descriptions now say to supply them through
vault.get.
Upgrade note: No code, schema, or behavioral changes. The model version moves to 2026.10.21.1 with an identity upgrade.
Global Arguments
| Argument | Type | Description |
|---|---|---|
| channel | string | Twitch channel login name |
| moderatorId | string | Your Twitch user ID (the moderator performing actions) |
| clientId | string | Twitch application client ID. Supply it as ${{ vault.get("twitch", "CLIENT_ID") }}; never pass the literal value |
| clientSecret | string | Twitch application client secret. Supply it as ${{ vault.get("twitch", "CLIENT_SECRET") }}; never pass the literal value |
| accessToken | string | OAuth2 access token. Supply it as ${{ vault.get("twitch", "ACCESS_TOKEN") }}; never pass the literal value |
| refreshToken | string | OAuth2 refresh token. Supply it as ${{ vault.get("twitch", "REFRESH_TOKEN") }}; never pass the literal value |
| hasBroadcasterAuth? | boolean | Set true if the broadcaster authorized this app (enables ban list and mod event reads) |
| Argument | Type | Description |
|---|---|---|
| login | string | Twitch login name to look up |
| Argument | Type | Description |
|---|---|---|
| login | string | Twitch login name to inspect |
| Argument | Type | Description |
|---|---|---|
| userId | string | Twitch user ID to ban |
| reason? | string | Reason for the ban |
| duration? | number | Timeout duration in seconds, 1 to 1209600 (2 weeks); omit for a permanent ban |
| Argument | Type | Description |
|---|---|---|
| userId | string | Twitch user ID to unban |
| Argument | Type | Description |
|---|---|---|
| message | string | Message text to send (max 500 chars) |
| replyToMessageId? | string | Message ID to reply to (threads the response) |
Resources
Cross-channel Twitch moderation audit. Gathers chatters, bans, and channel info from all channel instances in parallel, then flags suspicious users (new accounts, cross-channel ban overlap, multi-channel presence). NOTE: Steps use modelIdOrName: "*" to target all @webframp/twitch model instances. Create one model instance per channel before running this workflow (e.g. swamp model create --type @webframp/twitch --name channel1).
Analyze one Twitch user's observable moderation-relevant behavior using Twitch facts plus typed Jev rankings. This is not a personality, protected trait, or off-platform identity assessment.
Renders observable Twitch moderation facts and typed Jev rankings for one user
Cross-channel moderation report highlighting suspicious users, ban overlap, and recent mod activity
2026.11.03.1
Changed: Bump zod 4.6.5 → 4.6.7
2026.10.21.1
Fixed: The registry Quick Start created model instances without
clientId, clientSecret, accessToken, or refreshToken, which are required,
so the documented command failed. It also used swamp vault set, which does
not exist. Both Quick Starts now wire every credential with
${{ vault.get("twitch", "...") }}.
Changed: Documentation only otherwise. Credentials are stored with
swamp vault put twitch <KEY> at the interactive prompt instead of with the
value on the command line. The OAuth token exchange now sends the client secret
to curl on stdin rather than in argv, and stores the returned tokens straight
into the vault without printing them. The examples use a vault named twitch
with CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, and REFRESH_TOKEN keys;
existing instances that reference other vault or key names keep working. The
credential global argument descriptions now say to supply them through
vault.get.
Upgrade note: No code, schema, or behavioral changes. The model version moves to 2026.10.21.1 with an identity upgrade.
2026.10.21.1
Fixed: The registry Quick Start created model instances without
clientId, clientSecret, accessToken, or refreshToken, which are required,
so the documented command failed. It also used swamp vault set, which does
not exist. Both Quick Starts now wire every credential with
${{ vault.get("twitch", "...") }}.
Changed: Documentation only otherwise. Credentials are stored with
swamp vault put twitch <KEY> at the interactive prompt instead of with the
value on the command line. The OAuth token exchange now sends the client secret
to curl on stdin rather than in argv, and stores the returned tokens straight
into the vault without printing them. The examples use a vault named twitch
with CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN, and REFRESH_TOKEN keys;
existing instances that reference other vault or key names keep working. The
credential global argument descriptions now say to supply them through
vault.get.
Upgrade note: No code, schema, or behavioral changes. The model version moves to 2026.10.21.1 with an identity upgrade.
2026.10.14.1
Added: The manifest now declares license: Apache-2.0 (SPDX). The registry quality rubric scores a declared license separately from the bundled LICENSE.md.
Upgrade note: Metadata only. No code, schema, or behavioral changes.
2026.09.18.1
Fixed: helixApiPaginated now sets truncated: true when the post-loop
cap trim actually removes items, instead of returning truncated: false for
a result set that is missing data.
Upgrade note: Normalized npm:zod reference globally to 4.6.5.
Modified 1 behaviors. Removed 1 workflows. Removed 1 reports
2026.09.18.1
Fixed: helixApiPaginated now sets truncated: true when the post-loop
cap trim actually removes items, instead of returning truncated: false for
a result set that is missing data.
Upgrade note: Normalized npm:zod reference globally to 4.6.5.
2026.09.15.1
Changed: Bump zod 4.4.3 → 4.6.5
2026.08.28.1
Changed: Normalized the extension license to Apache-2.0 and corrected the copyright holder to "Sean Escriva". Extensions that previously shipped an MIT LICENSE.md are now Apache-2.0, consistent with the repository root and every other extension. No code or behavioral changes.
Upgrade note: License text only. No API, schema, or runtime behavior changed.
2026.08.26.3
Fixed: Restored inline npm:zod@4.4.3 import specifiers so the registry
quality scorer can resolve dependencies and score the extension. An earlier
release used a bare "zod" import-map specifier, which published but scored as
unscored.
Changed: Retained explicit compilerOptions.strict in deno.json. No
behavioral or schema changes.
2026.08.28.1
Changed: Normalized the extension license to Apache-2.0 and corrected the copyright holder to "Sean Escriva". Extensions that previously shipped an MIT LICENSE.md are now Apache-2.0, consistent with the repository root and every other extension. No code or behavioral changes.
Upgrade note: License text only. No API, schema, or runtime behavior changed.
2026.08.26.3
Fixed: Restored inline npm:zod@4.4.3 import specifiers so the registry
quality scorer can resolve dependencies and score the extension. An earlier
release used a bare "zod" import-map specifier, which published but scored as
unscored.
Changed: Retained explicit compilerOptions.strict in deno.json. No
behavioral or schema changes.
2026.08.26.3
Fixed: Restored inline npm:zod@4.4.3 import specifiers so the registry
quality scorer can resolve dependencies and score the extension. An earlier
release used a bare "zod" import-map specifier, which published but scored as
unscored.
Changed: Retained explicit compilerOptions.strict in deno.json. No
behavioral or schema changes.
2026.08.26.1
Fixed: Added missing description field to upgrade entry for version
2026.08.24.2. The omission caused swamp extension pull to fail with a catalog
validation error ("upgrades.N.description: Invalid input: expected string,
received undefined").
2026.08.24.3
Added: Output metadata attributes for observability.
durationMs: Method execution duration in milliseconds.collectedBy: Extension name that produced the data.fetchedAt: ISO 8601 timestamp when data was fetched (added to resources that previously lacked it).
2026.08.24.2
Added Troubleshooting section documenting non-persisted token refresh, broadcaster auth requirement, silent 50K pagination cap, rate-limit self-throttle, deprecated get_mod_events endpoint, and no 5xx retry.
2026.08.21.2
Changed:
ban_user,unban_user, andget_usernow reject emptyuserId/loginvalues before making any API call, instead of sending a blank ID to Twitch and surfacing whatever cryptic error Helix happens to return.ban_user'sduration(timeout length) is now validated against Twitch's actual limits — an integer between 1 second and 1,209,600 seconds (2 weeks). Out-of-range values are rejected immediately with a clear message rather than failing deep in the Helix API call.send_messagenow enforces the documented 500-character limit onmessage(and rejects empty messages) instead of letting the API reject an oversized message after the request is already sent.ban_user'sreasonfield is capped at 500 characters to match Twitch's API limit.- Errors raised by failed Helix API requests now name the HTTP method and
path that was attempted (e.g.
GET /moderation/banned?... returned 404) instead of just the status code and response body, making it clear which operation failed when multiple API calls happen in one method.
No behavioral changes for well-formed inputs — existing valid calls are unaffected.
2026.08.21.1
Changed: Tightened channel, moderatorId, clientId, clientSecret,
accessToken, and refreshToken on the global-args schema to require
non-empty strings. All six are required identifiers/tokens that the Twitch
API never accepts empty — this catches misconfigured vault references or
blank --global-arg values at model-create time instead of a confusing
Helix API failure on first method call.
2026.07.30.1
Added: hasBroadcasterAuth global arg (boolean, default false). When
false, get_banned_users and get_mod_events throw a clear error explaining
the broadcaster must have OAuth'd the app, instead of silently hitting a
Twitch 401.
Changed: Manifest description now separates methods into "Moderator auth"
and "Broadcaster auth" tables so users can see at a glance what works with
their token level. The OAuth scope URL replaces the deprecated moderation:read
with the granular moderator:read:banned_users.
Changed: Workflow step descriptions for get-banned-users and
get-mod-events note the broadcaster auth requirement. Both steps retain
allowFailure: true so the workflow completes even without broadcaster tokens.
Upgrade note: Existing model instances default to hasBroadcasterAuth=false
after upgrade. If you previously used get_banned_users or get_mod_events
successfully (because the broadcaster had authorized your app), update your
instances to restore that behavior:
swamp model update <name> --global-arg hasBroadcasterAuth=true
2026.07.30.1
Added: hasBroadcasterAuth global arg (boolean, default false). When
false, get_banned_users and get_mod_events throw a clear error explaining
the broadcaster must have OAuth'd the app, instead of silently hitting a
Twitch 401.
Changed: Manifest description now separates methods into "Moderator auth"
and "Broadcaster auth" tables so users can see at a glance what works with
their token level. The OAuth scope URL replaces the deprecated moderation:read
with the granular moderator:read:banned_users.
Changed: Workflow step descriptions for get-banned-users and
get-mod-events note the broadcaster auth requirement. Both steps retain
allowFailure: true so the workflow completes even without broadcaster tokens.
Upgrade note: Existing model instances default to hasBroadcasterAuth=false
after upgrade. If you previously used get_banned_users or get_mod_events
successfully (because the broadcaster had authorized your app), update your
instances to restore that behavior:
swamp model update <name> --global-arg hasBroadcasterAuth=true
2026.07.18.2
Added: An upgrades array entry (no-op) to mod.ts for proper typeVersion tracking on existing instances. No schema or behavior changes.
2026.07.18.1
Changed: Added @module-level JSDoc documentation to mod.ts. No
runtime behavior change.
2026.07.13.1
Changed: Upgraded the test-only dev dependency
@systeminit/swamp-testing to 0.20260504.10, matching the rest of the repo.
This is a test-harness change only — the published extension bundle is
unchanged and no runtime behavior is affected.
2026.07.18.1
Changed: Added @module-level JSDoc documentation to mod.ts. No
runtime behavior change.
2026.07.13.1
Changed: Upgraded the test-only dev dependency
@systeminit/swamp-testing to 0.20260504.10, matching the rest of the repo.
This is a test-harness change only — the published extension bundle is
unchanged and no runtime behavior is affected.
2026.07.13.1
Changed: Upgraded the test-only dev dependency
@systeminit/swamp-testing to 0.20260504.10, matching the rest of the repo.
This is a test-harness change only — the published extension bundle is
unchanged and no runtime behavior is affected.
2026.07.03.1
Changed: Added JSDoc documentation to HELIX_BASE, TOKEN_URL,
helixApiPaginated (API helpers), and report export for improved deno doc
coverage and quality rubric compliance.
2026.06.29.2
Added: README with quick start, authentication guide, method reference, and workflow/report documentation. Apache 2.0 LICENSE. JSDoc on model export.
Quality grade fix — addresses all missing scorer gates (README, code example, license, symbol documentation).
2026.06.29.2
Added: README with quick start, authentication guide, method reference, and workflow/report documentation. Apache 2.0 LICENSE. JSDoc on model export.
Quality grade fix — addresses all missing scorer gates (README, code example, license, symbol documentation).
- Has README or module doc2/2earned
- README has a code example1/1earned
- README is substantive1/1earned
- Most symbols documented1/1earned
- No slow types (deprecated)1/1earned
- Dependencies pass trust audit2/2earned
- Docs keep secrets in a vault1/1earned
- Has description1/1earned
- Platform support declared (or universal)2/2earned
- License2/2earned
- Verified public repository2/2earned