A sample that demonstrates how to use the Twitch API from an extension.
The panel extension allows viewers to conditionally "send" a message to the broadcaster if that message passes the channel's AutoMod settings. The EBS calls the /helix/moderation/enforcements/status
endpoint to accomplish this.
During extension configuration, the broadcaster goes through the Twitch OAuth Authorization Code Flow to grant the extension the necessary scope (moderation:read
) to call the endpoint. On success, the API access and refresh tokens are stored in a database (DynamoDB).
- Go 1.12+ with
dep
for dependency management. - DynamoDB for storing API credentials.
-
Create a new
Panel
extension. Set itsTesting Base URI
tohttp://localhost:8080/
as we're not using HTTPS for example purposes. Add a secondary user to theTesting Account Whitelist
to validate AutoMod functionality (messages sent as the broadcaster will always pass). -
Set the needed environment variables:
export CLIENT_ID=
export API_SECRET=
export EXTENSION_SECRET=
export SESSION_SECRET=
SESSION_SECRET
can be an arbitary string.
- Create the DynamoDB table:
aws dynamodb create-table --table-name automodder-users \
--attribute-definitions AttributeName=UserID,AttributeType=S \
--key-schema AttributeName=UserID,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
-
Clone the repo under your
$GOPATH/src
directory and navigate to theebs
directory; usually this would be$GOPATH/src/github.com/twitchdev/extensions-samples/automodder/ebs
. -
Install the dependencies:
dep ensure
- Run the extension EBS:
go build && ./ebs
To simplify development, the EBS also serves the front-end assets. You should see the extension if you open http://localhost:8080/panel.html in your browser.
- Install and configure the extension on your channel. You can do so via the https://dev.twitch.tv/console/extensions/CLIENT_ID/0.0.1/status page (see the
View on Twitch and Install
button). Note that you must explicitly allow HTTP content to be loaded when viewing the extension on twitch.tv . For example, in Chrome, this is done by clicking on the shield icon in the right corner of the location bar.
- As the broadcaser, open the extension configuration and give the extension permission to call the API on your behalf.
- As the viewer (the one you've added to the whitelist), open the extension and see which messages would pass AutoMod or not.