How to integrate Twitch chat commands
Let chat summon AI segments on demand. Wire Twitch commands into the HostFabric queue API with rate limits and moderator approvals.
Total time · 20Difficulty · IntermediateTwitch moderator accessServerless function or bot framework
Inside HostFabric, link your Twitch account and specify which commands are public vs moderator-only.
- Control → Integrations → Connect Twitch
- Enable !aiquestion for everyone, !airiff for subs only
- Create API key labelled “Twitch bot”
Use EventSub or your preferred bot library to listen for the allowed commands. Validate cooldown windows before forwarding.
- Deploy serverless function (Vercel/Cloudflare) or run a local bot
- Store HOSTFABRIC_API_KEY as env var
- Build cooldown map keyed by userId + command
Craft prompt templates for each command. Include viewer name, paraphrased chat message, and guardrails.
- Example payload: { "prompt": "Viewer {displayName} asked: {message}" }
- Attach metadata such as "source": "twitch-command"
- Send POST /queue with default panel preset
Flag suspicious inputs for review. Use queue.pause + resume endpoints or route to a backup prompt if mod approval fails.
- If message includes banned terms, route to `queue.failed` with reason
- Expose dashboard for mods to approve/deny pending prompts
- Emit Discord alert for escalations
Log command usage, acceptance rate, and resulting viewer retention. Iterate prompts based on top-performing commands.
- Send metrics to DataDog/Amplitude
- Tag queue jobs with command name
- Share weekly report in the community content hub
Need sample code? Check the developer resources repo for a ready-to-fork Cloudflare Worker that handles !aiquestion to /queue.