Skip to content

A public API for Twitch chat commands through StreamElements

Notifications You must be signed in to change notification settings

marcusmcb/chat-command-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A public API for Twitch chat commands via StreamElements

What's in this repo

This repo contains code for a REST API that is intended for use with the Twitch streaming platform by way of StreamElements.

When a viewer/user in your Twitch channel uses one of the included chat commands, a request is made to the corresponding command's endpoint to return the response.

The API contains responses for the following commands:

  • !strain - returns an autogenerated name of a fictional weed "strain" to the chaet

  • !urban (search term) - returns the searched term's results from the Urban Dictionary API

  • !askgpt (prompt) - returns a response to the given prompt from the OpenAI/ChatGPT API

StreamElements configuration

To use the API's responses in your Twitch channel's chat, you'll need to create a custom command in StreamElements for each of the commands included in this repo.

Once done, you'll need to enter the string for each command in it's corresponding "response type" in the StreamElements custom chat command UI.

  • For the !strain command, use:

${user} is on that ${urlfetch https://chat-command-api-f314fc32259e.herokuapp.com/strain} strain tonight!

  • For the !urban command, use:

$(urlfetch https://chat-command-api-f314fc32259e.herokuapp.com/urban?term=$(queryescape ${1:}))

  • For the !askgpt command, use:

$(urlfetch https://chat-command-api-f314fc32259e.herokuapp.com/askgpt?query=$(queryescape ${1:}))

In use

To use this code to create and run your own Twitch chat command API for use with StreamElements, simply clone the repo, add in the necessary environment values (listed below) and deploy the code to a cloud provider (Heroku, etc) to host the chat command API for your channel during live-streams.

Necessary Authorization Keys / Environment Variables

The following env values are used in this project

  • TWITCH_OAUTH_TOKEN
  • TWITCH_CHANNELS
  • TWITCH_USERNAME
  • URBAN_DICTIONARY_API_KEY
  • URBAN_DICTIONARY_API_HOST
  • OPENAI_API_KEY

The Twitch OAuth token is required in order to connect the script to Twitch's chat element, and the Twitch Username value is the account used when generating the token.

The Twitch Channels value is used to determine which channel(s) you'd like your API to respond to.

More information on creating a Twitch OAuth access token can be found here. When prompted, selected "bot chat token".

More information on creating and using an OpenAI developer key can be found here.

More information on creating and using an Urban Dictionary developer key can be found here.

Marcus McBride, 2025

About

A public API for Twitch chat commands through StreamElements

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published