The Simplest Extension in the (Hello) World.
The Hello World sample is designed to get you started building a Twitch Extension quickly. It contains all the key parts of a functioning Extension and can be immediately run in the Developer Rig. For a fast guide to get started, visit the Developer Rig documentation.
The Hello World Extension provides a simple scenario that demonstrates the end-to-end flow of an Extension. On the frontend, a user clicks a button that can change the color of a circle. Instead of changing the CSS locally, it calls its Extension Backend Service (EBS) to update the color of the circle. That message is then sent via Twitch PubSub to update all clients listening to the PubSub topic.
The sample is broken into two main components:
The recommended path to using this sample is with the Developer Rig. Use the Developer Rig's extension-init
command to clone this repository.
The Developer Rig is able to host the frontend Hello World files, but the EBS must be run and hosted separately.
Twitch Extensions require SSL (TLS).
If you're using the Developer Rig and used it to create this extension, it will have already configured the certificates. Otherwise, you'll need to set up a certificate for local development. This will generate a new certificate (server.crt
and server.key
) for you and place it in the conf/
directory. This certificate is different from the one used for the Developer Rig.
Navigate to the root of the Hello World extension folder and run npm install
and then npm run cert
Run the following commands to generate the necessary certificates for your Hello World backend
node scripts/ssl.js
mkdir ../my-extension/conf
mv ssl/selfsigned.crt ../my-extension/conf/server.crt
mv ssl/selfsigned.key ../my-extension/conf/server.key
If you're using the Developer Rig, it has buttons in its UI to perform the following actions.
To run the EBS, run node services/backend
, with the following command line arguments: -c <client id>
, -s <secret>
, -o <owner id>
.
This provides the EBS with your Extension client ID, Extension secret and the user ID of the Extension owner (likely you). These are necessary to validate calls to your EBS and make calls to Twitch services such as PubSub.
If you do not want to pass in command line arguments, you can also directly set the following environment variables: EXT_SECRET
, EXT_CLIENT_ID
, EXT_OWNER_ID
in your code.
You can get your client ID and secret from your Extension Dashboard.
To get the owner ID, you will need to execute a simple CURL command against the Twitch /users
endpoint. You'll need your extension client ID as part of the query (this will be made consistent with the Developer Rig shortly, by using owner name).
curl -H "Client-ID: <client id>" -X GET "https://api.twitch.tv/helix/users?login=<owner name>"
Note - If you haven't yet created an extension, you can start that process here.